Class: Bmg::Sql::Processor::Summarize

Inherits:
Bmg::Sql::Processor show all
Defined in:
lib/bmg/sql/processor/summarize.rb

Constant Summary

Constants inherited from Bmg::Sql::Processor

UnexpectedError

Instance Attribute Summary collapse

Attributes inherited from Bmg::Sql::Processor

#builder

Instance Method Summary collapse

Methods inherited from Bmg::Sql::Processor

#on_with_exp

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

#byObject (readonly)

Returns the value of attribute by.



11
12
13
# File 'lib/bmg/sql/processor/summarize.rb', line 11

def by
  @by
end

#summarizationObject (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