Class: Chicago::ETL::Transformations::AddKey

Inherits:
Chicago::ETL::Transformation show all
Defined in:
lib/chicago/etl/transformations.rb

Overview

Adds an :id field to a row, based on a KeyBuilder.

Also adds this id as :row_id to any rows in an embedded :_errors field.

Pass the :key_builder option to set the KeyBuilder.

Instance Method Summary collapse

Methods inherited from Chicago::ETL::Transformation

#added_fields, added_fields, adds_fields, #applies_to_stream?, #downstream_fields, #flush, #initialize, #process, removed_fields, #removed_fields, removes_fields, #required_options, required_options, requires_options, #upstream_fields

Constructor Details

This class inherits a constructor from Chicago::ETL::Transformation

Instance Method Details

#key_builderObject



54
55
56
# File 'lib/chicago/etl/transformations.rb', line 54

def key_builder
  @options[:key_builder]
end

#output_streamsObject



37
38
39
# File 'lib/chicago/etl/transformations.rb', line 37

def output_streams
  [:default, :dimension_key]
end

#process_row(row) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/chicago/etl/transformations.rb', line 41

def process_row(row)
  key, key_row = key_builder.key(row)
  row[:id] = key
  (row[:_errors] || []).each {|e| e[:row_id] = row[:id] }

  if key_row
    assign_stream(key_row, :dimension_key)
    [row, key_row]
  else
    row
  end
end