Search in sources :

Example 61 with Collect

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)));
}
Also used : Collect(io.crate.planner.node.dql.Collect) CollectPhase(io.crate.execution.dsl.phases.CollectPhase) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 62 with Collect

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)));
}
Also used : Collect(io.crate.planner.node.dql.Collect) Join(io.crate.planner.node.dql.join.Join) CollectPhase(io.crate.execution.dsl.phases.CollectPhase) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 63 with Collect

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)));
}
Also used : QueryThenFetch(io.crate.planner.node.dql.QueryThenFetch) Collect(io.crate.planner.node.dql.Collect) Join(io.crate.planner.node.dql.join.Join) OrderedTopNProjection(io.crate.execution.dsl.projection.OrderedTopNProjection) GroupProjection(io.crate.execution.dsl.projection.GroupProjection) FilterProjection(io.crate.execution.dsl.projection.FilterProjection) AggregationProjection(io.crate.execution.dsl.projection.AggregationProjection) Projection(io.crate.execution.dsl.projection.Projection) TopNProjection(io.crate.execution.dsl.projection.TopNProjection) FetchProjection(io.crate.execution.dsl.projection.FetchProjection) EvalProjection(io.crate.execution.dsl.projection.EvalProjection) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 64 with Collect

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)));
}
Also used : Collect(io.crate.planner.node.dql.Collect) FilterProjection(io.crate.execution.dsl.projection.FilterProjection) AggregationProjection(io.crate.execution.dsl.projection.AggregationProjection) Projection(io.crate.execution.dsl.projection.Projection) TopNProjection(io.crate.execution.dsl.projection.TopNProjection) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 65 with Collect

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))));
}
Also used : Row1(io.crate.data.Row1) Collect(io.crate.planner.node.dql.Collect) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Aggregations

Collect (io.crate.planner.node.dql.Collect)66 Test (org.junit.Test)57 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)55 RoutedCollectPhase (io.crate.execution.dsl.phases.RoutedCollectPhase)31 RandomizedTest (com.carrotsearch.randomizedtesting.RandomizedTest)27 GroupProjection (io.crate.execution.dsl.projection.GroupProjection)18 EvalProjection (io.crate.execution.dsl.projection.EvalProjection)16 Merge (io.crate.planner.Merge)16 MergePhase (io.crate.execution.dsl.phases.MergePhase)14 Projection (io.crate.execution.dsl.projection.Projection)12 Reference (io.crate.metadata.Reference)11 FilterProjection (io.crate.execution.dsl.projection.FilterProjection)10 TopNProjection (io.crate.execution.dsl.projection.TopNProjection)10 OrderedTopNProjection (io.crate.execution.dsl.projection.OrderedTopNProjection)9 CollectPhase (io.crate.execution.dsl.phases.CollectPhase)8 Symbol (io.crate.expression.symbol.Symbol)8 AggregationProjection (io.crate.execution.dsl.projection.AggregationProjection)6 QueryThenFetch (io.crate.planner.node.dql.QueryThenFetch)6 ColumnIndexWriterProjection (io.crate.execution.dsl.projection.ColumnIndexWriterProjection)5 InputColumn (io.crate.expression.symbol.InputColumn)5