use of io.crate.planner.node.dql.Collect in project crate by crate.
the class SubQueryPlannerTest method testNestedSimpleSelectContainsGroupProjectionWithFunction.
@Test
public void testNestedSimpleSelectContainsGroupProjectionWithFunction() throws Exception {
Collect collect = e.plan("select c + 100, max(max) from " + " (select x + 10::int as c, max(i) as max from t1 group by x + 10::int) t " + "group by c + 100 order by c + 100 " + "limit 100");
CollectPhase collectPhase = collect.collectPhase();
assertThat(collectPhase.toCollect(), contains(isReference("i"), isFunction("add", isReference("x"), isLiteral(10))));
assertThat(collectPhase.projections(), contains(instanceOf(GroupProjection.class), instanceOf(GroupProjection.class), instanceOf(EvalProjection.class), instanceOf(GroupProjection.class), instanceOf(OrderedTopNProjection.class), instanceOf(TopNProjection.class)));
}
use of io.crate.planner.node.dql.Collect in project crate by crate.
the class SubQueryPlannerTest method testJoinWithAggregationOnSubSelectsWithAggregations.
@Test
public void testJoinWithAggregationOnSubSelectsWithAggregations() throws Exception {
Join nl = e.plan("select t1.a, count(*) from " + " (select a, count(*) as cnt from t1 group by a) t1 " + "join" + " (select distinct i from t2) t2 " + "on t1.cnt = t2.i::long " + "group by t1.a");
assertThat(nl.joinPhase().projections(), contains(instanceOf(EvalProjection.class), instanceOf(GroupProjection.class)));
assertThat(nl.left(), instanceOf(Collect.class));
Collect leftPlan = (Collect) nl.left();
CollectPhase leftCollectPhase = leftPlan.collectPhase();
assertThat(leftCollectPhase.projections(), contains(instanceOf(GroupProjection.class), instanceOf(GroupProjection.class), instanceOf(EvalProjection.class)));
Collect rightPlan = (Collect) nl.right();
assertThat(rightPlan.collectPhase().projections(), contains(instanceOf(GroupProjection.class), instanceOf(GroupProjection.class)));
}
use of io.crate.planner.node.dql.Collect in project crate by crate.
the class SubQueryPlannerTest method testJoinWithAggregationOnSubSelectsWithLimitAndOffset.
@Test
public void testJoinWithAggregationOnSubSelectsWithLimitAndOffset() throws Exception {
Join join = e.plan("select t1.a, count(*) from " + " (select i, a from t1 order by a limit 10 offset 2) t1 " + "join" + " (select i from t2 order by i desc limit 5 offset 5) t2 " + "on t1.i = t2.i " + "group by t1.a");
QueryThenFetch qtf = (QueryThenFetch) join.left();
Collect left = (Collect) qtf.subPlan();
assertThat("1 node, otherwise mergePhases would be required", left.nodeIds().size(), is(1));
assertThat(((RoutedCollectPhase) left.collectPhase()).orderBy(), isSQL("doc.t1.a"));
assertThat(left.collectPhase().projections(), contains(isTopN(10, 2), instanceOf(FetchProjection.class)));
assertThat(left.collectPhase().toCollect(), isSQL("doc.t1._fetchid, doc.t1.a"));
Collect right = (Collect) join.right();
assertThat("1 node, otherwise mergePhases would be required", right.nodeIds().size(), is(1));
assertThat(((RoutedCollectPhase) right.collectPhase()).orderBy(), isSQL("doc.t2.i DESC"));
assertThat(right.collectPhase().projections(), contains(isTopN(5, 5)));
List<Projection> nlProjections = join.joinPhase().projections();
assertThat(nlProjections, contains(instanceOf(EvalProjection.class), instanceOf(GroupProjection.class)));
}
use of io.crate.planner.node.dql.Collect in project crate by crate.
the class GlobalAggregatePlannerTest method testAggregateOnSubQueryNoFetchBecauseColumnInUse.
@Test
public void testAggregateOnSubQueryNoFetchBecauseColumnInUse() throws Exception {
Collect plan = e.plan("select sum(x) from (select x, i from t1 order by x limit 10) ti");
List<Projection> projections = plan.collectPhase().projections();
assertThat(projections, contains(instanceOf(TopNProjection.class), instanceOf(AggregationProjection.class)));
}
use of io.crate.planner.node.dql.Collect in project crate by crate.
the class GlobalAggregatePlannerTest method test_aggregation_is_correctly_build_with_parameterized_expression.
@Test
public void test_aggregation_is_correctly_build_with_parameterized_expression() {
Collect plan = e.plan("select sum(x + ?) from t1", UUID.randomUUID(), 0, new Row1(1));
var projections = plan.collectPhase().projections();
assertThat(projections, contains(instanceOf(AggregationProjection.class), instanceOf(AggregationProjection.class)));
assertThat(projections.get(0).outputs(), contains(isAggregation("sum", isInputColumn(0))));
assertThat(projections.get(1).outputs(), contains(isAggregation("sum", isInputColumn(0))));
}
Aggregations