Search in sources :

Example 6 with NestedLoop

use of io.crate.planner.node.dql.join.NestedLoop in project crate by crate.

the class NestedLoopConsumerTest method testLimitIncludesOffsetOnNestedLoopTopNProjection.

@Test
public void testLimitIncludesOffsetOnNestedLoopTopNProjection() throws Exception {
    Merge merge = plan("select u1.name, u2.name from users u1, users u2 where u1.id = u2.id order by u1.name, u2.name limit 15 offset 10");
    NestedLoop nl = (NestedLoop) merge.subPlan();
    TopNProjection distTopN = (TopNProjection) nl.nestedLoopPhase().projections().get(1);
    assertThat(distTopN.limit(), is(25));
    assertThat(distTopN.offset(), is(0));
    TopNProjection localTopN = (TopNProjection) merge.mergePhase().projections().get(0);
    assertThat(localTopN.limit(), is(15));
    assertThat(localTopN.offset(), is(10));
}
Also used : NestedLoop(io.crate.planner.node.dql.join.NestedLoop) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 7 with NestedLoop

use of io.crate.planner.node.dql.join.NestedLoop in project crate by crate.

the class NestedLoopConsumerTest method testExplicitCrossJoinWithoutLimitOrOrderBy.

@Test
public void testExplicitCrossJoinWithoutLimitOrOrderBy() throws Exception {
    QueryThenFetch plan = plan("select u1.name, u2.name from users u1 cross join users u2");
    NestedLoop nestedLoop = (NestedLoop) plan.subPlan();
    assertThat(nestedLoop.nestedLoopPhase().projections(), Matchers.contains(instanceOf(EvalProjection.class), instanceOf(FetchProjection.class)));
    EvalProjection eval = ((EvalProjection) nestedLoop.nestedLoopPhase().projections().get(0));
    assertThat(eval.outputs().size(), is(2));
    MergePhase leftMerge = nestedLoop.nestedLoopPhase().leftMergePhase();
    assertThat(leftMerge.projections().size(), is(0));
    MergePhase rightMerge = nestedLoop.nestedLoopPhase().rightMergePhase();
    assertThat(rightMerge.projections().size(), is(0));
}
Also used : NestedLoop(io.crate.planner.node.dql.join.NestedLoop) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 8 with NestedLoop

use of io.crate.planner.node.dql.join.NestedLoop in project crate by crate.

the class NestedLoopConsumerTest method testAggregationOnCrossJoin.

@Test
public void testAggregationOnCrossJoin() throws Exception {
    NestedLoop nl = plan("select min(u1.name) from users u1, users u2");
    NestedLoopPhase nlPhase = nl.nestedLoopPhase();
    assertThat(nlPhase.projections(), contains(instanceOf(EvalProjection.class), instanceOf(AggregationProjection.class), instanceOf(EvalProjection.class)));
    AggregationProjection aggregationProjection = (AggregationProjection) nlPhase.projections().get(1);
    Aggregation minAgg = aggregationProjection.aggregations().get(0);
    assertThat(minAgg.fromStep(), is(Aggregation.Step.ITER));
    assertThat(minAgg.toStep(), is(Aggregation.Step.FINAL));
}
Also used : Aggregation(io.crate.analyze.symbol.Aggregation) NestedLoop(io.crate.planner.node.dql.join.NestedLoop) NestedLoopPhase(io.crate.planner.node.dql.join.NestedLoopPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 9 with NestedLoop

use of io.crate.planner.node.dql.join.NestedLoop in project crate by crate.

the class InsertPlannerTest method testInsertFromSubQueryJoin.

@Test
public void testInsertFromSubQueryJoin() throws Exception {
    NestedLoop nestedLoop = e.plan("insert into users (id, name) (select u1.id, u2.name from users u1 CROSS JOIN users u2)");
    assertThat(nestedLoop.nestedLoopPhase().projections(), contains(instanceOf(EvalProjection.class), instanceOf(ColumnIndexWriterProjection.class)));
    assertThat(nestedLoop.nestedLoopPhase().projections().get(1), instanceOf(ColumnIndexWriterProjection.class));
    ColumnIndexWriterProjection projection = (ColumnIndexWriterProjection) nestedLoop.nestedLoopPhase().projections().get(1);
    assertThat(projection.columnReferences().size(), is(2));
    assertThat(projection.columnReferences().get(0).ident().columnIdent().fqn(), is("id"));
    assertThat(projection.columnReferences().get(1).ident().columnIdent().fqn(), is("name"));
    assertThat(((InputColumn) projection.ids().get(0)).index(), is(0));
    assertThat(((InputColumn) projection.clusteredBy()).index(), is(0));
    assertThat(projection.partitionedBySymbols().isEmpty(), is(true));
}
Also used : NestedLoop(io.crate.planner.node.dql.join.NestedLoop) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 10 with NestedLoop

use of io.crate.planner.node.dql.join.NestedLoop in project crate by crate.

the class SingleRowSubselectPlannerTest method testSingleRowSubSelectOfWhereInJoin.

@Test
public void testSingleRowSubSelectOfWhereInJoin() throws Exception {
    QueryThenFetch plan = e.plan("select * from users u1, users u2 where u1.name = (select 'Arthur')");
    assertThat(plan.subPlan(), instanceOf(NestedLoop.class));
    assertThat(((NestedLoop) plan.subPlan()).left(), instanceOf(MultiPhasePlan.class));
}
Also used : NestedLoop(io.crate.planner.node.dql.join.NestedLoop) QueryThenFetch(io.crate.planner.node.dql.QueryThenFetch) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

NestedLoop (io.crate.planner.node.dql.join.NestedLoop)20 CrateUnitTest (io.crate.test.integration.CrateUnitTest)20 Test (org.junit.Test)20 NestedLoopPhase (io.crate.planner.node.dql.join.NestedLoopPhase)3 Aggregation (io.crate.analyze.symbol.Aggregation)1 Symbol (io.crate.analyze.symbol.Symbol)1 QueryThenFetch (io.crate.planner.node.dql.QueryThenFetch)1