Sha256: 07384e0ba5af1f90d525d81e22b954dd1ff1c75ab3b60b2d61d9e1fcb8af8b6b

Contents?: true

Size: 1.72 KB

Versions: 3

Compression:

Stored size: 1.72 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Optimizer::Algebra::Join::LeftMaterializedOperand, '#optimize' do
  subject { object.optimize }

  let(:relation) { left.join(right)              }
  let(:object)   { described_class.new(relation) }

  before do
    object.should be_optimizable
  end

  context 'with no joined tuples' do
    let(:left)  { Relation.new([ [ :id, Integer ],                    ], [])      }
    let(:right) { Relation.new([ [ :id, Integer ], [ :age,  Integer ] ], [].each) }

    it { should be_kind_of(Algebra::Join) }

    its(:left) { should eql(Relation::Empty.new(left.header)) }

    its(:right) { should eql(right.restrict { Function::Proposition::Contradiction.instance }) }
  end

  context 'with one joined tuple' do
    let(:left)  { Relation.new([ [ :id, Integer ],                    ], [ [ 1,    ] ])      }
    let(:right) { Relation.new([ [ :id, Integer ], [ :age,  Integer ] ], [ [ 1, 35 ] ].each) }

    it { should be_kind_of(Algebra::Join) }

    its(:left) { should equal(left) }

    its(:right) { should eql(right.restrict { |r| r.id.eq(1) }) }

    it 'is not further optimizable' do
      described_class.new(subject).should_not be_optimizable
    end
  end

  context 'with two or more joined tuples' do
    let(:left)  { Relation.new([ [ :id, Integer ],                    ], [ [ 1,    ], [ 2,    ] ])      }
    let(:right) { Relation.new([ [ :id, Integer ], [ :age,  Integer ] ], [ [ 1, 35 ], [ 2, 25 ] ].each) }

    it { should be_kind_of(Algebra::Join) }

    its(:left) { should equal(left) }

    its(:right) { should eql(right.restrict { |r| r.id.include([ 1, 2 ]) }) }

    it 'is not further optimizable' do
      described_class.new(subject).should_not be_optimizable
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
veritas-optimizer-0.0.7 spec/unit/veritas/optimizer/algebra/join/left_materialized_operand/optimize_spec.rb
veritas-optimizer-0.0.6 spec/unit/veritas/optimizer/algebra/join/left_materialized_operand/optimize_spec.rb
veritas-optimizer-0.0.5 spec/unit/veritas/optimizer/algebra/join/left_materialized_operand/optimize_spec.rb