Sha256: f101b15fdc21812a5458be2e7d790df58ad65f3f7abcae9f3c8fd156fee4d5ed

Contents?: true

Size: 1.05 KB

Versions: 5

Compression:

Stored size: 1.05 KB

Contents

module ETL #:nodoc:
  module Processor #:nodoc:
    # A row level processor that provides surrogate keys
    class SurrogateKeyProcessor < ETL::Processor::RowProcessor
      attr_accessor :query
      attr_accessor :destination
      
      # Initialize the surrogate key generator
      def initialize(control, configuration)
        super
        if configuration[:query]
          @surrogate_key = ETL::ActiveRecord::Base.connection.select_value(configuration[:query])
        end
        #puts "initial surrogate key: #{@surrogate_key}"
        @surrogate_key = 0 if @surrogate_key.blank?
        @surrogate_key = @surrogate_key.to_i
        #puts "surrogate key: #{@surrogate_key}"
        @destination = configuration[:destination] || :id
      end
      
      # Add a surrogate key to the row
      def process(row)
        if row
          #puts "processing row #{row.inspect}"
          @surrogate_key += 1
          #puts "adding surrogate key to row: #{@surrogate_key}"
          row[destination] = @surrogate_key
          row
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activewarehouse-etl-0.8.0 lib/etl/processor/surrogate_key_processor.rb
activewarehouse-etl-0.8.1 lib/etl/processor/surrogate_key_processor.rb
activewarehouse-etl-0.8.2 lib/etl/processor/surrogate_key_processor.rb
activewarehouse-etl-0.8.3 lib/etl/processor/surrogate_key_processor.rb
activewarehouse-etl-0.8.4 lib/etl/processor/surrogate_key_processor.rb