veritas-optimizer 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,17 @@
1
+ language: ruby
1
2
  bundler_args: --without guard metrics
2
3
  script: "bundle exec rake spec"
3
4
  rvm:
4
5
  - 1.8.7
5
6
  - 1.9.2
6
7
  - 1.9.3
7
- - ruby-head
8
+ - jruby-18mode
9
+ - jruby-19mode
10
+ - rbx-18mode
11
+ - rbx-19mode
8
12
  - ree
9
- - jruby
10
- - rbx
11
- - rbx-2.0
13
+ - ruby-head
14
+ - jruby-head
15
+ notifications:
16
+ email:
17
+ - dan.kubb@gmail.com
data/Gemfile CHANGED
@@ -1,8 +1,8 @@
1
1
  # encoding: utf-8
2
2
 
3
- source :rubygems
3
+ source 'https://rubygems.org'
4
4
 
5
- gem 'veritas', '~> 0.0.6', :git => 'git://github.com/dkubb/veritas.git'
5
+ gem 'veritas', '~> 0.0.7', :git => 'git://github.com/dkubb/veritas.git'
6
6
 
7
7
  group :development do
8
8
  gem 'backports', '~> 2.3.0'
data/TODO CHANGED
@@ -82,6 +82,10 @@
82
82
  * Offset with an offset > 0 can be transformed into an empty
83
83
  relation, since at most there can be only one match.
84
84
 
85
+ * When wrapping a Product and the predicate only contains
86
+ equality/conjunction between attributes from the left and right
87
+ operands, then transform into a Join.
88
+
85
89
  * Connective
86
90
  * "attr > ? OR attr > ?" -> "attr > ?", with the least restrictive value
87
91
  * Do the same for >=, <, <=
@@ -1,3 +1,3 @@
1
1
  ---
2
2
  threshold: 113
3
- total_score: 845
3
+ total_score: 862
@@ -34,7 +34,7 @@ module Veritas
34
34
  # Optimize when operands' headers are equal
35
35
  class EqualHeaders < self
36
36
 
37
- # Test if the operands' headers are equal to the join's headers
37
+ # Test if the operands' headers are equal
38
38
  #
39
39
  # @return [Boolean]
40
40
  #
@@ -43,7 +43,7 @@ module Veritas
43
43
  left.header.eql?(right.header)
44
44
  end
45
45
 
46
- # A Join with an equal header is an Intersection
46
+ # A Join with equal headers is an Intersection
47
47
  #
48
48
  # @return [Algebra::Intersection]
49
49
  #
@@ -54,6 +54,29 @@ module Veritas
54
54
 
55
55
  end # class EqualHeaders
56
56
 
57
+ # Optimize when operands' headers are disjoint
58
+ class DisjointHeaders < self
59
+
60
+ # Test if the operands' headers are disjoint
61
+ #
62
+ # @return [Boolean]
63
+ #
64
+ # @api private
65
+ def optimizable?
66
+ (left.header & right.header).none?
67
+ end
68
+
69
+ # A Join with disjoint headers is a Product
70
+ #
71
+ # @return [Algebra::Product]
72
+ #
73
+ # @api private
74
+ def optimize
75
+ left.product(right)
76
+ end
77
+
78
+ end # class EqualHeaders
79
+
57
80
  # Optimize when the left operand is materialized
58
81
  class LeftMaterializedOperand < self
59
82
 
@@ -146,6 +169,7 @@ module Veritas
146
169
  EmptyLeft,
147
170
  EmptyRight,
148
171
  EqualHeaders,
172
+ DisjointHeaders,
149
173
  LeftOrderOperand,
150
174
  RightOrderOperand,
151
175
  MaterializedOperands,
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Veritas
4
4
  class Optimizer
5
- VERSION = '0.0.6'
5
+ VERSION = '0.0.7'
6
6
  end # class Optimizer
7
7
  end # module Veritas
@@ -4,3 +4,4 @@
4
4
  --xrefs
5
5
  --profile
6
6
  --text-summary
7
+ --failure-threshold 100
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'rubygems'
4
4
  require 'backports'
