Class: Alf::Engine::Join::Hash

Inherits:
Object
  • Object
show all
Includes:
Cog
Defined in:
lib/alf-engine/alf/engine/join/hash.rb

Overview

Provides hash-based join.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Cog

#each, #to_dot, #to_relation

Constructor Details

#initialize(left, right) ⇒ Hash

Creates a Join::Hash instance



16
17
18
19
# File 'lib/alf-engine/alf/engine/join/hash.rb', line 16

def initialize(left, right)
  @left = left
  @right = right
end

Instance Attribute Details

#leftEnumerable (readonly)

Returns The left operand.

Returns:

  • (Enumerable)

    The left operand



10
11
12
# File 'lib/alf-engine/alf/engine/join/hash.rb', line 10

def left
  @left
end

#rightEnumerable (readonly)

Returns The right operand.

Returns:

  • (Enumerable)

    The right operand



13
14
15
# File 'lib/alf-engine/alf/engine/join/hash.rb', line 13

def right
  @right
end

Instance Method Details

#_each(&block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/alf-engine/alf/engine/join/hash.rb', line 22

def _each(&block)
  index = nil
  left.each do |left_tuple|
    index ||= Materialize::Hash.new(right, lambda{|t|
      AttrList.new(left_tuple.keys & t.keys)
    }, false).prepare
    index[left_tuple, true].each do |right_tuple|
      yield left_tuple.merge(right_tuple)
    end
  end
end