Class: Chicago::ETL::Transformations::HashColumns

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

Overview

Adds a hash of the specified columns as a field in the row.

Instance Method Summary collapse

Methods inherited from Chicago::ETL::Transformation

added_fields, adds_fields, #applies_to_stream?, #downstream_fields, #flush, #initialize, #output_streams, #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

#added_fieldsObject



114
115
116
# File 'lib/chicago/etl/transformations.rb', line 114

def added_fields
  [output_field]
end

#hash_columnsObject



122
123
124
# File 'lib/chicago/etl/transformations.rb', line 122

def hash_columns
  @options[:columns]
end

#output_fieldObject



118
119
120
# File 'lib/chicago/etl/transformations.rb', line 118

def output_field
  @options[:output_field] || :hash
end

#process_row(row) ⇒ Object



109
110
111
112
# File 'lib/chicago/etl/transformations.rb', line 109

def process_row(row)
  str = hash_columns.map {|c| row[c].to_s }.join
  row.put(output_field, Digest::MD5.hexdigest(str).upcase)
end