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

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

Overview

Provides hash-based join.

Constant Summary

Constants included from Cog

Cog::EMPTY_CHILDREN, Cog::EMPTY_OPTIONS

Instance Attribute Summary collapse

Attributes included from Compiler::Cog

#compiler, #expr

Instance Method Summary collapse

Methods included from Cog

#arguments, #children, #each, #options, #to_s

Methods included from Compiler::Cog

#cog_orders, #orderedby?, #relation_type, #to_ascii_tree, #to_cog, #to_relation

Constructor Details

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

Creates a Join::Hash instance


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

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

Instance Attribute Details

#leftEnumerable (readonly)


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

def left
  @left
end

#rightEnumerable (readonly)


14
15
16
# File 'lib/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/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/join/hash.rb', line 24

def operands
  [ left, right ]
end