bmg 0.18.1 → 0.18.2

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: 1e47d2972990cc85ae0a3b99fa6a79caf97176e46c7d70cdbbbb35ffdb3df21a
4
- data.tar.gz: dd7ddf0c123a9347f517da44cc923ec9664c8a1fd12b9e8f0ed08677be2dcdd4
3
+ metadata.gz: 2c9b490328160c9816102f7dd34b3ee46207ab4362cd2af6d8623c9fc5d4b87a
4
+ data.tar.gz: d113dc14ae1811f2b5565af9e84a0ffbc82b7842c46284af7fcad3bc9f3b7470
5
5
  SHA512:
6
- metadata.gz: 929f4c67a01d756b484e9ae27e5465173a4a1850686a173a8ab293dbe1e1ba01899c1ab21a8e2f29251378d0354287e379e7573ae551d3aef0583a0690640375
7
- data.tar.gz: 3a92ab6c7708badf0464a94c496000eb55d233fb979bfd7128b71f3229347fa56c38be381815dbbc7eb0f741b58138f89551080e7670b3b044dfbba6571ac892
6
+ metadata.gz: fd42b8787cc093c6452386760744d7480c64c8be186ab73b87a548a1b853643b46a6ad48cf019da9d77fddbb38c824eb0e0bef3ef5fa2f333f1d1240f5a0bd84
7
+ data.tar.gz: 7bd0cd32a28963123b03b59152fa03d6470bbdf1a3c6cfe0b17a6667a80d97e65d5309def4e31ec9cbb47353d409ad9ad2a6d1fbc9c2ec10797460852836ce35
@@ -74,15 +74,19 @@ module Bmg
74
74
  operand.matching(right, on).allbut(butlist)
75
75
  end
76
76
 
77
- def _restrict(type, predicate)
78
- operand.restrict(predicate).allbut(butlist)
79
- end
80
-
81
77
  def _page(type, ordering, page_index, options)
82
78
  return super unless self.preserving_key?
83
79
  operand.page(ordering, page_index, options).allbut(butlist)
84
80
  end
85
81
 
82
+ def _project(type, attrlist)
83
+ operand.project(attrlist)
84
+ end
85
+
86
+ def _restrict(type, predicate)
87
+ operand.restrict(predicate).allbut(butlist)
88
+ end
89
+
86
90
  protected ### inspect
87
91
 
88
92
  def preserving_key?
@@ -57,6 +57,12 @@ module Bmg
57
57
  [:autosummarize, operand.to_ast, by.dup, sums.dup]
58
58
  end
59
59
 
60
+ public ### for internal reasons
61
+
62
+ def _count
63
+ operand._count
64
+ end
65
+
60
66
  protected
61
67
 
62
68
  def _restrict(type, predicate)
@@ -52,6 +52,12 @@ module Bmg
52
52
  [ :autowrap, operand.to_ast, @original_options.dup ]
53
53
  end
54
54
 
55
+ public ### for internal reasons
56
+
57
+ def _count
58
+ operand._count
59
+ end
60
+
55
61
  protected ### optimization
56
62
 
57
63
  def _autowrap(type, opts)
@@ -92,6 +98,8 @@ module Bmg
92
98
  else
93
99
  super
94
100
  end
101
+ rescue UnknownAttributesError
102
+ super
95
103
  end
96
104
 
97
105
  def _page(type, ordering, page_index, opts)
@@ -105,6 +113,16 @@ module Bmg
105
113
  super
106
114
  end
107
115
 
116
+ def _project(type, attrlist)
117
+ if (wrapped_roots! & attrlist).empty?
118
+ operand.project(attrlist).autowrap(options)
119
+ else
120
+ super
121
+ end
122
+ rescue UnknownAttributesError
123
+ super
124
+ end
125
+
108
126
  def _rename(type, renaming)
109
127
  # 1. Can't optimize if renaming applies to a wrapped one
110
128
  return super unless (wrapped_roots! & renaming.keys).empty?
@@ -54,6 +54,12 @@ module Bmg
54
54
  [ :constants, operand.to_ast, constants.dup ]
55
55
  end
56
56
 
57
+ public ### for internal reasons
58
+
59
+ def _count
60
+ operand._count
61
+ end
62
+
57
63
  protected ### optimization
58
64
 
59
65
  def _page(type, ordering, page_index, options)
@@ -53,6 +53,12 @@ module Bmg
53
53
  [ :extend, operand.to_ast, extension.dup ]
54
54
  end
55
55
 
56
+ public ### for internal reasons
57
+
58
+ def _count
59
+ operand._count
60
+ end
61
+
56
62
  protected ### optimization
57
63
 
58
64
  def _allbut(type, butlist)
@@ -155,6 +155,12 @@ module Bmg
155
155
  end
156
156
  end
157
157
 
158
+ public ### for internal reasons
159
+
160
+ def _count
161
+ left._count
162
+ end
163
+
158
164
  protected ### optimization
159
165
 
160
166
  def _allbut(type, butlist)
@@ -185,6 +191,14 @@ module Bmg
185
191
  end
186
192
  end
187
193
 
194
+ def _project(type, attrlist)
195
+ if attrlist.include?(as)
196
+ super
197
+ else
198
+ left.project(attrlist)
199
+ end
200
+ end
201
+
188
202
  def _restrict(type, predicate)
189
203
  on_as, rest = predicate.and_split([as])
190
204
  if rest.tautology?
@@ -31,7 +31,7 @@ module Bmg
31
31
  def each
32
32
  seen = {}
33
33
  @operand.each do |tuple|
34
- projected = project(tuple)
34
+ projected = tuple_project(tuple)
35
35
  unless seen.has_key?(projected)
36
36
  yield(projected)
37
37
  seen[projected] = true
@@ -74,7 +74,7 @@ module Bmg
74
74
 
75
75
  private
76
76
 
77
- def project(tuple)
77
+ def tuple_project(tuple)
78
78
  tuple.dup.delete_if{|k,_| !@attrlist.include?(k) }
79
79
  end
80
80
 
@@ -60,6 +60,12 @@ module Bmg
60
60
  [ :rename, operand.to_ast, renaming.dup ]
61
61
  end
62
62
 
63
+ public ### for internal reasons
64
+
65
+ def _count
66
+ operand._count
67
+ end
68
+
63
69
  protected ### optimization
64
70
 
65
71
  def _page(type, ordering, page_index, options)
data/lib/bmg/relation.rb CHANGED
@@ -110,6 +110,18 @@ module Bmg
110
110
  end
111
111
  end
112
112
 
113
+ def count
114
+ if type.knows_keys?
115
+ project(type.keys.first)._count
116
+ else
117
+ self._count
118
+ end
119
+ end
120
+
121
+ def _count
122
+ to_a.size
123
+ end
124
+
113
125
  # Returns a json representation
114
126
  def to_json(*args, &bl)
115
127
  to_a.to_json(*args, &bl)
@@ -19,6 +19,10 @@ module Bmg
19
19
  def each(&bl)
20
20
  end
21
21
 
22
+ def _count
23
+ 0
24
+ end
25
+
22
26
  def to_ast
23
27
  [ :empty ]
24
28
  end
@@ -17,6 +17,16 @@ module Bmg
17
17
  @operand.each(&bl)
18
18
  end
19
19
 
20
+ def _count
21
+ if operand.respond_to?(:count)
22
+ operand.count
23
+ elsif operand.respond_to?(:size)
24
+ operand.size
25
+ else
26
+ super
27
+ end
28
+ end
29
+
20
30
  def to_ast
21
31
  [ :in_memory, operand ]
22
32
  end
@@ -16,6 +16,12 @@ module Bmg
16
16
  end
17
17
  protected :type=
18
18
 
19
+ public
20
+
21
+ def _count
22
+ operand._count
23
+ end
24
+
19
25
  public
20
26
 
21
27
  def each(&bl)
@@ -28,6 +28,11 @@ module Bmg
28
28
  operand.each(&bl)
29
29
  end
30
30
 
31
+ def count
32
+ spy.call(self) if bl
33
+ operand.count
34
+ end
35
+
31
36
  def to_ast
32
37
  [ :spied, operand.to_ast, spy ]
33
38
  end
@@ -33,6 +33,10 @@ module Bmg
33
33
  base_table.update(arg)
34
34
  end
35
35
 
36
+ def _count
37
+ dataset.count
38
+ end
39
+
36
40
  def to_ast
37
41
  [:sequel, dataset.sql]
38
42
  end
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 = 1
5
+ TINY = 2
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.1
4
+ version: 0.18.2
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-04-15 00:00:00.000000000 Z
11
+ date: 2021-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: predicate