class Bmg::Operator::Union

Union operator.

Returns all tuples of the left operand followed by all tuples from the right operand.

This implementation is actually a NAry-Union, since it handles an arbitrary number of operands.

By default, this operator strips duplicates, as of relational theory. Please set the `:all` option to true to avoid this behavior and save execution time.

Constants

DEFAULT_OPTIONS

Attributes

options[R]

Public Class Methods

new(type, operands, options = {}) click to toggle source
# File lib/bmg/operator/union.rb, line 23
def initialize(type, operands, options = {})
  @type = type
  @operands = operands
  @options = DEFAULT_OPTIONS.merge(options)
end

Public Instance Methods

all?() click to toggle source
# File lib/bmg/operator/union.rb, line 35
def all?
  @options[:all]
end
each() { |tuple| ... } click to toggle source
# File lib/bmg/operator/union.rb, line 39
def each(&bl)
  return to_enum unless block_given?
  if all?
    operands.each do |op|
      op.each(&bl)
    end
  else
    seen = {}
    operands.each do |op|
      op.each do |tuple|
        yield(tuple) unless seen.has_key?(tuple)
        seen[tuple] = true
      end
    end
  end
end
to_ast() click to toggle source
# File lib/bmg/operator/union.rb, line 56
def to_ast
  [ :union ] + operands.map(&:to_ast) + [ options.dup ]
end