axiom-optimizer 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +2 -1
- data/.rubocop.yml +6 -0
- data/.travis.yml +16 -20
- data/CONTRIBUTING.md +1 -2
- data/Gemfile +3 -1
- data/Gemfile.devtools +28 -18
- data/README.md +7 -13
- data/TODO +6 -5
- data/axiom-optimizer.gemspec +3 -3
- data/config/flay.yml +1 -1
- data/config/reek.yml +5 -29
- data/config/rubocop.yml +16 -10
- data/lib/axiom/optimizer.rb +3 -7
- data/lib/axiom/optimizer/algebra/difference.rb +2 -2
- data/lib/axiom/optimizer/algebra/extension.rb +6 -6
- data/lib/axiom/optimizer/algebra/intersection.rb +2 -2
- data/lib/axiom/optimizer/algebra/join.rb +4 -4
- data/lib/axiom/optimizer/algebra/product.rb +4 -4
- data/lib/axiom/optimizer/algebra/projection.rb +5 -5
- data/lib/axiom/optimizer/algebra/rename.rb +10 -10
- data/lib/axiom/optimizer/algebra/restriction.rb +8 -9
- data/lib/axiom/optimizer/algebra/summarization.rb +7 -7
- data/lib/axiom/optimizer/algebra/union.rb +2 -2
- data/lib/axiom/optimizer/function.rb +4 -6
- data/lib/axiom/optimizer/function/binary.rb +2 -2
- data/lib/axiom/optimizer/function/connective/binary.rb +1 -1
- data/lib/axiom/optimizer/function/connective/negation.rb +1 -1
- data/lib/axiom/optimizer/function/predicate.rb +1 -1
- data/lib/axiom/optimizer/function/predicate/comparable.rb +8 -6
- data/lib/axiom/optimizer/function/predicate/enumerable.rb +2 -2
- data/lib/axiom/optimizer/function/unary.rb +1 -1
- data/lib/axiom/optimizer/relation/operation/binary.rb +12 -12
- data/lib/axiom/optimizer/relation/operation/reverse.rb +9 -9
- data/lib/axiom/optimizer/relation/operation/{order.rb → sorted.rb} +15 -15
- data/lib/axiom/optimizer/relation/operation/unary.rb +7 -7
- data/lib/axiom/optimizer/support/predicate_partition.rb +11 -13
- data/lib/axiom/optimizer/version.rb +1 -1
- data/spec/integration/axiom/algebra/difference/optimize_spec.rb +12 -12
- data/spec/integration/axiom/algebra/intersection/optimize_spec.rb +12 -12
- data/spec/integration/axiom/algebra/join/optimize_spec.rb +6 -6
- data/spec/integration/axiom/algebra/product/optimize_spec.rb +10 -10
- data/spec/integration/axiom/algebra/projection/optimize_spec.rb +14 -14
- data/spec/integration/axiom/algebra/rename/optimize_spec.rb +38 -38
- data/spec/integration/axiom/algebra/restriction/optimize_spec.rb +12 -12
- data/spec/integration/axiom/algebra/summarization/optimize_spec.rb +2 -2
- data/spec/integration/axiom/algebra/union/optimize_spec.rb +16 -16
- data/spec/integration/axiom/function/optimize_spec.rb +1 -1
- data/spec/integration/axiom/relation/operation/limit/optimize_spec.rb +20 -20
- data/spec/integration/axiom/relation/operation/offset/optimize_spec.rb +14 -14
- data/spec/integration/axiom/relation/operation/reverse/optimize_spec.rb +15 -15
- data/spec/integration/axiom/relation/operation/{order → sorted}/optimize_spec.rb +6 -6
- data/spec/integration/axiom/relation/optimize_spec.rb +1 -1
- data/spec/shared/function_connective_binary_optimize_behavior.rb +8 -2
- data/spec/shared/optimize_method_behavior.rb +0 -11
- data/spec/spec_helper.rb +9 -9
- data/spec/support/config_alias.rb +2 -0
- data/spec/unit/axiom/optimizer/algebra/extension/{order_operand → sorted_operand}/optimizable_predicate_spec.rb +3 -3
- data/spec/unit/axiom/optimizer/algebra/extension/{order_operand → sorted_operand}/optimize_spec.rb +1 -1
- data/spec/unit/axiom/optimizer/algebra/rename/limit_operand/optimize_spec.rb +3 -3
- data/spec/unit/axiom/optimizer/algebra/rename/offset_operand/optimize_spec.rb +3 -3
- data/spec/unit/axiom/optimizer/algebra/rename/{order_operand → sorted_operand}/optimizable_predicate_spec.rb +3 -3
- data/spec/unit/axiom/optimizer/algebra/rename/{order_operand → sorted_operand}/optimize_spec.rb +2 -2
- data/spec/unit/axiom/optimizer/algebra/restriction/combination_operand/optimize_spec.rb +1 -1
- data/spec/unit/axiom/optimizer/algebra/restriction/predicate_spec.rb +5 -4
- data/spec/unit/axiom/optimizer/algebra/restriction/{order_operand → sorted_operand}/optimizable_predicate_spec.rb +3 -3
- data/spec/unit/axiom/optimizer/algebra/restriction/{order_operand → sorted_operand}/optimize_spec.rb +1 -1
- data/spec/unit/axiom/optimizer/algebra/summarization/empty_operand/class_methods/extension_default_spec.rb +1 -1
- data/spec/unit/axiom/optimizer/algebra/summarization/{order_operand → sorted_operand}/optimizable_predicate_spec.rb +3 -3
- data/spec/unit/axiom/optimizer/algebra/summarization/{order_operand → sorted_operand}/optimize_spec.rb +1 -1
- data/spec/unit/axiom/optimizer/algebra/summarization/summarize_per_spec.rb +1 -1
- data/spec/unit/axiom/optimizer/function/binary/constant_operands/optimizable_predicate_spec.rb +4 -4
- data/spec/unit/axiom/optimizer/function/connective/conjunction/contradiction/optimizable_predicate_spec.rb +2 -2
- data/spec/unit/axiom/optimizer/function/connective/disjunction/tautology/optimizable_predicate_spec.rb +2 -2
- data/spec/unit/axiom/optimizer/function/unary/constant_operand/optimizable_predicate_spec.rb +1 -1
- data/spec/unit/axiom/optimizer/function/util/class_methods/max_spec.rb +1 -1
- data/spec/unit/axiom/optimizer/function/util/class_methods/min_spec.rb +1 -1
- data/spec/unit/axiom/optimizer/optimizable/optimize_spec.rb +3 -3
- data/spec/unit/axiom/optimizer/optimizable_predicate_spec.rb +1 -5
- data/spec/unit/axiom/optimizer/optimize_spec.rb +1 -5
- data/spec/unit/axiom/optimizer/relation/operation/binary/{order_left → sorted_left}/optimizable_predicate_spec.rb +3 -3
- data/spec/unit/axiom/optimizer/relation/operation/binary/{order_left → sorted_left}/optimize_spec.rb +1 -1
- data/spec/unit/axiom/optimizer/relation/operation/binary/{order_right → sorted_right}/optimizable_predicate_spec.rb +3 -3
- data/spec/unit/axiom/optimizer/relation/operation/binary/{order_right → sorted_right}/optimize_spec.rb +1 -1
- data/spec/unit/axiom/optimizer/relation/operation/limit/equal_limit_operand/optimize_spec.rb +2 -2
- data/spec/unit/axiom/optimizer/relation/operation/limit/limit_operand/optimize_spec.rb +4 -4
- data/spec/unit/axiom/optimizer/relation/operation/limit/unoptimized_operand/optimize_spec.rb +3 -3
- data/spec/unit/axiom/optimizer/relation/operation/limit/zero_limit/optimize_spec.rb +2 -2
- data/spec/unit/axiom/optimizer/relation/operation/offset/offset_operand/optimize_spec.rb +3 -3
- data/spec/unit/axiom/optimizer/relation/operation/offset/unoptimized_operand/optimize_spec.rb +3 -3
- data/spec/unit/axiom/optimizer/relation/operation/offset/zero_offset/optimize_spec.rb +3 -3
- data/spec/unit/axiom/optimizer/relation/operation/reverse/{order_operand → sorted_operand}/optimizable_predicate_spec.rb +3 -3
- data/spec/unit/axiom/optimizer/relation/operation/reverse/{order_operand → sorted_operand}/optimize_spec.rb +2 -2
- data/spec/unit/axiom/optimizer/relation/operation/reverse/unoptimized_operand/optimize_spec.rb +4 -4
- data/spec/unit/axiom/optimizer/relation/operation/{order → sorted}/one_limit_operand/optimizable_predicate_spec.rb +2 -2
- data/spec/unit/axiom/optimizer/relation/operation/{order → sorted}/one_limit_operand/optimize_spec.rb +1 -1
- data/spec/unit/axiom/optimizer/relation/operation/{order/order_operand → sorted/sorted_operand}/optimizable_predicate_spec.rb +4 -4
- data/spec/unit/axiom/optimizer/relation/operation/{order/order_operand → sorted/sorted_operand}/optimize_spec.rb +5 -5
- data/spec/unit/axiom/optimizer/relation/operation/{order → sorted}/unoptimized_operand/optimizable_predicate_spec.rb +2 -2
- data/spec/unit/axiom/optimizer/relation/operation/{order → sorted}/unoptimized_operand/optimize_spec.rb +2 -2
- data/spec/unit/axiom/optimizer/relation/operation/unary/{order_operand → sorted_operand}/optimizable_predicate_spec.rb +4 -4
- data/spec/unit/axiom/optimizer/relation/operation/unary/{order_operand → sorted_operand}/optimize_spec.rb +2 -2
- metadata +291 -47
- data/spec/support/ice_nine_config.rb +0 -6
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Optimizer::Algebra::Summarization::
|
5
|
+
describe Optimizer::Algebra::Summarization::SortedOperand, '#optimize' do
|
6
6
|
subject { object.optimize }
|
7
7
|
|
8
8
|
let(:base) { Relation.new([[:id, Integer]], LazyEnumerable.new) }
|
@@ -20,7 +20,7 @@ describe Optimizer::Algebra::Summarization, '#summarize_per' do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
context 'when summarize_per is not not optimized' do
|
23
|
-
|
23
|
+
let(:summarize_per) { TABLE_DEE.rename({}) }
|
24
24
|
|
25
25
|
it { should_not be(summarize_per) }
|
26
26
|
|
data/spec/unit/axiom/optimizer/function/binary/constant_operands/optimizable_predicate_spec.rb
CHANGED
@@ -21,15 +21,15 @@ describe Optimizer::Function::Binary::ConstantOperands, '#optimizable?' do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
context 'when left is a constant, and right is not a constant' do
|
24
|
-
let(:left) { 1
|
25
|
-
let(:right) { proc {}
|
24
|
+
let(:left) { 1 }
|
25
|
+
let(:right) { proc {} }
|
26
26
|
|
27
27
|
it { should be(false) }
|
28
28
|
end
|
29
29
|
|
30
30
|
context 'when left is not a constant, and right is a constant' do
|
31
|
-
let(:left) { proc {}
|
32
|
-
let(:right) { 1
|
31
|
+
let(:left) { proc {} }
|
32
|
+
let(:right) { 1 }
|
33
33
|
|
34
34
|
it { should be(false) }
|
35
35
|
end
|
@@ -42,8 +42,8 @@ describe Optimizer::Function::Connective::Conjunction::Contradiction, '#optimiza
|
|
42
42
|
end
|
43
43
|
|
44
44
|
context 'when left and right are procs' do
|
45
|
-
let(:left) { proc {}
|
46
|
-
let(:right) { proc {}
|
45
|
+
let(:left) { proc {} }
|
46
|
+
let(:right) { proc {} }
|
47
47
|
|
48
48
|
it { should be(false) }
|
49
49
|
end
|
@@ -42,8 +42,8 @@ describe Optimizer::Function::Connective::Disjunction::Tautology, '#optimizable?
|
|
42
42
|
end
|
43
43
|
|
44
44
|
context 'when left and right are procs' do
|
45
|
-
let(:left) { proc {}
|
46
|
-
let(:right) { proc {}
|
45
|
+
let(:left) { proc {} }
|
46
|
+
let(:right) { proc {} }
|
47
47
|
|
48
48
|
it { should be(false) }
|
49
49
|
end
|
@@ -14,7 +14,7 @@ describe Optimizer::Function::Util, '.max' do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
context 'with a String attribute' do
|
17
|
-
let(:operand) { Attribute::String.new(:id,
|
17
|
+
let(:operand) { Attribute::String.new(:id, minimum_length: 1, maximum_length: 10) }
|
18
18
|
|
19
19
|
it { should == 10 }
|
20
20
|
end
|
@@ -14,7 +14,7 @@ describe Optimizer::Function::Util, '.min' do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
context 'with a String attribute' do
|
17
|
-
let(:operand) { Attribute::String.new(:id,
|
17
|
+
let(:operand) { Attribute::String.new(:id, minimum_length: 1, maximum_length: 10) }
|
18
18
|
|
19
19
|
it { should == 1 }
|
20
20
|
end
|
@@ -20,18 +20,18 @@ describe Optimizer::Optimizable, '#optimize' do
|
|
20
20
|
|
21
21
|
before do
|
22
22
|
described_class.optimizer = optimizer
|
23
|
-
optimized.
|
23
|
+
allow(optimized).to receive(:optimize).and_return(optimized)
|
24
24
|
end
|
25
25
|
|
26
26
|
it { should be(optimized) }
|
27
27
|
|
28
28
|
it 'calls the optimizer with the object' do
|
29
|
-
optimizer.
|
29
|
+
expect(optimizer).to receive(:call).with(object).and_return(optimized)
|
30
30
|
should be(optimized)
|
31
31
|
end
|
32
32
|
|
33
33
|
it '#optimize the optimized object' do
|
34
|
-
optimized.
|
34
|
+
expect(optimized).to receive(:optimize).with(no_args).and_return(optimized)
|
35
35
|
should be(optimized)
|
36
36
|
end
|
37
37
|
end
|
@@ -9,9 +9,5 @@ describe Optimizer, '#optimizable?' do
|
|
9
9
|
let(:operation) { double('Operation') }
|
10
10
|
let(:object) { described_class.new(operation) }
|
11
11
|
|
12
|
-
|
13
|
-
described_class.stub(:to_s).and_return('Optimizer')
|
14
|
-
end
|
15
|
-
|
16
|
-
specify { expect { subject }.to raise_error(NotImplementedError, 'Optimizer#optimizable? must be implemented') }
|
12
|
+
specify { expect { subject }.to raise_error(NotImplementedError, "#{described_class}#optimizable? is not implemented") }
|
17
13
|
end
|
@@ -9,9 +9,5 @@ describe Optimizer, '#optimize' do
|
|
9
9
|
let(:operation) { double('Operation') }
|
10
10
|
let(:object) { described_class.new(operation) }
|
11
11
|
|
12
|
-
|
13
|
-
described_class.stub(:to_s).and_return('Optimizer')
|
14
|
-
end
|
15
|
-
|
16
|
-
specify { expect { subject }.to raise_error(NotImplementedError, 'Optimizer#optimize must be implemented') }
|
12
|
+
specify { expect { subject }.to raise_error(NotImplementedError, "#{described_class}#optimize is not implemented") }
|
17
13
|
end
|
@@ -2,20 +2,20 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Optimizer::Relation::Operation::Binary::
|
5
|
+
describe Optimizer::Relation::Operation::Binary::SortedLeft, '#optimizable?' do
|
6
6
|
subject { object.optimizable? }
|
7
7
|
|
8
8
|
let(:relation) { double('Relation', left: left, right: right) }
|
9
9
|
let(:right) { double('Right') }
|
10
10
|
let(:object) { described_class.new(relation) }
|
11
11
|
|
12
|
-
context 'when left is
|
12
|
+
context 'when left is sorted' do
|
13
13
|
let(:left) { Relation.new([[:id, Integer]], LazyEnumerable.new).sort_by { |r| r.id } }
|
14
14
|
|
15
15
|
it { should be(true) }
|
16
16
|
end
|
17
17
|
|
18
|
-
context 'when left is not
|
18
|
+
context 'when left is not sorted' do
|
19
19
|
let(:left) { Relation.new([[:id, Integer]], LazyEnumerable.new) }
|
20
20
|
|
21
21
|
it { should be(false) }
|
data/spec/unit/axiom/optimizer/relation/operation/binary/{order_left → sorted_left}/optimize_spec.rb
RENAMED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Optimizer::Relation::Operation::Binary::
|
5
|
+
describe Optimizer::Relation::Operation::Binary::SortedLeft, '#optimize' do
|
6
6
|
subject { object.optimize }
|
7
7
|
|
8
8
|
let(:base) { Relation.new([[:id, Integer]], LazyEnumerable.new) }
|
@@ -2,20 +2,20 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Optimizer::Relation::Operation::Binary::
|
5
|
+
describe Optimizer::Relation::Operation::Binary::SortedRight, '#optimizable?' do
|
6
6
|
subject { object.optimizable? }
|
7
7
|
|
8
8
|
let(:relation) { double('Relation', left: left, right: right) }
|
9
9
|
let(:left) { double('Left') }
|
10
10
|
let(:object) { described_class.new(relation) }
|
11
11
|
|
12
|
-
context 'when right is
|
12
|
+
context 'when right is sorted' do
|
13
13
|
let(:right) { Relation.new([[:id, Integer]], LazyEnumerable.new).sort_by { |r| r.id } }
|
14
14
|
|
15
15
|
it { should be(true) }
|
16
16
|
end
|
17
17
|
|
18
|
-
context 'when right is not
|
18
|
+
context 'when right is not sorted' do
|
19
19
|
let(:right) { Relation.new([[:id, Integer]], LazyEnumerable.new) }
|
20
20
|
|
21
21
|
it { should be(false) }
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Optimizer::Relation::Operation::Binary::
|
5
|
+
describe Optimizer::Relation::Operation::Binary::SortedRight, '#optimize' do
|
6
6
|
subject { object.optimize }
|
7
7
|
|
8
8
|
let(:base) { Relation.new([[:id, Integer]], LazyEnumerable.new) }
|
data/spec/unit/axiom/optimizer/relation/operation/limit/equal_limit_operand/optimize_spec.rb
CHANGED
@@ -5,8 +5,8 @@ require 'spec_helper'
|
|
5
5
|
describe Optimizer::Relation::Operation::Limit::EqualLimitOperand, '#optimize' do
|
6
6
|
subject { object.optimize }
|
7
7
|
|
8
|
-
let(:
|
9
|
-
let(:limit) {
|
8
|
+
let(:sorted) { Relation.new([[:id, Integer]], LazyEnumerable.new([[1]])).sort_by { |r| r.id } }
|
9
|
+
let(:limit) { sorted.take(1) }
|
10
10
|
let(:relation) { limit.take(1) }
|
11
11
|
let(:object) { described_class.new(relation) }
|
12
12
|
|
@@ -5,8 +5,8 @@ require 'spec_helper'
|
|
5
5
|
describe Optimizer::Relation::Operation::Limit::LimitOperand, '#optimize' do
|
6
6
|
subject { object.optimize }
|
7
7
|
|
8
|
-
let(:
|
9
|
-
let(:limit) {
|
8
|
+
let(:sorted) { Relation.new([[:id, Integer]], LazyEnumerable.new([[1]])).sort_by { |r| r.id } }
|
9
|
+
let(:limit) { sorted.take(2) }
|
10
10
|
let(:object) { described_class.new(relation) }
|
11
11
|
|
12
12
|
before do
|
@@ -18,7 +18,7 @@ describe Optimizer::Relation::Operation::Limit::LimitOperand, '#optimize' do
|
|
18
18
|
|
19
19
|
it { should be_kind_of(Relation::Operation::Limit) }
|
20
20
|
|
21
|
-
its(:operand) { should be(
|
21
|
+
its(:operand) { should be(sorted) }
|
22
22
|
|
23
23
|
its(:limit) { should == 1 }
|
24
24
|
end
|
@@ -28,7 +28,7 @@ describe Optimizer::Relation::Operation::Limit::LimitOperand, '#optimize' do
|
|
28
28
|
|
29
29
|
it { should be_kind_of(Relation::Operation::Limit) }
|
30
30
|
|
31
|
-
its(:operand) { should be(
|
31
|
+
its(:operand) { should be(sorted) }
|
32
32
|
|
33
33
|
its(:limit) { should == 2 }
|
34
34
|
end
|
data/spec/unit/axiom/optimizer/relation/operation/limit/unoptimized_operand/optimize_spec.rb
CHANGED
@@ -6,8 +6,8 @@ describe Optimizer::Relation::Operation::Limit::UnoptimizedOperand, '#optimize'
|
|
6
6
|
subject { object.optimize }
|
7
7
|
|
8
8
|
let(:header) { Relation::Header.coerce([[:id, Integer]]) }
|
9
|
-
let(:
|
10
|
-
let(:relation) {
|
9
|
+
let(:sorted) { Relation.new(header, LazyEnumerable.new([[1]])).sort_by { |r| r.id } }
|
10
|
+
let(:relation) { sorted.rename({}).take(1) }
|
11
11
|
let(:object) { described_class.new(relation) }
|
12
12
|
|
13
13
|
before do
|
@@ -16,7 +16,7 @@ describe Optimizer::Relation::Operation::Limit::UnoptimizedOperand, '#optimize'
|
|
16
16
|
|
17
17
|
it { should be_kind_of(Relation::Operation::Limit) }
|
18
18
|
|
19
|
-
its(:operand) { should be(
|
19
|
+
its(:operand) { should be(sorted) }
|
20
20
|
|
21
21
|
its(:limit) { should == 1 }
|
22
22
|
end
|
@@ -6,8 +6,8 @@ describe Optimizer::Relation::Operation::Limit::ZeroLimit, '#optimize' do
|
|
6
6
|
subject { object.optimize }
|
7
7
|
|
8
8
|
let(:header) { Relation::Header.coerce([[:id, Integer]]) }
|
9
|
-
let(:
|
10
|
-
let(:relation) {
|
9
|
+
let(:sorted) { Relation.new(header, LazyEnumerable.new([[1]])).sort_by { |r| r.id } }
|
10
|
+
let(:relation) { sorted.take(0) }
|
11
11
|
let(:object) { described_class.new(relation) }
|
12
12
|
|
13
13
|
before do
|
@@ -5,8 +5,8 @@ require 'spec_helper'
|
|
5
5
|
describe Optimizer::Relation::Operation::Offset::OffsetOperand, '#optimize' do
|
6
6
|
subject { object.optimize }
|
7
7
|
|
8
|
-
let(:
|
9
|
-
let(:relation) {
|
8
|
+
let(:sorted) { Relation.new([[:id, Integer]], LazyEnumerable.new([[1]])).sort_by { |r| r.id } }
|
9
|
+
let(:relation) { sorted.drop(1).drop(2) }
|
10
10
|
let(:object) { described_class.new(relation) }
|
11
11
|
|
12
12
|
before do
|
@@ -15,7 +15,7 @@ describe Optimizer::Relation::Operation::Offset::OffsetOperand, '#optimize' do
|
|
15
15
|
|
16
16
|
it { should be_kind_of(Relation::Operation::Offset) }
|
17
17
|
|
18
|
-
its(:operand) { should be(
|
18
|
+
its(:operand) { should be(sorted) }
|
19
19
|
|
20
20
|
its(:offset) { should == 3 }
|
21
21
|
end
|
data/spec/unit/axiom/optimizer/relation/operation/offset/unoptimized_operand/optimize_spec.rb
CHANGED
@@ -6,8 +6,8 @@ describe Optimizer::Relation::Operation::Offset::UnoptimizedOperand, '#optimize'
|
|
6
6
|
subject { object.optimize }
|
7
7
|
|
8
8
|
let(:header) { Relation::Header.coerce([[:id, Integer]]) }
|
9
|
-
let(:
|
10
|
-
let(:relation) {
|
9
|
+
let(:sorted) { Relation.new(header, LazyEnumerable.new([[1]])).sort_by { |r| r.id } }
|
10
|
+
let(:relation) { sorted.rename({}).drop(1) }
|
11
11
|
let(:object) { described_class.new(relation) }
|
12
12
|
|
13
13
|
before do
|
@@ -16,7 +16,7 @@ describe Optimizer::Relation::Operation::Offset::UnoptimizedOperand, '#optimize'
|
|
16
16
|
|
17
17
|
it { should be_kind_of(Relation::Operation::Offset) }
|
18
18
|
|
19
|
-
its(:operand) { should be(
|
19
|
+
its(:operand) { should be(sorted) }
|
20
20
|
|
21
21
|
its(:offset) { should == 1 }
|
22
22
|
end
|
@@ -5,13 +5,13 @@ require 'spec_helper'
|
|
5
5
|
describe Optimizer::Relation::Operation::Offset::ZeroOffset, '#optimize' do
|
6
6
|
subject { object.optimize }
|
7
7
|
|
8
|
-
let(:
|
9
|
-
let(:relation) {
|
8
|
+
let(:sorted) { Relation.new([[:id, Integer]], LazyEnumerable.new([[1]])).sort_by { |r| r.id } }
|
9
|
+
let(:relation) { sorted.drop(0) }
|
10
10
|
let(:object) { described_class.new(relation) }
|
11
11
|
|
12
12
|
before do
|
13
13
|
expect(object).to be_optimizable
|
14
14
|
end
|
15
15
|
|
16
|
-
it { should be(
|
16
|
+
it { should be(sorted) }
|
17
17
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Optimizer::Relation::Operation::Reverse::
|
5
|
+
describe Optimizer::Relation::Operation::Reverse::SortedOperand, '#optimizable?' do
|
6
6
|
subject { object.optimizable? }
|
7
7
|
|
8
8
|
let(:base) { Relation.new([[:id, Integer]], LazyEnumerable.new([[1]])) }
|
@@ -13,13 +13,13 @@ describe Optimizer::Relation::Operation::Reverse::OrderOperand, '#optimizable?'
|
|
13
13
|
expect(object.operation).to be_kind_of(Relation::Operation::Reverse)
|
14
14
|
end
|
15
15
|
|
16
|
-
context 'when the operand is
|
16
|
+
context 'when the operand is sorted' do
|
17
17
|
let(:operand) { base.sort_by { |r| r.id } }
|
18
18
|
|
19
19
|
it { should be(true) }
|
20
20
|
end
|
21
21
|
|
22
|
-
context 'when the operand is not
|
22
|
+
context 'when the operand is not sorted' do
|
23
23
|
let(:operand) { base.sort_by { |r| r.id }.take(2) }
|
24
24
|
|
25
25
|
it { should be(false) }
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Optimizer::Relation::Operation::Reverse::
|
5
|
+
describe Optimizer::Relation::Operation::Reverse::SortedOperand, '#optimize' do
|
6
6
|
subject { object.optimize }
|
7
7
|
|
8
8
|
let(:base) { Relation.new([[:id, Integer]], LazyEnumerable.new([[1]])) }
|
@@ -14,7 +14,7 @@ describe Optimizer::Relation::Operation::Reverse::OrderOperand, '#optimize' do
|
|
14
14
|
expect(object).to be_optimizable
|
15
15
|
end
|
16
16
|
|
17
|
-
it { should be_kind_of(Relation::Operation::
|
17
|
+
it { should be_kind_of(Relation::Operation::Sorted) }
|
18
18
|
|
19
19
|
its(:operand) { should be(base) }
|
20
20
|
|
data/spec/unit/axiom/optimizer/relation/operation/reverse/unoptimized_operand/optimize_spec.rb
CHANGED
@@ -6,19 +6,19 @@ describe Optimizer::Relation::Operation::Reverse::UnoptimizedOperand, '#optimize
|
|
6
6
|
subject { object.optimize }
|
7
7
|
|
8
8
|
let(:base) { Relation.new([[:id, Integer]], LazyEnumerable.new([[1]])) }
|
9
|
-
let(:
|
10
|
-
let(:relation) {
|
9
|
+
let(:sorted) { base.sort_by { |r| r.id } }
|
10
|
+
let(:relation) { sorted.rename({}).reverse }
|
11
11
|
let(:object) { described_class.new(relation) }
|
12
12
|
|
13
13
|
before do
|
14
14
|
expect(object).to be_optimizable
|
15
15
|
end
|
16
16
|
|
17
|
-
it { should be_kind_of(Relation::Operation::
|
17
|
+
it { should be_kind_of(Relation::Operation::Sorted) }
|
18
18
|
|
19
19
|
it { should_not be(relation) }
|
20
20
|
|
21
|
-
its(:operand) { should be(
|
21
|
+
its(:operand) { should be(sorted) }
|
22
22
|
|
23
23
|
its(:directions) { should eql(relation.directions) }
|
24
24
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Optimizer::Relation::Operation::
|
5
|
+
describe Optimizer::Relation::Operation::Sorted::OneLimitOperand, '#optimizable?' do
|
6
6
|
subject { object.optimizable? }
|
7
7
|
|
8
8
|
let(:base) { Relation.new([[:id, Integer]], LazyEnumerable.new([[1]])) }
|
@@ -10,7 +10,7 @@ describe Optimizer::Relation::Operation::Order::OneLimitOperand, '#optimizable?'
|
|
10
10
|
let(:object) { described_class.new(relation) }
|
11
11
|
|
12
12
|
before do
|
13
|
-
expect(object.operation).to be_kind_of(Relation::Operation::
|
13
|
+
expect(object.operation).to be_kind_of(Relation::Operation::Sorted)
|
14
14
|
end
|
15
15
|
|
16
16
|
context 'when the operand is limited to 1' do
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Optimizer::Relation::Operation::
|
5
|
+
describe Optimizer::Relation::Operation::Sorted::OneLimitOperand, '#optimize' do
|
6
6
|
subject { object.optimize }
|
7
7
|
|
8
8
|
let(:base) { Relation.new([[:id, Integer]], LazyEnumerable.new([[1]])) }
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Optimizer::Relation::Operation::
|
5
|
+
describe Optimizer::Relation::Operation::Sorted::SortedOperand, '#optimizable?' do
|
6
6
|
subject { object.optimizable? }
|
7
7
|
|
8
8
|
let(:base) { Relation.new([[:id, Integer]], LazyEnumerable.new([[1]])) }
|
@@ -10,16 +10,16 @@ describe Optimizer::Relation::Operation::Order::OrderOperand, '#optimizable?' do
|
|
10
10
|
let(:object) { described_class.new(relation) }
|
11
11
|
|
12
12
|
before do
|
13
|
-
expect(object.operation).to be_kind_of(Relation::Operation::
|
13
|
+
expect(object.operation).to be_kind_of(Relation::Operation::Sorted)
|
14
14
|
end
|
15
15
|
|
16
|
-
context 'when the operand is
|
16
|
+
context 'when the operand is sorted' do
|
17
17
|
let(:operand) { base.sort_by { |r| r.id } }
|
18
18
|
|
19
19
|
it { should be(true) }
|
20
20
|
end
|
21
21
|
|
22
|
-
context 'when the operand is not
|
22
|
+
context 'when the operand is not sorted' do
|
23
23
|
let(:operand) { base }
|
24
24
|
|
25
25
|
it { should be(false) }
|