bmg 0.18.7 → 0.18.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/bmg/sequel/translator.rb +9 -3
 - data/lib/bmg/sql/processor/summarize.rb +2 -2
 - data/lib/bmg/sql/relation.rb +1 -1
 - data/lib/bmg/summarizer.rb +5 -1
 - data/lib/bmg/summarizer/distinct_count.rb +36 -0
 - data/lib/bmg/version.rb +1 -1
 - metadata +3 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 9489f2f59b1f3fc644c4a29ee53ba08662f9671ebda9cc6b0340a98c6daf20d9
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: f0506ba0dbea31d5d3a1c3f4e3edbdf0ea9ef88e40b386445494f6cd61f759c1
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: a3de98440bf031b653d2ef9f7cc6f89ab44969304ca6fdd04cadc514e617a17d5b8b5bfeb791bc03de576acac5431a1d85a52a413f59932aae77ee3f41175ff3
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: b583e4ade1f71740afaf2a43c5a0dad8eb27557de533b4cbd61c7f632e79d612a85340897e01ed571a91572acd4f2ab65c00d2b9e00d4d8a8cc8b97919c46102
         
     | 
| 
         @@ -90,11 +90,17 @@ module Bmg 
     | 
|
| 
       90 
90 
     | 
    
         
             
                  end
         
     | 
| 
       91 
91 
     | 
    
         | 
| 
       92 
92 
     | 
    
         
             
                  def on_summarizer(sexpr)
         
     | 
| 
       93 
     | 
    
         
            -
                    if sexpr. 
     | 
| 
       94 
     | 
    
         
            -
                       
     | 
| 
      
 93 
     | 
    
         
            +
                    func, distinct = if sexpr.summary_func == :distinct_count
         
     | 
| 
      
 94 
     | 
    
         
            +
                      [:count, true]
         
     | 
| 
       95 
95 
     | 
    
         
             
                    else
         
     | 
| 
       96 
     | 
    
         
            -
                       
     | 
| 
      
 96 
     | 
    
         
            +
                      [sexpr.summary_func, false]
         
     | 
| 
       97 
97 
     | 
    
         
             
                    end
         
     | 
| 
      
 98 
     | 
    
         
            +
                    f = if sexpr.summary_expr
         
     | 
| 
      
 99 
     | 
    
         
            +
                      ::Sequel.function(func, apply(sexpr.summary_expr))
         
     | 
| 
      
 100 
     | 
    
         
            +
                    else
         
     | 
| 
      
 101 
     | 
    
         
            +
                      ::Sequel.function(func).*
         
     | 
| 
      
 102 
     | 
    
         
            +
                    end
         
     | 
| 
      
 103 
     | 
    
         
            +
                    distinct ? f.distinct : f
         
     | 
| 
       98 
104 
     | 
    
         
             
                  end
         
     | 
| 
       99 
105 
     | 
    
         | 
| 
       100 
106 
     | 
    
         
             
                  def on_qualified_name(sexpr)
         
     | 
| 
         @@ -36,10 +36,10 @@ module Bmg 
     | 
|
| 
       36 
36 
     | 
    
         
             
                        [:select_item,
         
     | 
| 
       37 
37 
     | 
    
         
             
                          [ :summarizer,
         
     | 
| 
       38 
38 
     | 
    
         
             
                            summarizer.to_summarizer_name,
         
     | 
| 
       39 
     | 
    
         
            -
                            sexpr.desaliaser[ 
     | 
| 
      
 39 
     | 
    
         
            +
                            sexpr.desaliaser[summarizer.functor] ],
         
     | 
| 
       40 
40 
     | 
    
         
             
                          [:column_name, attr.to_s] ]
         
     | 
| 
       41 
41 
     | 
    
         
             
                      }
         
     | 
| 
       42 
     | 
    
         
            -
                      [:select_list] + by_list + group_list
         
     | 
| 
      
 42 
     | 
    
         
            +
                      ([:select_list] + by_list + group_list)
         
     | 
| 
       43 
43 
     | 
    
         
             
                    end
         
     | 
| 
       44 
44 
     | 
    
         | 
| 
       45 
45 
     | 
    
         
             
                  end # class Summarize
         
     | 
    
        data/lib/bmg/sql/relation.rb
    CHANGED
    
    | 
         @@ -160,7 +160,7 @@ module Bmg 
     | 
|
| 
       160 
160 
     | 
    
         | 
| 
       161 
161 
     | 
    
         
             
                  def can_compile_summarization?(summarization)
         
     | 
| 
       162 
162 
     | 
    
         
             
                    summarization.values.all?{|s|
         
     | 
| 
       163 
     | 
    
         
            -
                      [:avg, :count, :max, :min, :sum].include?(s.to_summarizer_name)
         
     | 
| 
      
 163 
     | 
    
         
            +
                      [:avg, :count, :max, :min, :sum, :distinct_count].include?(s.to_summarizer_name)
         
     | 
| 
       164 
164 
     | 
    
         
             
                    }
         
     | 
| 
       165 
165 
     | 
    
         
             
                  end
         
     | 
| 
       166 
166 
     | 
    
         | 
    
        data/lib/bmg/summarizer.rb
    CHANGED
    
    | 
         @@ -131,7 +131,10 @@ module Bmg 
     | 