5
- require 'backports/basic_object'
5
+ require 'backports/basic_object' unless RUBY_VERSION >= '1.9.2' && (RUBY_PLATFORM.include?('java') || RUBY_ENGINE == 'rbx')
6
6
  require 'veritas-optimizer'
7
7
  require 'spec'
8
8
  require 'spec/autorun'
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Optimizer::Algebra::Join::DisjointHeaders, '#optimizable?' do
6
+ subject { object.optimizable? }
7
+
8
+ let(:relation) { left.join(right) }
9
+ let(:object) { described_class.new(relation) }
10
+
11
+ before do
12
+ object.operation.should be_kind_of(Algebra::Join)
13
+ end
14
+
15
+ context 'when left and right headers are disjoint' do
16
+ let(:left) { Relation.new([ [ :id, Integer ] ], [ [ 1 ] ].each) }
17
+ let(:right) { Relation.new([ [ :other_id, Integer ] ], [ [ 1 ] ].each) }
18
+
19
+ it { should be(true) }
20
+ end
21
+
22
+ context 'when left and right headers are not disjoint' do
23
+ let(:header) { [ [ :id, Integer ] ] }
24
+ let(:left) { Relation.new(header, [ [ 1 ] ].each) }
25
+ let(:right) { Relation.new(header, [ [ 1 ] ].each) }
26
+
27
+ it { should be(false) }
28
+ end
29
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Optimizer::Algebra::Join::DisjointHeaders, '#optimize' do
6
+ subject { object.optimize }
7
+
8
+ let(:left) { Relation.new([ [ :id, Integer ] ], [ [ 1 ] ].each) }
9
+ let(:right) { Relation.new([ [ :other_id, Integer ] ], [ [ 2 ] ].each) }
10
+ let(:relation) { left.join(right) }
11
+ let(:object) { described_class.new(relation) }
12
+
13
+ before do
14
+ object.should be_optimizable
15
+ end
16
+
17
+ it { should be_kind_of(Algebra::Product) }
18
+
19
+ its(:left) { should equal(left) }
20
+
21
+ its(:right) { should equal(right) }
22
+ end
@@ -1,7 +1,7 @@
1
1
  desc 'Run metrics with Heckle'
2
- task :ci => [ 'ci:metrics', :heckle ]
2
+ task :ci => %w[ ci:metrics heckle ]
3
3
 
4
4
  namespace :ci do
5
5
  desc 'Run metrics'
6
- task :metrics => [ :verify_measurements, :flog, :flay, :reek, :roodi, 'metrics:all' ]
6
+ task :metrics => %w[ verify_measurements flog flay reek roodi metrics:all ]
7
7
  end
@@ -6,7 +6,7 @@ $LOAD_PATH.unshift(File.expand_path('../../../lib', __FILE__))
6
6
  begin
7
7
  require 'pathname'
8
8
  require 'backports'
9
- require 'backports/basic_object'
9
+ require 'backports/basic_object' unless RUBY_VERSION >= '1.9.2' && (RUBY_PLATFORM.include?('java') || RUBY_ENGINE == 'rbx')
10
10
  require 'active_support/inflector'
11
11
  require 'heckle'
12
12
  require 'mspec'
@@ -27,13 +27,16 @@ begin
27
27
  end
28
28
 
29
29
  desc 'Heckle each module and class'
30
- task :heckle => :verify_rcov do
30
+ task :heckle => :rcov do
31
31
  unless Ruby2Ruby::VERSION == '1.2.2'
32
32
  raise "ruby2ruby version #{Ruby2Ruby::VERSION} may not work properly, 1.2.2 *only* is recommended for use with heckle"
33
33
  end
34
34
 
35
35
  require 'veritas/optimizer'
36
- root_module = 'Veritas::Optimizer'
36
+
37
+ root_module_regexp = Regexp.union(
38
+ 'Veritas::Optimizer'
39
+ )
37
40
 
38
41
  spec_dir = Pathname('spec/unit')
39
42
 
@@ -50,7 +53,7 @@ begin
50
53
  unhandled_mutations = 0
51
54
 
52
55
  ObjectSpace.each_object(Module) do |mod|
