Search in sources :

Example 26 with Collect

use of io.crate.planner.node.dql.Collect in project crate by crate.

the class InsertPlannerTest method testInsertFromQueryWithPartitionedColumn.

@Test
public void testInsertFromQueryWithPartitionedColumn() {
    Merge planNode = e.plan("insert into users (id, date) (select id, date from parted_pks)");
    Collect queryAndFetch = (Collect) planNode.subPlan();
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) queryAndFetch.collectPhase());
    List<Symbol> toCollect = collectPhase.toCollect();
    assertThat(toCollect.size(), is(2));
    assertThat(toCollect.get(0), isReference("_doc['id']"));
    assertThat(toCollect.get(1), equalTo(new Reference(new ReferenceIdent(new RelationName(Schemas.DOC_SCHEMA_NAME, "parted_pks"), "date"), RowGranularity.PARTITION, DataTypes.TIMESTAMPZ, ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 3, null)));
}
Also used : Collect(io.crate.planner.node.dql.Collect) Symbol(io.crate.expression.symbol.Symbol) Reference(io.crate.metadata.Reference) SymbolMatchers.isReference(io.crate.testing.SymbolMatchers.isReference) RelationName(io.crate.metadata.RelationName) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) ReferenceIdent(io.crate.metadata.ReferenceIdent) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 27 with Collect

use of io.crate.planner.node.dql.Collect in project crate by crate.

the class InsertPlannerTest method test_insert_select_distinct.

@Test
public void test_insert_select_distinct() throws Exception {
    Merge merge = e.plan("insert into users (id) (select distinct id from users)");
    Collect collect = (Collect) merge.subPlan();
    List<Projection> projections = collect.collectPhase().projections();
    assertThat(projections, contains(instanceOf(GroupProjection.class), instanceOf(ColumnIndexWriterProjection.class)));
    assertThat(projections.get(0).requiredGranularity(), is(RowGranularity.SHARD));
}
Also used : Collect(io.crate.planner.node.dql.Collect) OrderedTopNProjection(io.crate.execution.dsl.projection.OrderedTopNProjection) ColumnIndexWriterProjection(io.crate.execution.dsl.projection.ColumnIndexWriterProjection) MergeCountProjection(io.crate.execution.dsl.projection.MergeCountProjection) 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 28 with Collect

use of io.crate.planner.node.dql.Collect in project crate by crate.

the class InsertPlannerTest method testInsertFromSubQueryReduceOnCollectorGroupByWithCast.

@Test
public void testInsertFromSubQueryReduceOnCollectorGroupByWithCast() {
    Merge merge = e.plan("insert into users (id, name) (select id, count(*) from users group by id)");
    Collect nonDistributedGroupBy = (Collect) merge.subPlan();
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) nonDistributedGroupBy.collectPhase());
    assertThat(collectPhase.projections(), contains(instanceOf(GroupProjection.class), instanceOf(EvalProjection.class), instanceOf(ColumnIndexWriterProjection.class)));
    EvalProjection collectTopN = (EvalProjection) collectPhase.projections().get(1);
    assertThat(collectTopN.outputs(), contains(isInputColumn(0), isFunction(ImplicitCastFunction.NAME, List.of(DataTypes.LONG, DataTypes.STRING))));
    ColumnIndexWriterProjection columnIndexWriterProjection = (ColumnIndexWriterProjection) collectPhase.projections().get(2);
    assertThat(columnIndexWriterProjection.columnReferencesExclPartition(), contains(isReference("id"), isReference("name")));
    MergePhase mergePhase = merge.mergePhase();
    assertThat(mergePhase.projections(), contains(instanceOf(MergeCountProjection.class)));
}
Also used : MergePhase(io.crate.execution.dsl.phases.MergePhase) Collect(io.crate.planner.node.dql.Collect) EvalProjection(io.crate.execution.dsl.projection.EvalProjection) ColumnIndexWriterProjection(io.crate.execution.dsl.projection.ColumnIndexWriterProjection) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 29 with Collect

use of io.crate.planner.node.dql.Collect in project crate by crate.

the class InsertPlannerTest method testInsertFromSubQueryWithLimit.

@Test
public void testInsertFromSubQueryWithLimit() {
    QueryThenFetch qtf = e.plan("insert into users (date, id, name) (select date, id, name from users limit 10)");
    Merge merge = (Merge) qtf.subPlan();
    Collect collect = (Collect) merge.subPlan();
    assertThat(collect.collectPhase().projections(), contains(instanceOf(TopNProjection.class)));
    assertThat(merge.mergePhase().projections(), contains(instanceOf(TopNProjection.class), instanceOf(FetchProjection.class), instanceOf(ColumnIndexWriterProjection.class)));
}
Also used : QueryThenFetch(io.crate.planner.node.dql.QueryThenFetch) Collect(io.crate.planner.node.dql.Collect) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 30 with Collect

use of io.crate.planner.node.dql.Collect in project crate by crate.

the class GlobalAggregatePlannerTest method test_aggregate_on_virtual_table_uses_shard_projections_if_possible.

@Test
public void test_aggregate_on_virtual_table_uses_shard_projections_if_possible() {
    Collect plan = e.plan("select sum(x) from (select x from t1) t");
    List<Projection> projections = plan.collectPhase().projections();
    assertThat(projections, contains(instanceOf(AggregationProjection.class), instanceOf(AggregationProjection.class)));
    assertThat(projections.get(0).requiredGranularity(), is(RowGranularity.SHARD));
}
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)

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