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: Check, DistinctList, Same, Trust, YByX, YsByX
Constant Summary collapse
- DEFAULT_OPTIONS =
{ default: :same }
Instance Attribute Summary
Attributes included from Bmg::Operator
Class Method Summary collapse
Instance Method Summary collapse
- #_count ⇒ Object
- #each(&bl) ⇒ Object
-
#initialize(type, operand, by, sums, options = {}) ⇒ Autosummarize
constructor
A new instance of Autosummarize.
- #to_ast ⇒ Object
Methods included from Unary
Methods included from Bmg::Operator
Methods included from Relation
#bind, #count, #debug, #delete, empty, #empty?, #insert, new, #one, #one_or_nil, #to_csv, #to_json, #to_xlsx, #type, #update, #visit, #with_type, #with_type_attrlist, #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, #minus, #not_matching, #page, #project, #rename, #restrict, #spied, #summarize, #transform, #ungroup, #union, #unspied, #unwrap
Methods included from Algebra::Shortcuts
#cross_product, #exclude, #image, #images, #join, #left_join, #matching, #not_matching, #prefix, #rxmatch, #suffix, #ungroup, #unwrap, #where
Constructor Details
#initialize(type, operand, by, sums, options = {}) ⇒ Autosummarize
Returns a new instance of Autosummarize.
18 19 20 21 22 23 24 25 |
# File 'lib/bmg/operator/autosummarize.rb', line 18 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) } @options = DEFAULT_OPTIONS.merge() @algo = build_algo end |
Class Method Details
.group(*args) ⇒ Object
37 38 39 |
# File 'lib/bmg/operator/autosummarize.rb', line 37 def self.group(*args) Group.new(*args) end |
.same(*args) ⇒ Object
33 34 35 |
# File 'lib/bmg/operator/autosummarize.rb', line 33 def self.same(*args) Same.new(*args) end |
Instance Method Details
#_count ⇒ Object
69 70 71 |
# File 'lib/bmg/operator/autosummarize.rb', line 69 def _count operand._count end |
#each(&bl) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/bmg/operator/autosummarize.rb', line 49 def each(&bl) return to_enum unless block_given? h = {} @operand.each do |tuple| key = key(tuple) h[key] ||= @algo.init(tuple) h[key] = @algo.sum(h[key], tuple) end h.each_pair do |k,v| h[k] = @algo.term(v) end h.values.each(&bl) end |
#to_ast ⇒ Object
63 64 65 |
# File 'lib/bmg/operator/autosummarize.rb', line 63 def to_ast [:autosummarize, operand.to_ast, by.dup, sums.dup, .dup] end |