Class: Bmg::Sql::Processor::Summarize
- Inherits:
-
Bmg::Sql::Processor
- Object
- Sexpr::Rewriter
- Bmg::Sql::Processor
- Bmg::Sql::Processor::Summarize
- Defined in:
- lib/bmg/sql/processor/summarize.rb
Constant Summary
Constants inherited from Bmg::Sql::Processor
Instance Attribute Summary collapse
-
#by ⇒ Object
readonly
Returns the value of attribute by.
-
#summarization ⇒ Object
readonly
Returns the value of attribute summarization.
Attributes inherited from Bmg::Sql::Processor
Instance Method Summary collapse
-
#initialize(by, summarization, builder) ⇒ Summarize
constructor
A new instance of Summarize.
- #on_select_exp(sexpr) ⇒ Object
- #on_select_list(sexpr) ⇒ Object
- #on_set_operator(sexpr) ⇒ Object (also: #on_union, #on_except, #on_intersect)
Methods inherited from Bmg::Sql::Processor
Constructor Details
#initialize(by, summarization, builder) ⇒ Summarize
Returns a new instance of Summarize.
6 7 8 9 10 |
# File 'lib/bmg/sql/processor/summarize.rb', line 6 def initialize(by, summarization, builder) super(builder) @by = by @summarization = summarization end |
Instance Attribute Details
#by ⇒ Object (readonly)
Returns the value of attribute by.
11 12 13 |
# File 'lib/bmg/sql/processor/summarize.rb', line 11 def by @by end |
#summarization ⇒ Object (readonly)
Returns the value of attribute summarization.
11 12 13 |
# File 'lib/bmg/sql/processor/summarize.rb', line 11 def summarization @summarization end |
Instance Method Details
#on_select_exp(sexpr) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/bmg/sql/processor/summarize.rb', line 20 def on_select_exp(sexpr) if obc = sexpr.group_by_clause sexpr = builder.from_self(sexpr) call(sexpr) else sexpr = sexpr.with_update(:select_list, apply(sexpr.select_list)) group_by = builder.group_by_clause(by, &sexpr.desaliaser) sexpr.push(group_by) end end |
#on_select_list(sexpr) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/bmg/sql/processor/summarize.rb', line 31 def on_select_list(sexpr) by_list = sexpr.sexpr_body.select{|select_item| by.include?(select_item.last.last.to_sym) } group_list = summarization.map{|attr,summarizer| [:select_item, [ :summarizer, summarizer.to_summarizer_name, sexpr.desaliaser[summarizer.functor] ], [:column_name, attr.to_s] ] } ([:select_list] + by_list + group_list) end |
#on_set_operator(sexpr) ⇒ Object Also known as: on_union, on_except, on_intersect
13 14 15 |
# File 'lib/bmg/sql/processor/summarize.rb', line 13 def on_set_operator(sexpr) call(builder.from_self(sexpr)) end |