bmg 0.21.3 → 0.21.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -12
- data/lib/bmg/algebra/shortcuts.rb +8 -0
- data/lib/bmg/type.rb +8 -1
- data/lib/bmg/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91f0681124b487847c3af44ea65635ebb02df727
|
4
|
+
data.tar.gz: e7613c53a87c753c3a8a8dfb5876de592219b0c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5948cf2f15c306b95cd289c01ea84602c250655a75de6bd884289efa4c1cb3535acbd811d77166750006f405a2d294a50135bc1eda92f390746aa0ae754c87d8
|
7
|
+
data.tar.gz: 9b82273935815d8808321d08dc292d3e4b3bb81a6eb97ef757715e4d7b0f6ff511d6ea648cb9851dee767cb29bb27559611a31494ad3fdcddbd8298fdcfa40e2
|
data/README.md
CHANGED
@@ -197,15 +197,17 @@ type = Bmg::Type::ANY.with_keys([[:id]])
|
|
197
197
|
r = Bmg.redis(type, {
|
198
198
|
key_prefix: "suppliers",
|
199
199
|
redis: Redis.new,
|
200
|
-
serializer: :marshal
|
200
|
+
serializer: :marshal,
|
201
|
+
ttl: 365 * 24 * 60 * 60
|
201
202
|
})
|
202
203
|
```
|
203
204
|
|
204
|
-
The key prefix will be used to distinguish the tuples from other
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
205
|
+
The key prefix will be used to distinguish the tuples from other elements in the
|
206
|
+
same database (e.g. tuples from other relvars). The serializer is either
|
207
|
+
`:marshal` or `:json`. Please note that types are not preserved when using the
|
208
|
+
second one (all attribute values will come back as strings, but keys will be
|
209
|
+
symbolized). The `ttl` is used to set the validity period of a tuple in redis
|
210
|
+
and is optional.
|
209
211
|
|
210
212
|
The redis relvars support basic algorithms for insert/update/delete.
|
211
213
|
No optimization is currently supported.
|
@@ -245,14 +247,15 @@ r.allbut([:a, :b, ...]) # remove specified attributes
|
|
245
247
|
r.autowrap(split: '_') # structure a flat relation, split: '_' is the default
|
246
248
|
r.autosummarize([:a, :b, ...], x: :sum) # (experimental) usual summarizers supported
|
247
249
|
r.constants(x: 12, ...) # add constant attributes (sometimes useful in unions)
|
250
|
+
r.cross_product(right) # cross product, alias `cross_join`
|
248
251
|
r.extend(x: ->(t){ ... }, ...) # add computed attributes
|
249
252
|
r.extend(x: :y) # shortcut for r.extend(x: ->(t){ t[:y] })
|
250
253
|
r.exclude(predicate) # shortcut for restrict(!predicate)
|
251
254
|
r.group([:a, :b, ...], :x) # relation-valued attribute from attributes
|
252
255
|
r.image(right, :x, [:a, :b, ...]) # relation-valued attribute from another relation
|
253
256
|
r.images({:x => r1, :y => r2}, [:a, ...]) # shortcut over image(r1, :x, ...).image(r2, :y, ...)
|
254
|
-
r.join(right, [:a, :b, ...]) #
|
255
|
-
r.join(right, :a => :x, :b => :y, ...) #
|
257
|
+
r.join(right, [:a, :b, ...]) # join on a join key
|
258
|
+
r.join(right, :a => :x, :b => :y, ...) # join after right reversed renaming
|
256
259
|
r.left_join(right, [:a, :b, ...], {...}) # left join with optional default right tuple
|
257
260
|
r.left_join(right, {:a => :x, ...}, {...}) # left join after right reversed renaming
|
258
261
|
r.matching(right, [:a, :b, ...]) # semi join, aka where exists
|
@@ -267,10 +270,10 @@ r.restrict(a: "foo", b: "bar", ...) # relational restriction, aka where
|
|
267
270
|
r.rxmatch([:a, :b, ...], /xxx/) # regex match kind of restriction
|
268
271
|
r.summarize([:a, :b, ...], x: :sum) # relational summarization
|
269
272
|
r.suffix(:_foo, but: [:a, ...]) # suffix kind of renaming
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
273
|
+
r.transform(:to_s) # all-attrs transformation
|
274
|
+
r.transform(&:to_s) # similar, but Proc-driven
|
275
|
+
r.transform(:foo => :upcase, ...) # specific-attrs tranformation
|
276
|
+
r.transform([:to_s, :upcase]) # chain-transformation
|
274
277
|
r.ungroup([:a, :b, ...]) # ungroup relation-valued attributes within parent tuple
|
275
278
|
r.ungroup(:a) # shortcut over ungroup([:a])
|
276
279
|
r.union(right) # relational union
|
@@ -57,6 +57,14 @@ module Bmg
|
|
57
57
|
self.left_join(right.rename(renaming), on.keys, *args)
|
58
58
|
end
|
59
59
|
|
60
|
+
def cross_product(right)
|
61
|
+
return join(right) unless self.type.typechecked? || right.type.typechecked?
|
62
|
+
return join(right) unless self.type.knows_attrlist? && right.type.knows_attrlist?
|
63
|
+
|
64
|
+
self.type.cross_join_compatible!(right)
|
65
|
+
return join(right)
|
66
|
+
end
|
67
|
+
|
60
68
|
def matching(right, on = [])
|
61
69
|
return super unless on.is_a?(Hash)
|
62
70
|
renaming = Hash[on.map{|k,v| [v,k] }]
|
data/lib/bmg/type.rb
CHANGED
@@ -310,7 +310,7 @@ module Bmg
|
|
310
310
|
}
|
311
311
|
end
|
312
312
|
|
313
|
-
|
313
|
+
public
|
314
314
|
|
315
315
|
def known_attributes!(attrs)
|
316
316
|
extra = attrs - self.attrlist
|
@@ -331,5 +331,12 @@ module Bmg
|
|
331
331
|
end
|
332
332
|
end
|
333
333
|
|
334
|
+
def cross_join_compatible!(right)
|
335
|
+
shared = self.attrlist & right.type.attrlist
|
336
|
+
unless shared.empty?
|
337
|
+
raise TypeError, "Cross product incompatible — duplicate attribute(s): #{shared.join(', ')}"
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
334
341
|
end # class Type
|
335
342
|
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.21.
|
4
|
+
version: 0.21.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernard Lambeau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: predicate
|