-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Handles push-down of an insertion into a projection operator * Only applies if the removed attributes are optional, since the right relation needs to be extended with those attributes and the value defaults to nil.
- Loading branch information
Showing
6 changed files
with
155 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
spec/unit/veritas/optimizer/relation/operation/insertion/projection_left/optimizable_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# encoding: utf-8 | ||
|
||
require 'spec_helper' | ||
|
||
describe Optimizer::Relation::Operation::Insertion::ProjectionLeft, '#optimizable?' do | ||
subject { object.optimizable? } | ||
|
||
let(:object) { described_class.new(relation) } | ||
let(:relation) { left.insert(right) } | ||
let(:right) { Relation.new([ [ :id, Integer ] ], [ [ 2 ] ].each) } | ||
|
||
before do | ||
object.operation.should be_kind_of(Relation::Operation::Insertion) | ||
end | ||
|
||
context 'when the left is a projection, and removed attributes are optional' do | ||
let(:header) { [ [ :id, Integer ], [ :name, String, { :required => false } ] ] } | ||
let(:left) { Relation.new(header, [ [ 1, 'John Doe' ] ].each).project([ :id ]) } | ||
|
||
it { should be(true) } | ||
end | ||
|
||
context 'when the left is a projection, and removed attributes are required' do | ||
let(:header) { [ [ :id, Integer ], [ :name, String ] ] } | ||
let(:left) { Relation.new(header, [ [ 1, 'John Doe' ] ].each).project([ :id ]) } | ||
|
||
it { should be(false) } | ||
end | ||
|
||
context 'when the left is not a projection' do | ||
let(:left) { Relation.new([ [ :id, Integer ] ], [ [ 1 ] ].each) } | ||
|
||
it { should be(false) } | ||
end | ||
end |
29 changes: 29 additions & 0 deletions
29
spec/unit/veritas/optimizer/relation/operation/insertion/projection_left/optimize_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# encoding: utf-8 | ||
|
||
require 'spec_helper' | ||
|
||
describe Optimizer::Relation::Operation::Insertion::ProjectionLeft, '#optimize' do | ||
subject { object.optimize } | ||
|
||
let(:object) { described_class.new(relation) } | ||
let(:relation) { left.insert(right) } | ||
let(:base_left) { Relation.new(header, [ [ 1, 'John Doe' ] ].each) } | ||
let(:left) { base_left.project([ :id ]) } | ||
let(:right) { Relation.new([ [ :id, Integer ] ], [ [ 2 ] ].each) } | ||
let(:header) { [ [ :id, Integer ], [ :name, String, { :required => false } ] ] } | ||
|
||
before do | ||
object.should be_optimizable | ||
end | ||
|
||
it { should be_instance_of(Algebra::Projection) } | ||
|
||
# the operand is the base left and the right is extended with the removed attributes | ||
its(:operand) do | ||
should eql(base_left.insert(right.extend { |r| | ||
r.add([ :name, String, { :required => false } ], nil) | ||
})) | ||
end | ||
|
||
its(:header) { should == [ [ :id, Integer ] ] } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters