Class: Bmg::Operator::Autosummarize

Inherits:
Object
  • Object
show all
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

#type

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Unary

#bind

Methods included from Bmg::Operator

#inspect, #to_s

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, options = {})
  @type = type
  @operand = operand
  @by = by
  @sums = sums.each_with_object({}){|(k,v),h| h[k] = to_summarizer(v) }
  @options = DEFAULT_OPTIONS.merge(options)
  @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

.y_by_x(*args) ⇒ Object



41
42
43
# File 'lib/bmg/operator/autosummarize.rb', line 41

def self.y_by_x(*args)
  YByX.new(*args)
end

.ys_by_x(*args) ⇒ Object



45
46
47
# File 'lib/bmg/operator/autosummarize.rb', line 45

def self.ys_by_x(*args)
  YsByX.new(*args)
end

Instance Method Details

#_countObject



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_astObject



63
64
65
# File 'lib/bmg/operator/autosummarize.rb', line 63

def to_ast
  [:autosummarize, operand.to_ast, by.dup, sums.dup, options.dup]
end