|
| 
       131 
131 
     | 
    
         | 
| 
       132 
132 
     | 
    
         
             
                # Returns the canonical summarizer name
         
     | 
| 
       133 
133 
     | 
    
         
             
                def to_summarizer_name
         
     | 
| 
       134 
     | 
    
         
            -
                  self.class.name 
     | 
| 
      
 134 
     | 
    
         
            +
                  self.class.name
         
     | 
| 
      
 135 
     | 
    
         
            +
                    .gsub(/[a-z][A-Z]/){|x| x.split('').join('_') }
         
     | 
| 
      
 136 
     | 
    
         
            +
                    .downcase[/::([a-z_]+)$/, 1]
         
     | 
| 
      
 137 
     | 
    
         
            +
                    .to_sym
         
     | 
| 
       135 
138 
     | 
    
         
             
                end
         
     | 
| 
       136 
139 
     | 
    
         | 
| 
       137 
140 
     | 
    
         
             
              protected
         
     | 
| 
         @@ -161,6 +164,7 @@ require_relative 'summarizer/stddev' 
     | 
|
| 
       161 
164 
     | 
    
         
             
            require_relative 'summarizer/percentile'
         
     | 
| 
       162 
165 
     | 
    
         
             
            require_relative 'summarizer/collect'
         
     | 
| 
       163 
166 
     | 
    
         
             
            require_relative 'summarizer/distinct'
         
     | 
| 
      
 167 
     | 
    
         
            +
            require_relative 'summarizer/distinct_count'
         
     | 
| 
       164 
168 
     | 
    
         
             
            require_relative 'summarizer/concat'
         
     | 
| 
       165 
169 
     | 
    
         
             
            require_relative 'summarizer/by_proc'
         
     | 
| 
       166 
170 
     | 
    
         
             
            require_relative 'summarizer/multiple'
         
     | 
| 
         @@ -0,0 +1,36 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Bmg
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Summarizer
         
     | 
| 
      
 3 
     | 
    
         
            +
                #
         
     | 
| 
      
 4 
     | 
    
         
            +
                # Collect the count of distinct values.
         
     | 
| 
      
 5 
     | 
    
         
            +
                #
         
     | 
| 
      
 6 
     | 
    
         
            +
                # Example:
         
     | 
| 
      
 7 
     | 
    
         
            +
                #
         
     | 
| 
      
 8 
     | 
    
         
            +
                #   # direct ruby usage
         
     | 
| 
      
 9 
     | 
    
         
            +
                #   Bmg::Summarizer.distinct_count(:qty).summarize(...)
         
     | 
| 
      
 10 
     | 
    
         
            +
                #
         
     | 
| 
      
 11 
     | 
    
         
            +
                class DistinctCount < Summarizer
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                  # Returns [] as least value.
         
     | 
| 
      
 14 
     | 
    
         
            +
                  def least()
         
     | 
| 
      
 15 
     | 
    
         
            +
                    {}
         
     | 
| 
      
 16 
     | 
    
         
            +
                  end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                  # Adds val to the memo array
         
     | 
| 
      
 19 
     | 
    
         
            +
                  def _happens(memo, val)
         
     | 
| 
      
 20 
     | 
    
         
            +
                    memo[val] = true
         
     | 
| 
      
 21 
     | 
    
         
            +
                    memo
         
     | 
| 
      
 22 
     | 
    
         
            +
                  end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                  def finalize(memo)
         
     | 
| 
      
 25 
     | 
    
         
            +
                    memo.keys.size
         
     | 
| 
      
 26 
     | 
    
         
            +
                  end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                end # class DistinctCount
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                # Factors a distinct count summarizer
         
     | 
| 
      
 31 
     | 
    
         
            +
                def self.distinct_count(*args, &bl)
         
     | 
| 
      
 32 
     | 
    
         
            +
                  DistinctCount.new(*args, &bl)
         
     | 
| 
      
 33 
     | 
    
         
            +
                end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
              end # class Summarizer
         
     | 
| 
      
 36 
     | 
    
         
            +
            end # module Bmg
         
     | 
    
        data/lib/bmg/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: bmg
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.18. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.18.8
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Bernard Lambeau
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2021-06- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2021-06-15 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: predicate
         
     | 
| 
         @@ -273,6 +273,7 @@ files: 
     | 
|
| 
       273 
273 
     | 
    
         
             
            - lib/bmg/summarizer/concat.rb
         
     | 
| 
       274 
274 
     | 
    
         
             
            - lib/bmg/summarizer/count.rb
         
     | 
| 
       275 
275 
     | 
    
         
             
            - lib/bmg/summarizer/distinct.rb
         
     | 
| 
      
 276 
     | 
    
         
            +
            - lib/bmg/summarizer/distinct_count.rb
         
     | 
| 
       276 
277 
     | 
    
         
             
            - lib/bmg/summarizer/max.rb
         
     | 
| 
       277 
278 
     | 
    
         
             
            - lib/bmg/summarizer/min.rb
         
     | 
| 
       278 
279 
     | 
    
         
             
            - lib/bmg/summarizer/multiple.rb
         
     |