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

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

Overview

Provides hash-based join.

Instance Attribute Summary collapse

Attributes included from Cog

#expr

Instance Method Summary collapse

Methods included from Cog

#each, #heading, #keys, #to_cog, #to_dot, #to_relation

Constructor Details

#initialize(left, right, expr = nil) ⇒ Hash

Creates a Join::Hash instance



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

def initialize(left, right, expr = nil)
  super(expr)
  @left = left
  @right = right
end

Instance Attribute Details

#leftEnumerable (readonly)

Returns The left operand.

Returns:

  • (Enumerable)

    The left operand



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

def left
  @left
end

#rightEnumerable (readonly)

Returns The right operand.

Returns:

  • (Enumerable)

    The right operand



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

def right
  @right
end

Instance Method Details

#_each(&block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/alf-engine/alf/engine/join/hash.rb', line 29

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, expr).prepare
    index[left_tuple, true].each do |right_tuple|
      yield left_tuple.merge(right_tuple)
    end
  end
end

#operandsObject

Returns left and right operands in an array



24
25
26
# File 'lib/alf-engine/alf/engine/join/hash.rb', line 24

def operands
  [ left, right ]
end