Search in sources :

Example 1 with NestedLoopPhase

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

the class NestedLoopPhaseTest method testSerialization.

@Test
public void testSerialization() throws Exception {
    TopNProjection topNProjection = new TopNProjection(10, 0, Collections.emptyList());
    UUID jobId = UUID.randomUUID();
    MergePhase mp1 = new MergePhase(jobId, 2, "merge", 1, Collections.emptyList(), ImmutableList.<DataType>of(DataTypes.STRING), ImmutableList.of(), DistributionInfo.DEFAULT_BROADCAST, null);
    MergePhase mp2 = new MergePhase(jobId, 3, "merge", 1, Collections.emptyList(), ImmutableList.<DataType>of(DataTypes.STRING), ImmutableList.of(), DistributionInfo.DEFAULT_BROADCAST, null);
    SqlExpressions sqlExpressions = new SqlExpressions(T3.SOURCES, T3.TR_1);
    Symbol joinCondition = sqlExpressions.normalize(sqlExpressions.asSymbol("t1.x = t1.i"));
    NestedLoopPhase node = new NestedLoopPhase(jobId, 1, "nestedLoop", ImmutableList.of(topNProjection), mp1, mp2, Sets.newHashSet("node1", "node2"), JoinType.INNER, joinCondition, 1, 1);
    BytesStreamOutput output = new BytesStreamOutput();
    node.writeTo(output);
    StreamInput input = StreamInput.wrap(output.bytes());
    NestedLoopPhase node2 = new NestedLoopPhase();
    node2.readFrom(input);
    assertThat(node.nodeIds(), Is.is(node2.nodeIds()));
    assertThat(node.jobId(), Is.is(node2.jobId()));
    assertThat(node.name(), is(node2.name()));
    assertThat(node.outputTypes(), is(node2.outputTypes()));
    assertThat(node.joinType(), is(node2.joinType()));
    assertThat(node.numLeftOutputs(), is(node2.numLeftOutputs()));
    assertThat(node.numRightOutputs(), is(node2.numRightOutputs()));
}
Also used : Symbol(io.crate.analyze.symbol.Symbol) StreamInput(org.elasticsearch.common.io.stream.StreamInput) TopNProjection(io.crate.planner.projection.TopNProjection) UUID(java.util.UUID) SqlExpressions(io.crate.testing.SqlExpressions) NestedLoopPhase(io.crate.planner.node.dql.join.NestedLoopPhase) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 2 with NestedLoopPhase

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

the class NestedLoopConsumerTest method testFetch.

@Test
public void testFetch() throws Exception {
    QueryThenFetch plan = plan("select u1.name, u2.id from users u1, users u2 order by 2");
    NestedLoopPhase nlp = ((NestedLoop) plan.subPlan()).nestedLoopPhase();
    assertThat(nlp.projections().get(0).outputs(), isSQL("INPUT(1), INPUT(0)"));
}
Also used : 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 3 with NestedLoopPhase

use of io.crate.planner.node.dql.join.NestedLoopPhase 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 4 with NestedLoopPhase

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

the class NestedLoopConsumerTest method testLimitNotAppliedWhenFilteringRemains.

@Test
public void testLimitNotAppliedWhenFilteringRemains() throws Exception {
    QueryThenFetch plan = plan("select * from users u1 " + "left join users u2 on u1.id=u2.id " + "left join users u3 on u2.id=u3.id " + "left join users u4 on u3.id=u4.id " + "where u1.name = u4.name " + "limit 10");
    NestedLoopPhase nl = ((NestedLoop) plan.subPlan()).nestedLoopPhase();
    assertThat(nl.projections().get(1), instanceOf(TopNProjection.class));
    assertThat(((TopNProjection) nl.projections().get(1)).limit(), is(10));
    nl = ((NestedLoop) ((NestedLoop) plan.subPlan()).left()).nestedLoopPhase();
    assertThat(nl.projections().get(0), instanceOf(EvalProjection.class));
    nl = ((NestedLoop) ((NestedLoop) ((NestedLoop) plan.subPlan()).left()).left()).nestedLoopPhase();
    assertThat(nl.projections().get(0), instanceOf(EvalProjection.class));
}
Also used : 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)

Aggregations

NestedLoopPhase (io.crate.planner.node.dql.join.NestedLoopPhase)4 CrateUnitTest (io.crate.test.integration.CrateUnitTest)4 Test (org.junit.Test)4 NestedLoop (io.crate.planner.node.dql.join.NestedLoop)3 Aggregation (io.crate.analyze.symbol.Aggregation)1 Symbol (io.crate.analyze.symbol.Symbol)1 TopNProjection (io.crate.planner.projection.TopNProjection)1 SqlExpressions (io.crate.testing.SqlExpressions)1 UUID (java.util.UUID)1 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)1 StreamInput (org.elasticsearch.common.io.stream.StreamInput)1