Sha256: 33b14fb0421932463eb174d6632fb23a7638b8abbef6dd9ad2e71d4f58b2bb5f

Contents?: true

Size: 1.05 KB

Versions: 27

Compression:

Stored size: 1.05 KB

Contents

module ETL #:nodoc:
  module Processor #:nodoc:
    # Row processor that checks whether or not the row has already passed 
    # through the ETL processor, using the key fields provided as the keys
    # to check.
    class CheckUniqueProcessor < ETL::Processor::RowProcessor

      # The keys to check
      attr_accessor :keys
      
      # Initialize the processor
      # Configuration options:
      # * <tt>:keys</tt>: An array of keys to check against
      def initialize(control, configuration)
        super
        @keys = configuration[:keys]
      end

      # A Hash of keys that have already been processed.
      def compound_key_constraints
        @compound_key_constraints ||= {}
      end
      
      # Process the row. This implementation will only return a row if it
      # it's key combination has not already been seen.
      def process(row)
        key = (keys.collect { |k| row[k] }).join('|')
        unless compound_key_constraints[key]
          compound_key_constraints[key] = 1
          return row
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 7 rubygems

Version Path
activewarehouse-etl-0.7.1 lib/etl/processor/check_unique_processor.rb
activewarehouse-etl-0.8.4 lib/etl/processor/check_unique_processor.rb
activewarehouse-etl-0.8.3 lib/etl/processor/check_unique_processor.rb
activewarehouse-etl-0.8.2 lib/etl/processor/check_unique_processor.rb
activewarehouse-etl-0.8.1 lib/etl/processor/check_unique_processor.rb
activewarehouse-etl-0.9.0 lib/etl/processor/check_unique_processor.rb
activewarehouse-etl-0.9.1 lib/etl/processor/check_unique_processor.rb