53
- next unless mod.name =~ /\A#{root_module}(?::|\z)/
56
+ next unless mod.name =~ /\A#{root_module_regexp}(?::|\z)/
54
57
 
55
58
  spec_prefix = spec_dir.join(mod.name.underscore)
56
59
 
@@ -135,9 +138,9 @@ begin
135
138
  descedant_specs = []
136
139
 
137
140
  ObjectSpace.each_object(Module) do |descedant|
138
- next unless descedant.name =~ /\A#{root_module}(?::|\z)/ && mod >= descedant
141
+ next unless descedant.name =~ /\A#{root_module_regexp}(?::|\z)/ && mod >= descedant
139
142
  descedant_spec_prefix = spec_dir.join(descedant.name.underscore)
140
- descedant_specs.concat(Pathname.glob(descedant_spec_prefix.join('*_spec.rb')))
143
+ descedant_specs << descedant_spec_prefix
141
144
 
142
145
  if method.to_s == 'initialize'
143
146
  descedant_specs.concat(Pathname.glob(descedant_spec_prefix.join('class_methods/new_spec.rb')))
@@ -151,9 +154,8 @@ begin
151
154
  descedant_specs = []
152
155
 
153
156
  ObjectSpace.each_object(Module) do |descedant|
154
- next unless descedant.name =~ /\A#{root_module}(?::|\z)/ && mod >= descedant
155
- descedant_spec_prefix = spec_dir.join(descedant.name.underscore)
156
- descedant_specs.concat(Pathname.glob(descedant_spec_prefix.join('class_methods/*_spec.rb')))
157
+ next unless descedant.name =~ /\A#{root_module_regexp}(?::|\z)/ && mod >= descedant
158
+ descedant_specs << spec_dir.join(descedant.name.underscore).join('class_methods')
157
159
  end
158
160
 
159
161
  specs << [ ".#{method}", descedant_specs ]
@@ -1,37 +1,46 @@
1
1
  spec_defaults = lambda do |spec|
2
- spec.pattern = 'spec/**/*_spec.rb'
3
- spec.libs << 'lib' << 'spec'
4
2
  spec.spec_opts << '--options' << 'spec/spec.opts'
5
3
  end
6
4
 
7
5
  begin
8
6
  require 'spec/rake/spectask'
9
7
 
10
- Spec::Rake::SpecTask.new(:spec, &spec_defaults)
8
+ desc 'Run all specs'
9
+ task :spec => %w[ spec:unit spec:integration ]
10
+
11
+ namespace :spec do
12
+ desc 'Run unit specs'
13
+ Spec::Rake::SpecTask.new(:unit) do |unit|
14
+ spec_defaults.call(unit)
15
+ unit.pattern = 'spec/unit/**/*_spec.rb'
16
+ end
17
+
18
+ desc 'Run integration specs'
19
+ Spec::Rake::SpecTask.new(:integration) do |integration|
20
+ spec_defaults.call(integration)
21
+ integration.pattern = 'spec/integration/**/*_spec.rb'
22
+ end
23
+ end
11
24
  rescue LoadError
12
- task :spec do
13
- abort 'rspec is not available. In order to run spec, you must: gem install rspec'
25
+ %w[ spec spec:unit spec:integration ].each do |name|
26
+ task name do
27
+ abort "rspec is not available. In order to run #{name}, you must: gem install rspec"
28
+ end
14
29
  end
15
30
  end
16
31
 
17
32
  begin
18
33
  require 'rcov'
19
- require 'spec/rake/verify_rcov'
20
34
 
21
35
  Spec::Rake::SpecTask.new(:rcov) do |rcov|
22
36
  spec_defaults.call(rcov)
23
37
  rcov.rcov = true
38
+ rcov.pattern = 'spec/unit/**/*_spec.rb'
24
39
  rcov.rcov_opts = File.read('spec/rcov.opts').split(/\s+/)
25
40
  end
26
-
27
- RCov::VerifyTask.new(:verify_rcov => :rcov) do |rcov|
28
- rcov.threshold = 100
29
- end
30
41
  rescue LoadError
