lib/veritas/algebra/join.rb in veritas-0.0.4 vs lib/veritas/algebra/join.rb in veritas-0.0.5
- old
+ new
@@ -5,10 +5,17 @@
# The join between relations
class Join < Relation
include Relation::Operation::Combination
+ # The common headers between the operands
+ #
+ # @return [Header]
+ #
+ # @api private
+ attr_reader :join_header
+
# Instantiate a new Join
#
# @example
# join = Join.new(left, right)
#
@@ -52,11 +59,11 @@
# @api private
def initialize(left, right)
super
right_header = right.header
@join_header = left.header & right_header
- @remainder_header = right_header - @join_header
+ @remainder_header = right_header - join_header
end
# Iterate over each tuple in the set
#
# @example
@@ -71,12 +78,12 @@
# @return [self]
#
# @api public
def each(&block)
return to_enum unless block_given?
- index = build_index
util = Relation::Operation::Combination
+ index = build_index
left.each do |left_tuple|
right_tuples = index[join_tuple(left_tuple)]
if right_tuples
util.combine_tuples(header, left_tuple, right_tuples, &block)
@@ -107,11 +114,11 @@
#
# @return [Tuple]
#
# @api private
def join_tuple(tuple)
- tuple.project(@join_header)
+ tuple.project(join_header)
end
# Generate a tuple with the disjoint attributes to use in the join
#
# @return [Tuple]
@@ -130,10 +137,10 @@
#
# @example natural join
# join = relation.join(other)
#
# @example theta-join using a block
- # join = relation.join(other) { |r| r[:a].gte(r[:b]) }
+ # join = relation.join(other) { |r| r.a.gte(r.b) }
#
# @param [Relation] other
# the other relation to join
#
# @yield [relation]