Class: Axiom::Algebra::Join

Inherits:
Relation show all
Includes:
Relation::Operation::Combination
Defined in:
lib/axiom/algebra/join.rb

Overview

The join between relations

Defined Under Namespace

Modules: Methods

Instance Attribute Summary collapse

Attributes included from Operation::Binary

#left, #right

Attributes inherited from Relation

#header

Instance Method Summary collapse

Methods included from Relation::Operation::Combination

combine_tuples

Methods inherited from Relation

#==, #[], #directions, #empty?, #include?, #materialize, #materialized?, new, #replace

Methods included from Visitable

#accept

Constructor Details

#initialize(_left, _right) ⇒ undefined

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize a Join

Parameters:



25
26
27
28
29
30
# File 'lib/axiom/algebra/join.rb', line 25

def initialize(_left, _right)
  super
  right_header     = right.header
  @join_header     = left.header  & right_header
  @disjoint_header = right_header - join_header
end

Instance Attribute Details

#join_headerHeader (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The common headers between the operands

Returns:



15
16
17
# File 'lib/axiom/algebra/join.rb', line 15

def join_header
  @join_header
end

Instance Method Details

#delete(other) ⇒ Join

Delete a relation from the Join

Examples:

new_relation = join.delete(other)

Parameters:

Returns:



84
85
86
87
# File 'lib/axiom/algebra/join.rb', line 84

def delete(other)
  other = coerce(other)
  delete_left(other).join(delete_right(other))
end

#each {|tuple| ... } ⇒ self

Iterate over each tuple in the set

Examples:

join = Join.new(left, right)
join.each { |tuple| ... }

Yields:

  • (tuple)

Yield Parameters:

  • tuple (Tuple)

    each tuple in the set

Returns:

  • (self)


46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/axiom/algebra/join.rb', line 46

def each(&block)
  return to_enum unless block_given?
  util  = Relation::Operation::Combination
  index = build_index

  left.each do |left_tuple|
    right_tuples = index[join_tuple(left_tuple)]
    util.combine_tuples(header, left_tuple, right_tuples, &block)
  end

  self
end

#insert(other) ⇒ Join

Insert a relation into the Join

Examples:

new_relation = join.insert(other)

Parameters:

Returns:



69
70
71
72
# File 'lib/axiom/algebra/join.rb', line 69

def insert(other)
  other = coerce(other)
  insert_left(other).join(insert_right(other))
end