class Axiom::Relation::Materialized

A materialized relation

Constants

ZERO_TUPLE

Attributes

directions[R]

The relation sort order

@return [Operation::Sorted::DirectionSet]

@api private

Public Class Methods

new(*args) click to toggle source

Instantiate a materialized Relation

@example of a materialized Array based relation

array    = [[1], [2], [3]]
relation = Relation::Materialized.new([[:id, Integer]], array)

@example of a materialized Set based relation

set      = Set[[1], [2], [3]]
relation = Relation::Materialized.new([[:id, Integer]], set)

@example of a materialized empty relation

relation = Relation::Materialized.new([[:id, Integer]])

@param [Array(Header, Enumerable)] args

@return [Relation]

@api public

Calls superclass method Axiom::Relation::new
# File lib/axiom/relation/materialized.rb, line 35
def self.new(*args)
  if equal?(Materialized) && empty?(args[1])
    Empty.new(args.first)
  else
    super
  end
end
new(header, tuples, directions = Operation::Sorted::DirectionSet::EMPTY) click to toggle source

Initialize a materialized Relation

@param [Header, to_ary] header

the relation header

@param [Enumerable] tuples

the relation tuples

@param [Operation::Sorted::DirectionSet] directions

optional directions to sort the relation by

@return [undefined]

@api private

Calls superclass method Axiom::Relation::new
# File lib/axiom/relation/materialized.rb, line 73
def initialize(header, tuples, directions = Operation::Sorted::DirectionSet::EMPTY)
  super(header, tuples)
  @directions = Operation::Sorted::DirectionSet.coerce(directions)
end

Private Class Methods

empty?(tuples) click to toggle source

Test if the tuples are empty

When tuples are nil, it means there are no tuples so it is the equivalent of specifying [] for the tuples.

@param [nil, size] tuples

@return [Boolean]

@api private

# File lib/axiom/relation/materialized.rb, line 53
def self.empty?(tuples)
  tuples.nil? || begin
    size = tuples.size
    size && size.zero?
  end
end

Public Instance Methods

materialize() click to toggle source

A noop for Materialized relations

@example

materialized.materialize  # (Always returns self)

@return [self]

@api public

# File lib/axiom/relation/materialized.rb, line 86
def materialize
  self
end
materialized?() click to toggle source

Return true for a Materialized relation

@example

relation.materialized?  # => true

@return [true]

@api public

# File lib/axiom/relation/materialized.rb, line 98
def materialized?
  true
end
size() click to toggle source

Return the number of tuples

@example

materialized.size  # => 10

@return [Integer]

@api public

# File lib/axiom/relation/materialized.rb, line 110
def size
  tuples.size
end