31
- %w[ rcov verify_rcov ].each do |name|
32
- task name do
33
- abort "rcov is not available. In order to run #{name}, you must: gem install rcov"
34
- end
42
+ task :rcov do
43
+ abort 'rcov is not available. In order to run rcov, you must: gem install rcov'
35
44
  end
36
45
  end
37
46
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "veritas-optimizer"
8
- s.version = "0.0.6"
8
+ s.version = "0.0.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dan Kubb"]
12
- s.date = "2011-10-04"
12
+ s.date = "2012-03-08"
13
13
  s.description = "Optimizes veritas relations"
14
14
  s.email = "dan.kubb@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -141,6 +141,8 @@ Gem::Specification.new do |s|
141
141
  "spec/unit/veritas/optimizer/algebra/intersection/empty_left/optimize_spec.rb",
142
142
  "spec/unit/veritas/optimizer/algebra/intersection/empty_right/optimize_spec.rb",
143
143
  "spec/unit/veritas/optimizer/algebra/intersection/equal_operands/optimize_spec.rb",
144
+ "spec/unit/veritas/optimizer/algebra/join/disjoint_headers/optimizable_spec.rb",
145
+ "spec/unit/veritas/optimizer/algebra/join/disjoint_headers/optimize_spec.rb",
144
146
  "spec/unit/veritas/optimizer/algebra/join/equal_headers/optimizable_spec.rb",
145
147
  "spec/unit/veritas/optimizer/algebra/join/equal_headers/optimize_spec.rb",
146
148
  "spec/unit/veritas/optimizer/algebra/join/left_materialized_operand/optimizable_spec.rb",
@@ -362,21 +364,21 @@ Gem::Specification.new do |s|
362
364
  ]
363
365
  s.homepage = "https://github.com/dkubb/veritas-optimizer"
364
366
  s.require_paths = ["lib"]
365
- s.rubygems_version = "1.8.10"
367
+ s.rubygems_version = "1.8.16"
366
368
  s.summary = "Relational algebra optimizer"
367
369
 
368
370
  if s.respond_to? :specification_version then
369
371
  s.specification_version = 3
370
372
 
371
373
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
372
- s.add_runtime_dependency(%q<veritas>, ["~> 0.0.6"])
374
+ s.add_runtime_dependency(%q<veritas>, ["~> 0.0.7"])
373
375
  s.add_development_dependency(%q<backports>, ["~> 2.3.0"])
374
376
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
375
377
  s.add_development_dependency(%q<rake>, ["~> 0.9.2"])
376
378
  s.add_development_dependency(%q<rspec>, ["~> 1.3.2"])
377
379
  s.add_development_dependency(%q<yard>, ["~> 0.7.2"])
378
380
  else
379
- s.add_dependency(%q<veritas>, ["~> 0.0.6"])
381
+ s.add_dependency(%q<veritas>, ["~> 0.0.7"])
380
382
  s.add_dependency(%q<backports>, ["~> 2.3.0"])
381
383
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
382
384
  s.add_dependency(%q<rake>, ["~> 0.9.2"])
@@ -384,7 +386,7 @@ Gem::Specification.new do |s|
384
386
  s.add_dependency(%q<yard>, ["~> 0.7.2"])
385
387
  end
386
388
  else
387
- s.add_dependency(%q<veritas>, ["~> 0.0.6"])
389
+ s.add_dependency(%q<veritas>, ["~> 0.0.7"])
388
390
  s.add_dependency(%q<backports>, ["~> 2.3.0"])
389
391
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
390
392
  s.add_dependency(%q<rake>, ["~> 0.9.2"])
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: veritas-optimizer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dan Kubb
@@ -15,28 +15,27 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-04 00:00:00 Z
18
+ date: 2012-03-08 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  type: :runtime
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
23
  none: false
25
24
  requirements:
26
25
  - - ~>
27
26
  - !ruby/object:Gem::Version
28
- hash: 19
27
+ hash: 17
29
28
  segments:
30
29
  - 0
31
30
  - 0
32
- - 6
33
- version: 0.0.6
34
- version_requirements: *id001
31
+ - 7
32
+ version: 0.0.7
33
+ prerelease: false
34
+ requirement: *id001
35
35
  name: veritas
