bmg 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bmg/algebra.rb +9 -0
- data/lib/bmg/operator.rb +1 -0
- data/lib/bmg/operator/matching.rb +80 -0
- data/lib/bmg/sequel/relation.rb +10 -1
- data/lib/bmg/type.rb +4 -0
- data/lib/bmg/version.rb +2 -2
- metadata +2 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd47ac94bb3775d03bddef092ad532dc4c3463c5
|
4
|
+
data.tar.gz: 1a8fd964c8e074f1632cf1067050f1581efad8ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95c27ba47fe64d1624b9dc8129f9b8071c8e313919e594dd7fa8e82958187d45dc4bebb8b6406029d70b728c29ca79d43add0bc323642270e279e2638d272ff7
|
7
|
+
data.tar.gz: 0eb469720408c4c38b0680c67504c9f1853387f7d09c5cd4d4d980af303ea482e9decdffee16c19247885e0ad9df8513b7bfbff9a2ce2cf84e9f9cdc8e737705
|
data/lib/bmg/algebra.rb
CHANGED
@@ -68,6 +68,15 @@ module Bmg
|
|
68
68
|
end
|
69
69
|
protected :_image
|
70
70
|
|
71
|
+
def matching(right, on = [])
|
72
|
+
_matching self.type.matching(right, on), right, on
|
73
|
+
end
|
74
|
+
|
75
|
+
def _matching(type, right, on)
|
76
|
+
Operator::Matching.new(type, self, right, on)
|
77
|
+
end
|
78
|
+
protected :_matching
|
79
|
+
|
71
80
|
def project(attrlist = [])
|
72
81
|
_project self.type.project(attrlist), attrlist
|
73
82
|
end
|
data/lib/bmg/operator.rb
CHANGED
@@ -0,0 +1,80 @@
|
|
1
|
+
module Bmg
|
2
|
+
module Operator
|
3
|
+
#
|
4
|
+
# Image operator.
|
5
|
+
#
|
6
|
+
# Extends each tuple with its image in right.
|
7
|
+
#
|
8
|
+
class Matching
|
9
|
+
include Operator::Binary
|
10
|
+
|
11
|
+
def initialize(type, left, right, on)
|
12
|
+
@type = type
|
13
|
+
@left = left
|
14
|
+
@right = right
|
15
|
+
@on = on
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :on
|
21
|
+
|
22
|
+
public
|
23
|
+
|
24
|
+
def each
|
25
|
+
index = Hash.new
|
26
|
+
right.each_with_object(index) do |t, index|
|
27
|
+
key = tuple_project(t, on)
|
28
|
+
index[key] = true
|
29
|
+
end
|
30
|
+
left.each do |tuple|
|
31
|
+
key = tuple_project(tuple, on)
|
32
|
+
yield tuple if index.has_key?(key)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_ast
|
37
|
+
[ :matching, left.to_ast, right.to_ast, on ]
|
38
|
+
end
|
39
|
+
|
40
|
+
protected ### optimization
|
41
|
+
|
42
|
+
def _restrict(type, predicate)
|
43
|
+
# Predicate can always be fully applied to left
|
44
|
+
new_left = left.restrict(predicate)
|
45
|
+
|
46
|
+
# regarding right... the predicate possibly makes references
|
47
|
+
# to the join key, but also to left attributes... let split
|
48
|
+
# on the join key attributes, to try to remove spurious
|
49
|
+
# attributes for right...
|
50
|
+
on_on_and_more, left_only = predicate.and_split(on)
|
51
|
+
|
52
|
+
# it's not guaranteed! let now check whether the split led
|
53
|
+
# to a situation where the predicate on `on` attributes
|
54
|
+
# actually refers to no other ones...
|
55
|
+
if !on_on_and_more.tautology? and (on_on_and_more.free_variables - on).empty?
|
56
|
+
new_right = right.restrict(on_on_and_more)
|
57
|
+
else
|
58
|
+
new_right = right
|
59
|
+
end
|
60
|
+
|
61
|
+
new_left.matching(new_right)
|
62
|
+
rescue Predicate::NotSupportedError
|
63
|
+
super
|
64
|
+
end
|
65
|
+
|
66
|
+
protected ### inspect
|
67
|
+
|
68
|
+
def args
|
69
|
+
[ on ]
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def tuple_project(tuple, on)
|
75
|
+
TupleAlgebra.project(tuple, on)
|
76
|
+
end
|
77
|
+
|
78
|
+
end # class Project
|
79
|
+
end # module Operator
|
80
|
+
end # module Bmg
|
data/lib/bmg/sequel/relation.rb
CHANGED
@@ -24,7 +24,16 @@ module Bmg
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def insert(arg)
|
27
|
-
|
27
|
+
case arg
|
28
|
+
when Hash then
|
29
|
+
dataset.insert(arg.merge(type.predicate.constants))
|
30
|
+
when Enumerable then
|
31
|
+
dataset.multi_insert(arg.map { |x|
|
32
|
+
x.merge(type.predicate.constants)
|
33
|
+
})
|
34
|
+
else
|
35
|
+
dataset.insert(arg.merge(type.predicate.constants))
|
36
|
+
end
|
28
37
|
end
|
29
38
|
|
30
39
|
def update(arg)
|
data/lib/bmg/type.rb
CHANGED
data/lib/bmg/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bmg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernard Lambeau
|
@@ -66,20 +66,6 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '1.3'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: roo
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '2.7'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '2.7'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: sequel
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -129,6 +115,7 @@ files:
|
|
129
115
|
- lib/bmg/operator/constants.rb
|
130
116
|
- lib/bmg/operator/extend.rb
|
131
117
|
- lib/bmg/operator/image.rb
|
118
|
+
- lib/bmg/operator/matching.rb
|
132
119
|
- lib/bmg/operator/project.rb
|
133
120
|
- lib/bmg/operator/rename.rb
|
134
121
|
- lib/bmg/operator/restrict.rb
|