module Bmg
Constants
- Leaf
Deprecated
- VERSION
Public Class Methods
csv(path, options = {}, type = Type::ANY)
click to toggle source
# File lib/bmg.rb, line 17 def csv(path, options = {}, type = Type::ANY) Reader::Csv.new(type, path, options).spied(main_spy) end
excel(path, options = {}, type = Type::ANY)
click to toggle source
# File lib/bmg.rb, line 22 def excel(path, options = {}, type = Type::ANY) Reader::Excel.new(type, path, options).spied(main_spy) end
in_memory(enumerable, type = Type::ANY)
click to toggle source
# File lib/bmg.rb, line 7 def in_memory(enumerable, type = Type::ANY) Relation::InMemory.new(type, enumerable).spied(main_spy) end
main_spy()
click to toggle source
# File lib/bmg.rb, line 27 def main_spy @main_spy end
main_spy=(spy)
click to toggle source
# File lib/bmg.rb, line 32 def main_spy=(spy) @main_spy = spy end
sequel(source, sequel_db = nil, type = nil)
click to toggle source
Builds a Relation
that uses Sequel
for managing real data accesses.
Supported signatures:
# Table name, providing the Sequel's Database object Bmg.sequel(:suppliers, DB) # Sequel dataset object, embedding the Database object # `from_self` will be used at compilation time, you don't # need to call it yourself. Bmg.sequel(DB[:suppliers]) # Similar, but with with a pure SQL query Bmg.sequel(DB[%Q{SELECT ... FROM ...}]) # All signatures above with an explicit type object, e.g.: Bmg.sequel(:suppliers, DB, Type::ANY) Bmg.sequel(DB[:suppliers], Type::ANY)
# File lib/bmg/sequel.rb, line 57 def sequel(source, sequel_db = nil, type = nil) Sequel.sequel(source, sequel_db, type) end
sql(table, type = Type::ANY)
click to toggle source
# File lib/bmg/sql.rb, line 10 def sql(table, type = Type::ANY) builder = Sql::Builder.new sexpr = builder.select_star_from(table) Sql::Relation.new(type, builder, sexpr).spied(main_spy) end
text_file(path, options = {}, type = Type::ANY)
click to toggle source
# File lib/bmg.rb, line 12 def text_file(path, options = {}, type = Type::ANY) Reader::TextFile.new(type, path, options).spied(main_spy) end
Public Instance Methods
_join(type, right, on)
click to toggle source
Calls superclass method
# File lib/bmg/operator/autowrap.rb, line 72 def _join(type, right, on) if _join_optimizable?(type, right, on) operand.join(right, on).autowrap(options) else super end end
_join_optimizable?(type, right, on)
click to toggle source
# File lib/bmg/operator/autowrap.rb, line 88 def _join_optimizable?(type, right, on) # 1. Can't optimize if wrapped roots are used in join clause # 2. Can't optimize if other attributes would be autowrapped (wrapped_roots! & on).empty? && wrapped_roots_of!(right, options).empty? rescue UnknownAttributesError false end
_joined_with(type, right, on)
click to toggle source
Calls superclass method
# File lib/bmg/operator/autowrap.rb, line 80 def _joined_with(type, right, on) if _join_optimizable?(type, right, on) right.join(operand, on).autowrap(options) else super end end
_matching(type, right, on)
click to toggle source
Calls superclass method
# File lib/bmg/operator/autowrap.rb, line 96 def _matching(type, right, on) if (wrapped_roots! & on).empty? operand.matching(right, on).autowrap(options) else super end rescue UnknownAttributesError super end
_not_matching(type, right, on = [])
click to toggle source
Calls superclass method
# File lib/bmg/operator/extend.rb, line 97 def _not_matching(type, right, on = []) ext_keys = extension.keys if (ext_keys & on).empty? operand.not_matching(right, on).extend(extension) else super end end
_page(type, ordering, page_index, opts)
click to toggle source
Calls superclass method
# File lib/bmg/operator/autowrap.rb, line 106 def _page(type, ordering, page_index, opts) attrs = ordering.map{|(a,d)| a } if (wrapped_roots! & attrs).empty? operand.page(ordering, page_index, opts).autowrap(options) else super end rescue UnknownAttributesError super end
_project(type, attrlist)
click to toggle source
Calls superclass method
# File lib/bmg/operator/autowrap.rb, line 117 def _project(type, attrlist) if (wrapped_roots! & attrlist).empty? operand.project(attrlist).autowrap(options) else super end rescue UnknownAttributesError super end
_rename(type, renaming)
click to toggle source
Calls superclass method
# File lib/bmg/operator/autowrap.rb, line 127 def _rename(type, renaming) # 1. Can't optimize if renaming applies to a wrapped one return super unless (wrapped_roots! & renaming.keys).empty? # 2. Can't optimize if new attributes would be autowrapped new_roots = Support.wrapped_roots(renaming.values, options[:split]) return super unless new_roots.empty? operand.rename(renaming).autowrap(options) rescue UnknownAttributesError super end
_restrict(type, predicate)
click to toggle source
Calls superclass method
# File lib/bmg/operator/autowrap.rb, line 140 def _restrict(type, predicate) vars = predicate.free_variables if (wrapped_roots! & vars).empty? operand.restrict(predicate).autowrap(options) else super end rescue UnknownAttributesError super end
args()
click to toggle source
# File lib/bmg/operator/allbut.rb, line 99 def args [ butlist ] end
Private Instance Methods
csv(path, options = {}, type = Type::ANY)
click to toggle source
# File lib/bmg.rb, line 17 def csv(path, options = {}, type = Type::ANY) Reader::Csv.new(type, path, options).spied(main_spy) end
empty_group()
click to toggle source
# File lib/bmg/operator/group.rb, line 79 def empty_group Relation::InMemory.new(group_type, Set.new) end
excel(path, options = {}, type = Type::ANY)
click to toggle source
# File lib/bmg.rb, line 22 def excel(path, options = {}, type = Type::ANY) Reader::Excel.new(type, path, options).spied(main_spy) end
group_type()
click to toggle source
# File lib/bmg/operator/group.rb, line 83 def group_type operand.type.project(attrs) end
in_memory(enumerable, type = Type::ANY)
click to toggle source
# File lib/bmg.rb, line 7 def in_memory(enumerable, type = Type::ANY) Relation::InMemory.new(type, enumerable).spied(main_spy) end
init(key, tuple)
click to toggle source
Returns the initial tuple to use for a given determinant.
# File lib/bmg/operator/autosummarize.rb, line 96 def init(key, tuple) tuple.each_with_object({}){|(k,v),h| h.merge!(k => summarizer(k).init(v)) } end
key(tuple)
click to toggle source
Returns the tuple determinant.
# File lib/bmg/operator/autosummarize.rb, line 91 def key(tuple) @by.map{|by| tuple[by] } end
main_spy()
click to toggle source
# File lib/bmg.rb, line 27 def main_spy @main_spy end
main_spy=(spy)
click to toggle source
# File lib/bmg.rb, line 32 def main_spy=(spy) @main_spy = spy end
sequel(source, sequel_db = nil, type = nil)
click to toggle source
Builds a Relation
that uses Sequel
for managing real data accesses.
Supported signatures:
# Table name, providing the Sequel's Database object Bmg.sequel(:suppliers, DB) # Sequel dataset object, embedding the Database object # `from_self` will be used at compilation time, you don't # need to call it yourself. Bmg.sequel(DB[:suppliers]) # Similar, but with with a pure SQL query Bmg.sequel(DB[%Q{SELECT ... FROM ...}]) # All signatures above with an explicit type object, e.g.: Bmg.sequel(:suppliers, DB, Type::ANY) Bmg.sequel(DB[:suppliers], Type::ANY)
# File lib/bmg/sequel.rb, line 57 def sequel(source, sequel_db = nil, type = nil) Sequel.sequel(source, sequel_db, type) end
sql(table, type = Type::ANY)
click to toggle source
# File lib/bmg/sql.rb, line 10 def sql(table, type = Type::ANY) builder = Sql::Builder.new sexpr = builder.select_star_from(table) Sql::Relation.new(type, builder, sexpr).spied(main_spy) end
sum(memo, tuple)
click to toggle source
Sums `tuple` on `memo`, returning the new tuple to use as memo.
# File lib/bmg/operator/autosummarize.rb, line 108 def sum(memo, tuple) tuple.each_with_object(memo.dup){|(k,v),h| h.merge!(k => summarizer(k).sum(h[k], v)) } end
summarizer(k)
click to toggle source
Returns the summarizer to use for a given key.
# File lib/bmg/operator/autosummarize.rb, line 103 def summarizer(k) @sums[k] || Same.new end
term(tuple)
click to toggle source
Terminates the summarization of a given tuple.
# File lib/bmg/operator/autosummarize.rb, line 115 def term(tuple) tuple.each_with_object({}){|(k,v),h| h.merge!(k => summarizer(k).term(v)) } end
text_file(path, options = {}, type = Type::ANY)
click to toggle source
# File lib/bmg.rb, line 12 def text_file(path, options = {}, type = Type::ANY) Reader::TextFile.new(type, path, options).spied(main_spy) end
to_summarizer(x)
click to toggle source
# File lib/bmg/operator/autosummarize.rb, line 121 def to_summarizer(x) case x when :same then Same.new when :group then DistinctList.new else x end end
transformer()
click to toggle source
# File lib/bmg/operator/transform.rb, line 89 def transformer @transformer ||= TupleTransformer.new(transformation) end
tuple_allbut(tuple)
click to toggle source
# File lib/bmg/operator/allbut.rb, line 105 def tuple_allbut(tuple) TupleAlgebra.allbut(tuple, @butlist) end
tuple_project(tuple, on)
click to toggle source
# File lib/bmg/operator/join.rb, line 93 def tuple_project(tuple, on) TupleAlgebra.project(tuple, on) end
valid_tuple!(tuple)
click to toggle source
# File lib/bmg/operator/allbut.rb, line 109 def valid_tuple!(tuple) offending = tuple.keys & butlist raise InvalidUpdateError, "#{offending.inspect} cannot be updated" unless offending.empty? tuple end