36
36
  - !ruby/object:Gem::Dependency
37
37
  type: :development
38
- prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
42
41
  - - ~>
@@ -47,12 +46,12 @@ dependencies:
47
46
  - 3
48
47
  - 0
49
48
  version: 2.3.0
50
- version_requirements: *id002
49
+ prerelease: false
50
+ requirement: *id002
51
51
  name: backports
52
52
  - !ruby/object:Gem::Dependency
53
53
  type: :development
54
- prerelease: false
55
- requirement: &id003 !ruby/object:Gem::Requirement
54
+ version_requirements: &id003 !ruby/object:Gem::Requirement
56
55
  none: false
57
56
  requirements:
58
57
  - - ~>
@@ -63,12 +62,12 @@ dependencies:
63
62
  - 6
64
63
  - 4
65
64
  version: 1.6.4
66
- version_requirements: *id003
65
+ prerelease: false
66
+ requirement: *id003
67
67
  name: jeweler
68
68
  - !ruby/object:Gem::Dependency
69
69
  type: :development
70
- prerelease: false
71
- requirement: &id004 !ruby/object:Gem::Requirement
70
+ version_requirements: &id004 !ruby/object:Gem::Requirement
72
71
  none: false
73
72
  requirements:
74
73
  - - ~>
@@ -79,12 +78,12 @@ dependencies:
79
78
  - 9
80
79
  - 2
81
80
  version: 0.9.2
82
- version_requirements: *id004
81
+ prerelease: false
82
+ requirement: *id004
83
83
  name: rake
84
84
  - !ruby/object:Gem::Dependency
85
85
  type: :development
86
- prerelease: false
87
- requirement: &id005 !ruby/object:Gem::Requirement
86
+ version_requirements: &id005 !ruby/object:Gem::Requirement
88
87
  none: false
89
88
  requirements:
90
89
  - - ~>
@@ -95,12 +94,12 @@ dependencies:
95
94
  - 3
96
95
  - 2
97
96
  version: 1.3.2
98
- version_requirements: *id005
97
+ prerelease: false
98
+ requirement: *id005
99
99
  name: rspec
100
100
  - !ruby/object:Gem::Dependency
101
101
  type: :development
102
- prerelease: false
103
- requirement: &id006 !ruby/object:Gem::Requirement
102
+ version_requirements: &id006 !ruby/object:Gem::Requirement
104
103
  none: false
105
104
  requirements:
106
105
  - - ~>
@@ -111,7 +110,8 @@ dependencies:
111
110
  - 7
112
111
  - 2
113
112
  version: 0.7.2
114
- version_requirements: *id006
113
+ prerelease: false
114
+ requirement: *id006
115
115
  name: yard
116
116
  description: Optimizes veritas relations
117
117
  email: dan.kubb@gmail.com
@@ -247,6 +247,8 @@ files:
247
247
  - spec/unit/veritas/optimizer/algebra/intersection/empty_left/optimize_spec.rb
248
248
  - spec/unit/veritas/optimizer/algebra/intersection/empty_right/optimize_spec.rb
249
249
  - spec/unit/veritas/optimizer/algebra/intersection/equal_operands/optimize_spec.rb
250
+ - spec/unit/veritas/optimizer/algebra/join/disjoint_headers/optimizable_spec.rb
251
+ - spec/unit/veritas/optimizer/algebra/join/disjoint_headers/optimize_spec.rb
250
252
  - spec/unit/veritas/optimizer/algebra/join/equal_headers/optimizable_spec.rb
251
253
  - spec/unit/veritas/optimizer/algebra/join/equal_headers/optimize_spec.rb
252
254
  - spec/unit/veritas/optimizer/algebra/join/left_materialized_operand/optimizable_spec.rb
@@ -494,7 +496,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
494
496
  requirements: []
495
497
 
496
498
  rubyforge_project:
497
- rubygems_version: 1.8.10
499
+ rubygems_version: 1.8.16
498
500
  signing_key:
499
501
  specification_version: 3
500
502
  summary: Relational algebra optimizer