Sha256: fa0c3a9010c1871b2a9b328e8191aa18f54ff0e7fa6b8f0588432c783e9194c6

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

require 'arc-furnace/source'

module ArcFurnace
  class AbstractJoin < Source
    private_attr_reader :hash, :source, :key_column
    attr_reader :value

    # The source is a source, the hash is a hash, and one can optionally
    # pass the key column to get the primary key for each source entity, the
    # default is equijoin semantics--the key of the hash is used.
    def initialize(source: , hash:, key_column: nil)
      if source.is_a?(::ArcFurnace::Source) && hash.is_a?(::ArcFurnace::Hash)
        @hash = hash
        @source = source
        @key_column = key_column || hash.key_column
      else
        raise 'Must be passed one Hash and one Source!'
      end
    end

    def prepare
      advance
    end

    def advance
      raise "Unimplemented!"
    end

    delegate empty?: :source

    protected

    def merge_source_row(source_row)
      key = source_row[key_column]
      if key
        if hash_value = hash.get(key)
          hash_value = hash_value.deep_dup
          source_row.each do |key, value|
            hash_value[key] = value
          end
          @value = hash_value
          true
        else
          error_handler.missing_hash_key(source_row: source_row, key: key, node_id: node_id)
          false
        end
      else
        error_handler.missing_join_key(source_row: source_row, node_id: node_id)
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
arc-furnace-0.1.3 lib/arc-furnace/abstract_join.rb
arc-furnace-0.1.0 lib/arc-furnace/abstract_join.rb