Search in sources :

Example 51 with Collect

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

the class CopyToPlannerTest method testCopyToWithColumnsReferenceRewrite.

@Test
public void testCopyToWithColumnsReferenceRewrite() {
    Merge plan = plan("copy users (name) to directory '/tmp'");
    Collect innerPlan = (Collect) plan.subPlan();
    RoutedCollectPhase node = ((RoutedCollectPhase) innerPlan.collectPhase());
    Reference nameRef = (Reference) node.toCollect().get(0);
    assertThat(nameRef.column().name(), is(DocSysColumns.DOC.name()));
    assertThat(nameRef.column().path().get(0), is("name"));
}
Also used : Merge(io.crate.planner.Merge) Collect(io.crate.planner.node.dql.Collect) Reference(io.crate.metadata.Reference) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Example 52 with Collect

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

the class UpdatePlanner method createCollectAndMerge.

private static ExecutionPlan createCollectAndMerge(PlannerContext plannerCtx, TableInfo tableInfo, Reference idReference, Projection updateProjection, WhereClause where, int numOutPuts, int maxRowsPerNode, Projection... mergeProjections) {
    SessionContext sessionContext = plannerCtx.transactionContext().sessionContext();
    Routing routing = plannerCtx.allocateRouting(tableInfo, where, RoutingProvider.ShardSelection.PRIMARIES, sessionContext);
    RoutedCollectPhase collectPhase = new RoutedCollectPhase(plannerCtx.jobId(), plannerCtx.nextExecutionPhaseId(), "collect", routing, tableInfo.rowGranularity(), List.of(idReference), singletonList(updateProjection), Optimizer.optimizeCasts(where.queryOrFallback(), plannerCtx), DistributionInfo.DEFAULT_BROADCAST);
    Collect collect = new Collect(collectPhase, TopN.NO_LIMIT, 0, numOutPuts, maxRowsPerNode, null);
    return Merge.ensureOnHandler(collect, plannerCtx, List.of(mergeProjections));
}
Also used : Collect(io.crate.planner.node.dql.Collect) SessionContext(io.crate.action.sql.SessionContext) Routing(io.crate.metadata.Routing) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase)

Example 53 with Collect

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

the class GroupByScalarPlannerTest method testGroupByWithScalarPlan.

@Test
public void testGroupByWithScalarPlan() throws Exception {
    Merge merge = e.plan("select id + 1 from users group by id");
    Collect collect = (Collect) merge.subPlan();
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
    assertEquals(DataTypes.LONG, collectPhase.outputTypes().get(0));
    assertThat(collectPhase.maxRowGranularity(), is(RowGranularity.DOC));
    assertThat(collectPhase.projections().size(), is(2));
    assertThat(collectPhase.projections().get(0), instanceOf(GroupProjection.class));
    assertThat(collectPhase.projections().get(0).requiredGranularity(), is(RowGranularity.SHARD));
    assertThat(collectPhase.projections().get(1), instanceOf(EvalProjection.class));
    assertThat(collectPhase.projections().get(1).outputs().get(0), instanceOf(Function.class));
    assertThat(collectPhase.toCollect(), contains(isReference("id", DataTypes.LONG)));
    GroupProjection groupProjection = (GroupProjection) collectPhase.projections().get(0);
    assertThat(groupProjection.keys().get(0).valueType(), is(DataTypes.LONG));
    assertThat(collectPhase.projections().get(1).outputs(), contains(isFunction("add")));
    MergePhase mergePhase = merge.mergePhase();
    assertEquals(DataTypes.LONG, mergePhase.inputTypes().iterator().next());
    assertEquals(DataTypes.LONG, mergePhase.outputTypes().get(0));
}
Also used : SymbolMatchers.isFunction(io.crate.testing.SymbolMatchers.isFunction) Function(io.crate.expression.symbol.Function) MergePhase(io.crate.execution.dsl.phases.MergePhase) Collect(io.crate.planner.node.dql.Collect) EvalProjection(io.crate.execution.dsl.projection.EvalProjection) GroupProjection(io.crate.execution.dsl.projection.GroupProjection) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Example 54 with Collect

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

the class InsertPlannerTest method testInsertFromSubQueryWithoutLimit.

@Test
public void testInsertFromSubQueryWithoutLimit() {
    Merge planNode = e.plan("insert into users (id, name) (select id, name from users)");
    Collect collect = (Collect) planNode.subPlan();
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
    assertThat(collectPhase.projections().size(), is(1));
    assertThat(collectPhase.projections().get(0), instanceOf(ColumnIndexWriterProjection.class));
    MergePhase localMergeNode = planNode.mergePhase();
    assertThat(localMergeNode.projections().size(), is(1));
    assertThat(localMergeNode.projections().get(0), instanceOf(MergeCountProjection.class));
}
Also used : MergeCountProjection(io.crate.execution.dsl.projection.MergeCountProjection) MergePhase(io.crate.execution.dsl.phases.MergePhase) Collect(io.crate.planner.node.dql.Collect) 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 55 with Collect

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

the class InsertPlannerTest method testInsertFromSubQueryDistributedGroupByWithLimit.

@Test
public void testInsertFromSubQueryDistributedGroupByWithLimit() {
    Merge localMerge = e.plan("insert into users (id, name) " + "(select name, count(*) from users group by name order by name limit 10)");
    Merge distMerge = (Merge) localMerge.subPlan();
    Collect collect = (Collect) distMerge.subPlan();
    assertThat(collect.collectPhase().projections(), contains(instanceOf(GroupProjection.class)));
    assertThat(distMerge.mergePhase().projections(), contains(instanceOf(GroupProjection.class), instanceOf(OrderedTopNProjection.class), instanceOf(EvalProjection.class)));
    assertThat(localMerge.mergePhase().projections(), contains(instanceOf(TopNProjection.class), instanceOf(ColumnIndexWriterProjection.class)));
}
Also used : Collect(io.crate.planner.node.dql.Collect) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

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