Class: Bmg::Operator::Autosummarize
- Inherits:
-
Object
- Object
- Bmg::Operator::Autosummarize
- Includes:
- Unary
- Defined in:
- lib/bmg/operator/autosummarize.rb
Overview
Autosummarize operator.
Autosummarize helps structuring the results of a big flat join.
This operator is still largely experimental and should be used with care…
Defined Under Namespace
Classes: DistinctList, Same, YByX, YsByX
Instance Attribute Summary
Attributes included from Bmg::Operator
Instance Method Summary collapse
- #each(&bl) ⇒ Object
-
#initialize(type, operand, by, sums) ⇒ Autosummarize
constructor
A new instance of Autosummarize.
- #to_ast ⇒ Object
Methods included from Unary
Methods included from Bmg::Operator
Methods included from Relation
#bind, #debug, #delete, empty, #empty?, #insert, new, #one, #one_or_nil, #to_csv, #to_json, #update, #visit, #with_typecheck, #without_typecheck, #y_by_x, #ys_by_x
Methods included from Algebra
#allbut, #autosummarize, #autowrap, #constants, #extend, #group, #image, #join, #left_join, #matching, #materialize, #not_matching, #page, #project, #rename, #restrict, #spied, #summarize, #transform, #union, #unspied
Methods included from Algebra::Shortcuts
#image, #join, #left_join, #matching, #not_matching, #prefix, #rxmatch, #suffix
Constructor Details
#initialize(type, operand, by, sums) ⇒ Autosummarize
Returns a new instance of Autosummarize.
14 15 16 17 18 19 |
# File 'lib/bmg/operator/autosummarize.rb', line 14 def initialize(type, operand, by, sums) @type = type @operand = operand @by = by @sums = sums.each_with_object({}){|(k,v),h| h[k] = to_summarizer(v) } end |
Instance Method Details
#each(&bl) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bmg/operator/autosummarize.rb', line 27 def each(&bl) h = {} @operand.each do |tuple| key = key(tuple) h[key] ||= init(key, tuple) h[key] = sum(h[key], tuple) end h.each_pair do |k,v| h[k] = term(v) end h.values.each(&bl) end |
#to_ast ⇒ Object
40 41 42 |
# File 'lib/bmg/operator/autosummarize.rb', line 40 def to_ast [:autosummarize, operand.to_ast, by.dup, sums.dup] end |