Class: Axiom::Relation
- Inherits:
-
Object
- Object
- Axiom::Relation
- Includes:
- Adamantium::Flat, 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/index.rb,
lib/axiom/relation/proxy.rb,
lib/axiom/relation/header.rb,
lib/axiom/relation/variable.rb,
lib/axiom/relation/materialized.rb,
lib/axiom/relation/operation/set.rb,
lib/axiom/relation/operation/wrap.rb,
lib/axiom/relation/operation/group.rb,
lib/axiom/relation/operation/limit.rb,
lib/axiom/relation/operation/unary.rb,
lib/axiom/relation/operation/binary.rb,
lib/axiom/relation/operation/offset.rb,
lib/axiom/relation/operation/sorted.rb,
lib/axiom/relation/operation/unwrap.rb,
lib/axiom/relation/operation/reverse.rb,
lib/axiom/relation/operation/ungroup.rb,
lib/axiom/relation/operation/deletion.rb,
lib/axiom/relation/operation/insertion.rb,
lib/axiom/relation/operation/combination.rb,
lib/axiom/relation/operation/sorted/direction.rb,
lib/axiom/relation/operation/sorted/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::Group, Operation::Insertion, Operation::Limit, Operation::Offset, Operation::Sorted, Operation::Ungroup, Operation::Unwrap, Operation::Wrap, Variable
Defined Under Namespace
Modules: Operation, Proxy Classes: Base, Empty, Header, Index, Keys, Materialized, Variable
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::Sorted::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.
-
#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
86 87 88 89 |
# File 'lib/axiom/relation.rb', line 86 def initialize(header, tuples) @header = Header.coerce(header) @tuples = 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 |
# File 'lib/axiom/relation.rb', line 53 def self.new(*args) if equal?(Relation) && materialized?(args[1]) Materialized.new(*args) else super end end |
Instance Method Details
#==(other) ⇒ Boolean
Compare the relation with other relation for equivalency
197 198 199 200 201 202 |
# File 'lib/axiom/relation.rb', line 197 def ==(other) other = coerce(other) other.kind_of?(Relation) && header == other.header && to_set == other.to_set end |
#[](name) ⇒ Attribute
Lookup an Attribute in the header given an attribute name
102 103 104 |
# File 'lib/axiom/relation.rb', line 102 def [](name) header[name] end |
#directions ⇒ Operation::Sorted::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::Sorted::DirectionSet::EMPTY end |
#each {|tuple| ... } ⇒ self
Iterate over each tuple in the set
120 121 122 123 124 125 126 127 128 |
# File 'lib/axiom/relation.rb', line 120 def each return to_enum unless block_given? seen = {} 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
212 213 214 |
# File 'lib/axiom/relation.rb', line 212 def empty? none? end |
#include?(tuple) ⇒ Boolean
Test if the tuple exists in the relation
182 183 184 |
# File 'lib/axiom/relation.rb', line 182 def include?(tuple) to_set.include?(tuple) end |
#materialize ⇒ Materialized
Return a relation with each tuple materialized
156 157 158 |
# File 'lib/axiom/relation.rb', line 156 def materialize Materialized.new(header, to_a, directions) end |
#materialized? ⇒ false
Return false for a non-Materialized relation
168 169 170 |
# File 'lib/axiom/relation.rb', line 168 def materialized? false 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.
143 144 145 146 |
# File 'lib/axiom/relation.rb', line 143 def replace(other) other = coerce(other) delete(difference(other)).insert(other.difference(self)) end |