bmg 0.18.7 → 0.18.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b7b4d39e83f04ee58369bef32ce396893d5ac98d357fd8c497d309fa17cc93b2
4
- data.tar.gz: b36344887bb1142c4ddd3de0eb4419c0ba1821490a9c8c336668c37008e59156
3
+ metadata.gz: 9489f2f59b1f3fc644c4a29ee53ba08662f9671ebda9cc6b0340a98c6daf20d9
4
+ data.tar.gz: f0506ba0dbea31d5d3a1c3f4e3edbdf0ea9ef88e40b386445494f6cd61f759c1
5
5
  SHA512:
6
- metadata.gz: c21cc2eb5c0e0e93cb8c4afc823855140051112f6ac5bd896181634edb67f87fca9b88f4a16c0ec70da36c8ce937e3265ade2506e7077f103e4fb46409b8dded
7
- data.tar.gz: b40c206ad43a6ec36e4951c8ff8d531872154e0e855f055f62059ff3af9f0d35e7d96f2443e8046bd107741c4df481aa4ebc2b680ccf1fc88181b988add1d2d6
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.summary_expr
94
- ::Sequel.function(sexpr.summary_func, apply(sexpr.summary_expr))
93
+ func, distinct = if sexpr.summary_func == :distinct_count
94
+ [:count, true]
95
95
  else
96
- ::Sequel.function(sexpr.summary_func).*
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[attr] ],
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
@@ -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
 
@@ -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.downcase[/::([a-z]+)$/, 1].to_sym
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
@@ -2,7 +2,7 @@ module Bmg
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 18
5
- TINY = 7
5
+ TINY = 8
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
8
8
  end
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.7
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-14 00:00:00.000000000 Z
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