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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2b2153bc229ff1517982db773316de847812ac3
4
- data.tar.gz: 9f9b558de99c868d0b8dd5d8e11eb649fca7e1bd
3
+ metadata.gz: cd47ac94bb3775d03bddef092ad532dc4c3463c5
4
+ data.tar.gz: 1a8fd964c8e074f1632cf1067050f1581efad8ef
5
5
  SHA512:
6
- metadata.gz: b46d9fe457281dcee1cc202b341fc98a8dbb55a4b5a1c1fc8cf7163bc4c5694149d2697b55736c112d4583596cc8d1b353f8c4f1144475ef2fe7d7d79deb3047
7
- data.tar.gz: 4ed985da29e10309920a3a8866aff6f2d21014e23ee023a695cc4105f6d740ab62c4b87cc72f9157aa98bfc06b0c5e2c1f8dd98f8554e1e605fe27e8b1f1ba43
6
+ metadata.gz: 95c27ba47fe64d1624b9dc8129f9b8071c8e313919e594dd7fa8e82958187d45dc4bebb8b6406029d70b728c29ca79d43add0bc323642270e279e2638d272ff7
7
+ data.tar.gz: 0eb469720408c4c38b0680c67504c9f1853387f7d09c5cd4d4d980af303ea482e9decdffee16c19247885e0ad9df8513b7bfbff9a2ce2cf84e9f9cdc8e737705
@@ -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
@@ -75,3 +75,4 @@ require_relative 'operator/project'
75
75
  require_relative 'operator/rename'
76
76
  require_relative 'operator/restrict'
77
77
  require_relative 'operator/union'
78
+ require_relative 'operator/matching'
@@ -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
@@ -24,7 +24,16 @@ module Bmg
24
24
  end
25
25
 
26
26
  def insert(arg)
27
- dataset.insert(arg.merge(type.predicate.constants))
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)
@@ -37,6 +37,10 @@ module Bmg
37
37
  ANY
38
38
  end
39
39
 
40
+ def matching(right, on)
41
+ ANY
42
+ end
43
+
40
44
  def project(attrlist)
41
45
  ANY
42
46
  end
@@ -1,8 +1,8 @@
1
1
  module Bmg
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 6
5
- TINY = 1
4
+ MINOR = 7
5
+ TINY = 0
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
8
8
  end
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.6.1
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