Class: Axiom::Relation
- Inherits:
-
Object
- Object
- Axiom::Relation
- Includes:
- Visitable, Enumerable
- Defined in:
- lib/axiom/relation.rb,
lib/axiom/relation/base.rb,
lib/axiom/relation/keys.rb,
lib/axiom/relation/empty.rb,
lib/axiom/relation/proxy.rb,
lib/axiom/relation/header.rb,
lib/axiom/relation/materialized.rb,
lib/axiom/relation/operation/set.rb,
lib/axiom/relation/operation/limit.rb,
lib/axiom/relation/operation/order.rb,
lib/axiom/relation/operation/unary.rb,
lib/axiom/relation/operation/binary.rb,
lib/axiom/relation/operation/offset.rb,
lib/axiom/relation/operation/reverse.rb,
lib/axiom/relation/operation/deletion.rb,
lib/axiom/relation/operation/insertion.rb,
lib/axiom/relation/operation/combination.rb,
lib/axiom/relation/operation/order/direction.rb,
lib/axiom/relation/operation/order/direction_set.rb
Overview
Abstract base class for Relation operations
Direct Known Subclasses
Algebra::Difference, Algebra::Extension, Algebra::Intersection, Algebra::Join, Algebra::Product, Algebra::Projection, Algebra::Rename, Algebra::Restriction, Algebra::Summarization, Algebra::Union, Base, Materialized, Operation::Deletion, Operation::Insertion, Operation::Limit, Operation::Offset, Operation::Order
Defined Under Namespace
Modules: Operation, Proxy Classes: Base, Empty, Header, Keys, Materialized
Instance Attribute Summary collapse
-
#header ⇒ Header
readonly
private
The relation header.
Class Method Summary collapse
-
.new(*args) ⇒ Relation
Instantiate a new Relation.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compare the relation with other relation for equivalency.
-
#[](name) ⇒ Attribute
Lookup an Attribute in the header given an attribute name.
-
#directions ⇒ Operation::Order::DirectionSet
private
The relation sort order.
-
#each {|tuple| ... } ⇒ self
Iterate over each tuple in the set.
-
#empty? ⇒ Boolean
Test if there are no tuples.
-
#include?(tuple) ⇒ Boolean
Test if the tuple exists in the relation.
-
#initialize(header, tuples) ⇒ undefined
constructor
private
Initialize a Relation.
-
#materialize ⇒ Materialized
Return a relation with each tuple materialized.
-
#materialized? ⇒ false
Return false for a non-Materialized relation.
-
#one ⇒ Tuple
Return a tuple if the relation contains exactly one tuple.
-
#replace(other) ⇒ Relation::Operation::Insertion
Return a relation that represents a replacement of a relation.
Methods included from Visitable
Constructor Details
#initialize(header, tuples) ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize a Relation
72 73 74 75 |
# File 'lib/axiom/relation.rb', line 72 def initialize(header, tuples) @header = Header.coerce(header) @tuples = freeze_object(tuples) end |
Instance Attribute Details
#header ⇒ Header (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The relation header
15 16 17 |
# File 'lib/axiom/relation.rb', line 15 def header @header end |
Class Method Details
.new(*args) ⇒ Relation
Instantiate a new Relation
53 54 55 56 57 58 59 60 |
# File 'lib/axiom/relation.rb', line 53 def self.new(*args) last = args.last if superclass.equal?(Object) && last.respond_to?(:size) && last.size.kind_of?(Integer) Materialized.new(*args) else super end end |
Instance Method Details
#==(other) ⇒ Boolean
Compare the relation with other relation for equivalency
202 203 204 205 206 |
# File 'lib/axiom/relation.rb', line 202 def ==(other) other = coerce(other) header == other.header && to_set == other.to_set end |
#[](name) ⇒ Attribute
Lookup an Attribute in the header given an attribute name
88 89 90 |
# File 'lib/axiom/relation.rb', line 88 def [](name) header[name] end |
#directions ⇒ Operation::Order::DirectionSet
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The relation sort order
30 31 32 |
# File 'lib/axiom/relation.rb', line 30 def directions Operation::Order::DirectionSet::EMPTY end |
#each {|tuple| ... } ⇒ self
Iterate over each tuple in the set
106 107 108 109 110 111 112 113 114 |
# File 'lib/axiom/relation.rb', line 106 def each return to_enum unless block_given? seen = Hash.new tuples.each do |tuple| tuple = Tuple.coerce(header, tuple) yield seen[tuple] = tuple unless seen.key?(tuple) end self end |
#empty? ⇒ Boolean
Test if there are no tuples
216 217 218 |
# File 'lib/axiom/relation.rb', line 216 def empty? none? end |
#include?(tuple) ⇒ Boolean
Test if the tuple exists in the relation
187 188 189 |
# File 'lib/axiom/relation.rb', line 187 def include?(tuple) to_set.include?(tuple) end |
#materialize ⇒ Materialized
Return a relation with each tuple materialized
161 162 163 |
# File 'lib/axiom/relation.rb', line 161 def materialize Materialized.new(header, to_a, directions) end |
#materialized? ⇒ false
Return false for a non-Materialized relation
173 174 175 |
# File 'lib/axiom/relation.rb', line 173 def materialized? false end |
#one ⇒ Tuple
Return a tuple if the relation contains exactly one tuple
129 130 131 132 133 |
# File 'lib/axiom/relation.rb', line 129 def one tuples = to_a assert_exactly_one_tuple(tuples.size) tuples.first end |
#replace(other) ⇒ Relation::Operation::Insertion
Return a relation that represents a replacement of a relation
Delete the tuples from the relation that are not in the other relation, then insert only new tuples.
148 149 150 151 |
# File 'lib/axiom/relation.rb', line 148 def replace(other) other = coerce(other) delete(difference(other)).insert(other.difference(self)) end |