bmg 0.19.1 → 0.19.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -2
- data/lib/bmg/operator/extend.rb +6 -1
- data/lib/bmg/sequel/translator.rb +1 -0
- data/lib/bmg/sql/processor/extend.rb +33 -0
- data/lib/bmg/sql/processor/reorder.rb +1 -1
- data/lib/bmg/sql/processor/where.rb +2 -1
- data/lib/bmg/sql/processor.rb +1 -0
- data/lib/bmg/sql/relation.rb +17 -0
- data/lib/bmg/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 611ca787e8f1fa6fc240f245bb27a606be9ff9a2
|
4
|
+
data.tar.gz: 6b573c0c20c2224595bdc00af3c9892de6ce7483
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ac0ab63a95c91e9cdaa8b6774d3cc5d576017b42807fd6ecef2918d2efedec7a16c67f4089fc288a1b9e9a61edbab78db4da1d87cfae039242d079068ee476a
|
7
|
+
data.tar.gz: 688d057048b65194aafb7ce42b58f8b0b4e7cb6f99e5816f404fcb2d1946d70d68a92a5982fafe5046e73affa4999113111b5b75b4a2bd09e42bc19d720256ce
|
data/README.md
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# Bmg, a relational algebra (Alf's successor)!
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.com/enspirit/bmg.svg?branch=master)](https://travis-ci.com/enspirit/bmg)
|
4
|
-
|
5
3
|
Bmg is a relational algebra implemented as a ruby library. It implements the
|
6
4
|
[Relation as First-Class Citizen](http://www.try-alf.org/blog/2013-10-21-relations-as-first-class-citizen)
|
7
5
|
paradigm contributed with [Alf](http://www.try-alf.org/) a few years ago.
|
@@ -210,6 +208,7 @@ r.autowrap(split: '_') # structure a flat relation, split:
|
|
210
208
|
r.autosummarize([:a, :b, ...], x: :sum) # (experimental) usual summarizers supported
|
211
209
|
r.constants(x: 12, ...) # add constant attributes (sometimes useful in unions)
|
212
210
|
r.extend(x: ->(t){ ... }, ...) # add computed attributes
|
211
|
+
r.extend(x: :y) # shortcut for r.extend(x: ->(t){ t[:y] })
|
213
212
|
r.exclude(predicate) # shortcut for restrict(!predicate)
|
214
213
|
r.group([:a, :b, ...], :x) # relation-valued attribute from attributes
|
215
214
|
r.image(right, :x, [:a, :b, ...]) # relation-valued attribute from another relation
|
data/lib/bmg/operator/extend.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Bmg
|
2
|
+
module Sql
|
3
|
+
class Processor
|
4
|
+
class Extend < Processor
|
5
|
+
|
6
|
+
def initialize(extension, builder)
|
7
|
+
super(builder)
|
8
|
+
@extension = extension
|
9
|
+
end
|
10
|
+
attr_reader :extension
|
11
|
+
|
12
|
+
def on_set_operator(sexpr)
|
13
|
+
apply(builder.from_self(sexpr))
|
14
|
+
end
|
15
|
+
alias :on_union :on_set_operator
|
16
|
+
alias :on_except :on_set_operator
|
17
|
+
alias :on_intersect :on_set_operator
|
18
|
+
|
19
|
+
def on_select_star(sexpr)
|
20
|
+
raise NotImplementedError, "Extend on * is not supported"
|
21
|
+
end
|
22
|
+
|
23
|
+
def on_select_list(sexpr)
|
24
|
+
sexpr + extension.each_pair.map{|(k,v)|
|
25
|
+
desaliased = sexpr.desaliaser[v]
|
26
|
+
[:select_item, desaliased, [:column_name, k] ]
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
end # class Extend
|
31
|
+
end # class Processor
|
32
|
+
end # module Sql
|
33
|
+
end # module Bmg
|
@@ -39,9 +39,10 @@ module Bmg
|
|
39
39
|
def falsy?(sexpr)
|
40
40
|
return false unless sexpr.respond_to?(:predicate)
|
41
41
|
return false if sexpr.predicate.nil?
|
42
|
+
|
42
43
|
left = Predicate.new(Predicate::Grammar.sexpr(sexpr.predicate)).unqualify
|
43
44
|
right = Predicate.new(Predicate::Grammar.sexpr(@predicate.sexpr)).unqualify
|
44
|
-
|
45
|
+
(left & right).contradiction?
|
45
46
|
end
|
46
47
|
|
47
48
|
end # class Where
|
data/lib/bmg/sql/processor.rb
CHANGED
@@ -71,6 +71,7 @@ require_relative 'processor/distinct'
|
|
71
71
|
require_relative 'processor/all'
|
72
72
|
require_relative 'processor/clip'
|
73
73
|
require_relative 'processor/constants'
|
74
|
+
require_relative 'processor/extend'
|
74
75
|
require_relative 'processor/star'
|
75
76
|
require_relative 'processor/rename'
|
76
77
|
require_relative 'processor/order_by'
|
data/lib/bmg/sql/relation.rb
CHANGED
@@ -57,6 +57,23 @@ module Bmg
|
|
57
57
|
_instance(type, builder, expr)
|
58
58
|
end
|
59
59
|
|
60
|
+
def _extend(type, extension)
|
61
|
+
supported, unsupported = {}, {}
|
62
|
+
extension.each_pair do |k,v|
|
63
|
+
(v.is_a?(Symbol) ? supported : unsupported)[k] = v
|
64
|
+
end
|
65
|
+
if supported.empty?
|
66
|
+
Operator::Extend.new(type, self, extension)
|
67
|
+
elsif unsupported.empty?
|
68
|
+
expr = Processor::Extend.new(supported, builder).call(self.expr)
|
69
|
+
_instance(type, builder, expr)
|
70
|
+
else
|
71
|
+
expr = Processor::Extend.new(supported, builder).call(self.expr)
|
72
|
+
operand = _instance(type.allbut(unsupported.keys), builder, expr)
|
73
|
+
Operator::Extend.new(type, operand, unsupported)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
60
77
|
def _join(type, right, on)
|
61
78
|
if right_expr = extract_compatible_sexpr(right)
|
62
79
|
right_expr = Processor::Requalify.new(builder).call(right_expr)
|
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.19.
|
4
|
+
version: 0.19.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: 2022-04-
|
11
|
+
date: 2022-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: predicate
|
@@ -248,6 +248,7 @@ files:
|
|
248
248
|
- lib/bmg/sql/processor/clip.rb
|
249
249
|
- lib/bmg/sql/processor/constants.rb
|
250
250
|
- lib/bmg/sql/processor/distinct.rb
|
251
|
+
- lib/bmg/sql/processor/extend.rb
|
251
252
|
- lib/bmg/sql/processor/flatten.rb
|
252
253
|
- lib/bmg/sql/processor/from_self.rb
|
253
254
|
- lib/bmg/sql/processor/join.rb
|