Code Monkey home page Code Monkey logo

arc-furnace's Introduction

ArcFurnace

Gem Version Build Status

ArcFurnace melts, melds, and transforms your scrap data into perfectly crafted data for ingest into applications, analysis, or whatnot. ArcFurnace simplifies simple ETL (Extract, Transform, Load) tasks for small to medium sets of data using a programmatic DSL interface. Here's an example:

class Transform < ArcFurnace::Pipeline

    source :marketing_info_csv, type: ArcFurnace::CSVSource, params: { filename: :marketing_filename }

    transform :marketing_info_source, params: { source: :marketing_info_csv } do |row|
      row.delete('Name')
      row
    end

    source :product_attributes,
           type: ArcFurnace::MultiCSVSource,
           params: { filenames: :product_attribute_filenames }

    hash_node :marketing_info,
              params: {
                  key_column: :primary_key,
                  source: :marketing_info_source
              }

    outer_join :join_results,
               params: {
                   source: :product_attributes,
                   hash: :marketing_info
               }

    sink type: ArcFurnace::AllFieldsCSVSink,
         source: :join_results,
         params: { filename: :destination_name }

end

Installation

Add this line to your application's Gemfile:

gem 'arc-furnace', github: 'salsify/arc-furnace'

And then execute:

$ bundle

Usage

ArcFurnace provides a few concepts useful to extracting and transforming data.

Node Types Available

Pipelines

Pipelines define a a complete transformation and define a directed, acyclic graph of operations that define how data is transformed. Each type of node in a Pipeline is defined below, but a Pipelines defines the network of nodes that transform data.

Sources

A Source provides values to a Pipeline. A Pipeline may have many sources. Essentially, any nodes that require a stream of data (Hash, Transform, Join, Sink) will have one.

Hashes

A Hash provides indexed access to a Source but pre-computing the index based on a key. The processing happens during the prepare stage of pipeline processing. Hashes have a simple interface, #get(primary_key), to requesting data. Hashes are almost exclusively used as inputs to one side of joins.

Joins

An InnerJoin or an OuterJoin join two sources of data (one must be a Hash) based upon a key. By default the join key is the key that the hash was rolled-up on, however, the key_column option on both InnerJoin and OuterJoin may override this. Note the default join is an inner join, which will drop source rows if the hash does not contain a matching row.

Filters

A Filter acts as a source, however, takes a source as an input and determines whether to pass each row to the next downstream node by calling the #filter method on itself. There is an associated BlockFilter and sugar on Pipeline to make this easy.

Transforms

A Transform acts as a source, however, takes a source as an input and transforms each input. The BlockTransform and associated sugar in the transform method of Pipeline make this very easy (see the example above).

Unfolds

An Unfold acts as a source, however, takes a source as an input and produces multiple rows for that source as an output. A common case for this is splitting rows into multiple rows depending upon their keys. The BlockTransform and associated sugar in the unfold method of Pipeline make this fairly easy (see pipeline_spec.rb).

Observers

An Observer acts as a source and takes a source as an input and serves as a pass-through for a stream. Observers are used to observe the data stream--record data for use elsewhere.

Sinks

Each Pipeline has a single sink. Pipelines must produce data somewhere, and that data goes to a sink. Sinks subscribe to the #row(hash) interace--each output row is passed to this method for handling.

General pipeline development process

  1. Define a source. Choose an existing Source implementation in this library (CSVSource or ExcelSource), extend the EnumeratorSource, or implement the row() method for a new source.
  2. Define any transformations, or joins. This may cause you to revisit #1.
  3. Define the sink. This is generally custom, or, may be one of the provided CSVSink types.
  4. Roll it together in a Pipeline.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release to create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

TODOs

  1. Add examples for ErrorHandler interface.
  2. Add sugar to define a BlockTransform on a Source definition in a Pipeline.

Contributing

  1. Fork it ( https://github.com/[my-github-username]/arc-furnace/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

arc-furnace's People

Contributors

brian-penguin avatar cdurling avatar dependabot[bot] avatar jfo84 avatar lee-feigenbaum avatar patbreault avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arc-furnace's Issues

Add logging for failed expectations when processing rows

In many cases the ArcFurnace nodes expect rows that come in to have certain fields--this is especially true for Hash and Equijoin nodes. These nodes should be resilient to missing data and properly log when expectations are not met instead of failing with a stacktrace (which they often do).

Much larger output file sizes than input file sizes

One of our projects has a ProductPipeline that is a relatively simple implementation of the library. Here's a snippet:

require_relative 'constants'
require 'arc-furnace/pipeline'
require 'arc-furnace/excel_source'
require 'arc-furnace/all_fields_csv_sink'

class ProductsPipeline < ArcFurnace::Pipeline

  include Constants

  # create products source

  source :products_source,
         type: ArcFurnace::ExcelSource,
         params: {
             filename: :product_filename,
             encoding: 'ISO-8859-1'
         }

  transform :products_transform, params: { source: :products_source } do |hash|
    result = hash.deep_dup
    result[SALSIFY_ID] = result.delete(BLAH_ID)
    result
  end

  filter :filtered_products, params: { source: :products_transform, observed_products: :observed_products } do |row, params|
    params.fetch(:observed_products).add(row[BLAH_ID])
  end

  sink type: ArcFurnace::AllFieldsCSVSink,
       source: :filtered_products,
       params: { filename: "#{Dir.pwd}/products_import.csv" }

end

The source file is a 14 MB XLSX file, but the output file is a 71 MB CSV file. The output file is five times larger and XLSX files tend to be larger than CSV files relative to the information contained. I tried removing the filter and the file size was the same, and I spot checked the file and they look identical. I feel like something is going wrong with the AllFieldsCSVSink.

Queue @dspangen

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.