class Axiom::Algebra::Join

The join between relations

Attributes

join_header[R]

The common headers between the operands

@return [Header]

@api private

Public Class Methods

new(_left, _right) click to toggle source

Initialize a Join

@param [Relation] _left @param [Relation] _right

@return [undefined]

@api private

Calls superclass method
# 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

Public Instance Methods

delete(other) click to toggle source

Delete a relation from the Join

@example

new_relation = join.delete(other)

@param [Relation] other

@return [Join]

@api public

# File lib/axiom/algebra/join.rb, line 81
def delete(other)
  other = coerce(other)
  delete_left(other).join(delete_right(other))
end
each(&block) click to toggle source

Iterate over each tuple in the set

@example

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

@yield [tuple]

@yieldparam [Tuple] tuple

each tuple in the set

@return [self]

@api public

# 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|
    util.combine_tuples(header, left_tuple, index[left_tuple], &block)
  end
  self
end
insert(other) click to toggle source

Insert a relation into the Join

@example

new_relation = join.insert(other)

@param [Relation] other

@return [Join]

@api public

# File lib/axiom/algebra/join.rb, line 66
def insert(other)
  other = coerce(other)
  insert_left(other).join(insert_right(other))
end

Private Instance Methods

build_index() click to toggle source

Build an index using every tuple in the right relation

@return [Hash]

@api private

# File lib/axiom/algebra/join.rb, line 93
def build_index
  Index.new(join_header, @disjoint_header).merge(right)
end
delete_left(other) click to toggle source

Delete the other relation from the left operand

@param [Relation] other

@return [Relation::Operation::Deletion]

@api private

# File lib/axiom/algebra/join.rb, line 126
def delete_left(other)
  left.delete(other.project(left.header))
end
delete_right(other) click to toggle source

Delete the other relation from the right operand

@param [Relation] other

@return [Relation::Operation::Deletion]

@api private

# File lib/axiom/algebra/join.rb, line 137
def delete_right(other)
  right.delete(other.project(right.header))
end
insert_left(other) click to toggle source

Insert the other relation into the left operand

@param [Relation] other

@return [Relation::Operation::Insertion]

@api private

# File lib/axiom/algebra/join.rb, line 104
def insert_left(other)
  left.insert(other.project(left.header))
end
insert_right(other) click to toggle source

Insert the other relation into the right operand

@param [Relation] other

@return [Relation::Operation::Insertion]

@api private

# File lib/axiom/algebra/join.rb, line 115
def insert_right(other)
  right.insert(other.project(right.header))
end