Sha256: 2ea15c00ada0eb8a48c029d89a3848484d3a0c08a5e8aa4fa755d2d892fa8ae8

Contents?: true

Size: 1.39 KB

Versions: 26

Compression:

Stored size: 1.39 KB

Contents

module Bmg
  module Sql
    class Processor
      class Summarize < Processor

        def initialize(by, summarization, builder)
          super(builder)
          @by = by
          @summarization = summarization
        end
        attr_reader :by, :summarization

        def on_set_operator(sexpr)
          call(builder.from_self(sexpr))
        end
        alias :on_union     :on_set_operator
        alias :on_except    :on_set_operator
        alias :on_intersect :on_set_operator

        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

        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[attr] ],
              [:column_name, attr.to_s] ]
          }
          [:select_list] + by_list + group_list
        end

      end # class Summarize
    end # class Processor
  end # module Sql
end # module Bmg

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
bmg-0.18.7 lib/bmg/sql/processor/summarize.rb
bmg-0.18.6 lib/bmg/sql/processor/summarize.rb
bmg-0.18.5 lib/bmg/sql/processor/summarize.rb
bmg-0.18.4 lib/bmg/sql/processor/summarize.rb
bmg-0.18.3 lib/bmg/sql/processor/summarize.rb
bmg-0.18.2 lib/bmg/sql/processor/summarize.rb
bmg-0.18.1 lib/bmg/sql/processor/summarize.rb
bmg-0.18.0 lib/bmg/sql/processor/summarize.rb
bmg-0.17.8 lib/bmg/sql/processor/summarize.rb
bmg-0.17.7 lib/bmg/sql/processor/summarize.rb
bmg-0.17.6 lib/bmg/sql/processor/summarize.rb
bmg-0.17.5 lib/bmg/sql/processor/summarize.rb
bmg-0.17.4 lib/bmg/sql/processor/summarize.rb
bmg-0.17.3 lib/bmg/sql/processor/summarize.rb
bmg-0.17.2 lib/bmg/sql/processor/summarize.rb
bmg-0.16.7 lib/bmg/sql/processor/summarize.rb
bmg-0.17.1 lib/bmg/sql/processor/summarize.rb
bmg-0.17.0 lib/bmg/sql/processor/summarize.rb
bmg-0.16.6 lib/bmg/sql/processor/summarize.rb
bmg-0.16.5 lib/bmg/sql/processor/summarize.rb