bmg 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5cdd3816b79a6f29c387456d9ffdc12d9ae7872e
4
- data.tar.gz: 4c30157082a6474c76a156efc7fcdb510f2f2d44
3
+ metadata.gz: 7b43a1cda1c1650f7678db8e4a9213e7065d26a5
4
+ data.tar.gz: 6f130fa599d6d24b4eaa0450883cfef539b95e6f
5
5
  SHA512:
6
- metadata.gz: 95290af1dba5768f4a4bfee0357d53ddd70063a6fb6a34ee8c6b329805f44ec1ac49ba0fd5baea0b6946d4e81bf3250b30a954f2b1288c53e0eaa4019687e6d8
7
- data.tar.gz: 95fb7f28fbaf62b2f12286857bd04ccc0849d397f085bd366f303572e21a01d6baeb023d4226f56b8223182f075f0c455a3ef06aa7433c677fa5390404c4b9d9
6
+ metadata.gz: 0ac9c79f0c348dbd7685a5c922a28a315192a72ce6b42da708b3233f1fb53da1b64da97659ddb3935aad39a4bdf3141d06be24ff102d202be0e7d8677fbb9f8a
7
+ data.tar.gz: 40aea311e6e4d372ca07ffd91fd5c6ad102f3dd67da5443287121233848e3470ccded49eea97ef4e1f9d4a01afebeb4b43425e7426081ee2472cb0b8a95833ed
@@ -74,7 +74,17 @@ module Bmg
74
74
  protected :_rename
75
75
 
76
76
  def restrict(predicate)
77
- _restrict self.type.restrict(predicate), Predicate.coerce(predicate)
77
+ predicate = Predicate.coerce(predicate)
78
+ if predicate.tautology?
79
+ self
80
+ else
81
+ type = self.type.restrict(predicate)
82
+ if predicate.contradiction?
83
+ Relation.empty(type)
84
+ else
85
+ _restrict type, predicate
86
+ end
87
+ end
78
88
  end
79
89
 
80
90
  def _restrict(type, predicate)
@@ -36,18 +36,20 @@ module Bmg
36
36
  protected ### optimization
37
37
 
38
38
  def _restrict(type, predicate)
39
+ # bottom_p makes no reference to constants, top_p possibly
40
+ # does...
39
41
  top_p, bottom_p = predicate.and_split(constants.keys)
40
42
  if top_p.tautology?
41
- # push all situation
43
+ # push all situation: predicate made no reference to constants
42
44
  result = operand
43
- result = result.restrict(bottom_p) unless bottom_p.tautology?
45
+ result = result.restrict(bottom_p)
44
46
  result = result.constants(constants)
45
47
  result
46
48
  elsif (top_p.free_variables - constants.keys).empty?
47
49
  # top_p applies to constants only
48
50
  if eval = top_p.evaluate(constants)
49
51
  result = operand
50
- result = result.restrict(bottom_p) unless bottom_p.tautology?
52
+ result = result.restrict(bottom_p)
51
53
  result = result.constants(constants)
52
54
  result
53
55
  else
@@ -58,14 +58,35 @@ module Bmg
58
58
 
59
59
  def _restrict(type, predicate)
60
60
  on_as, rest = predicate.and_split([as])
61
- if on_as == predicate
61
+ if rest.tautology?
62
+ # push none situation: on_as is still the full predicate
62
63
  super
63
64
  else
64
- shared, left_only = rest.and_split(on)
65
- new_left = left.restrict(rest)
66
- new_right = shared.tautology? ? right : right.restrict(shared)
65
+ # rest makes no reference to `as` and can be pushed
66
+ # down...
67
+ new_left = left.restrict(rest)
68
+
69
+ # regarding right... rest possibly makes references to the
70
+ # join key, but also to left attributes... let split again
71
+ # on the join key attributes, to try to remove spurious
72
+ # attributes for right...
73
+ on_on_and_more, left_only = rest.and_split(on)
74
+
75
+ # it's not guaranteed! let now check whether the split led
76
+ # to a situation where the predicate on `on` attributes
77
+ # actually refers to no other ones...
78
+ if !on_on_and_more.tautology? and (on_on_and_more.free_variables - on).empty?
79
+ new_right = right.restrict(on_on_and_more)
80
+ else
81
+ new_right = right
82
+ end
83
+
84
+ # This is the image itself
67
85
  opt = new_left.image(new_right, as, on, options)
68
- opt = opt.restrict(on_as) unless on_as.tautology?
86
+
87
+ # finaly, it still needs to be kept on the final node
88
+ opt = opt.restrict(on_as)
89
+
69
90
  opt
70
91
  end
71
92
  rescue Predicate::NotSupportedError
@@ -2,7 +2,7 @@ module Bmg
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 4
5
- TINY = 0
5
+ TINY = 1
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.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Lambeau
@@ -16,20 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.1'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 1.1.1
19
+ version: '1.2'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '1.1'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 1.1.1
26
+ version: '1.2'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: rake
35
29
  requirement: !ruby/object:Gem::Requirement