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()));
}
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)"));
}
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));
}
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));
}
Aggregations