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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83f3d7ebfe5587af85b9823b7ab5a9d11d6e9b30
4
- data.tar.gz: 34418e3d5ccfe156c3b0320e6821030a09ba1cdc
3
+ metadata.gz: 91f0681124b487847c3af44ea65635ebb02df727
4
+ data.tar.gz: e7613c53a87c753c3a8a8dfb5876de592219b0c3
5
5
  SHA512:
6
- metadata.gz: f1e68f36ad0cd1a5c9ba2d2dd5fdcd8f02220c3588e5ef995439db58c46dab2bb6fa91ff249f3541ae2096e9d12f3c0d9a9d424c99310c7e90fef7cd4f460994
7
- data.tar.gz: 0c9c97791462f47799be4ae510d5be7b0aa3c30360592899fbfb336f31c25762d8fe5d35d87202413f85916ce8fc9199c48d40a26a22b480fc72d497edbe1f1d
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
- elements in the same database (e.g. tuples from other relvars).
206
- The serializer is either `:marshal` or `:json`. Please note that
207
- types are not preserved when using the second one (all attribute
208
- values will come back as strings, but keys will be symbolized).
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, ...]) # natural join on a join key
255
- r.join(right, :a => :x, :b => :y, ...) # natural join after right reversed renaming
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
- t.transform(:to_s) # all-attrs transformation
271
- t.transform(&:to_s) # similar, but Proc-driven
272
- t.transform(:foo => :upcase, ...) # specific-attrs tranformation
273
- t.transform([:to_s, :upcase]) # chain-transformation
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
- private
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
@@ -2,7 +2,7 @@ module Bmg
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 21
5
- TINY = 3
5
+ TINY = 5
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.21.3
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-01-18 00:00:00.000000000 Z
11
+ date: 2024-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: predicate