class Axiom::Algebra::Join
The join between relations
Attributes
The common headers between the operands
@return [Header]
@api private
Public Class Methods
Initialize a Join
@param [Relation] _left @param [Relation] _right
@return [undefined]
@api private
# 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 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
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 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 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 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 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 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 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