Module: Bmg::Relation
- Includes:
- Algebra, Enumerable
- Included in:
- Operator, Reader, Empty, InMemory, Sequel::Relation
- Defined in:
- lib/bmg/relation.rb,
lib/bmg/relation/empty.rb,
lib/bmg/relation/spied.rb,
lib/bmg/relation/in_memory.rb
Defined Under Namespace
Classes: Empty, InMemory, Spied
Constant Summary
Constants included from Algebra
Class Method Summary collapse
Instance Method Summary collapse
-
#debug(max_level = nil, on = STDERR) ⇒ Object
Returns a String representing the query plan.
- #delete ⇒ Object
- #empty? ⇒ Boolean
- #insert(arg) ⇒ Object
-
#one ⇒ Object
Returns the only tuple that the relation contains.
-
#one_or_nil ⇒ Object
Returns the only tuple that the relation contains.
-
#to_ast ⇒ Object
Converts to an sexpr expression.
-
#to_json(*args, &bl) ⇒ Object
Returns a json representation.
- #update(arg) ⇒ Object
- #visit(&visitor) ⇒ Object
- #ys_by_x(y, x, options = {}) ⇒ Object
Methods included from Algebra
#allbut, #autosummarize, #autowrap, #constants, #extend, #image, #matching, #project, #rename, #restrict, #spied, #union, #unspied
Class Method Details
Instance Method Details
#debug(max_level = nil, on = STDERR) ⇒ Object
Returns a String representing the query plan
92 93 94 95 |
# File 'lib/bmg/relation.rb', line 92 def debug(max_level = nil, on = STDERR) on.puts(self.inspect) self end |
#delete ⇒ Object
53 54 55 |
# File 'lib/bmg/relation.rb', line 53 def delete raise InvalidUpdateError, "Cannot delete from this Relvar" end |
#empty? ⇒ Boolean
16 17 18 19 |
# File 'lib/bmg/relation.rb', line 16 def empty? each{|t| return false } true end |
#insert(arg) ⇒ Object
45 46 47 |
# File 'lib/bmg/relation.rb', line 45 def insert(arg) raise InvalidUpdateError, "Cannot insert into this Relvar" end |
#one ⇒ Object
Returns the only tuple that the relation contains. Throws a OneException when there is no tuple or more than one
34 35 36 |
# File 'lib/bmg/relation.rb', line 34 def one one_or_yield{ raise OneError, "Relation is empty" } end |
#one_or_nil ⇒ Object
Returns the only tuple that the relation contains. Returns nil if the relation is empty. Throws a OneException when the relation contains more than one tuple
41 42 43 |
# File 'lib/bmg/relation.rb', line 41 def one_or_nil one_or_yield{ nil } end |
#to_ast ⇒ Object
Converts to an sexpr expression.
87 88 89 |
# File 'lib/bmg/relation.rb', line 87 def to_ast raise "Bmg is missing a feature!" end |
#to_json(*args, &bl) ⇒ Object
Returns a json representation
82 83 84 |
# File 'lib/bmg/relation.rb', line 82 def to_json(*args, &bl) to_a.to_json(*args, &bl) end |
#update(arg) ⇒ Object
49 50 51 |
# File 'lib/bmg/relation.rb', line 49 def update(arg) raise InvalidUpdateError, "Cannot update this Relvar" end |
#visit(&visitor) ⇒ Object
57 58 59 |
# File 'lib/bmg/relation.rb', line 57 def visit(&visitor) _visit(nil, visitor) end |
#ys_by_x(y, x, options = {}) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/bmg/relation.rb', line 66 def ys_by_x(y, x, = {}) ordering = [:order] projection = [y, ordering].compact.uniq by_x = each.each_with_object({}) do |tuple,h| h[tuple[x]] ||= [] h[tuple[x]] << TupleAlgebra.project(tuple, projection) end by_x.each_with_object({}) do |(x,ys),h| ys = ys.sort{|y1,y2| y1[ordering] <=> y2[ordering] } if ordering ys = ys.map{|t| t[y] } ys = ys.uniq if [:distinct] h[x] = ys end end |