Search in sources :

Example 6 with Collect

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

the class DeleteStatementPlanner method collectWithDeleteProjection.

private static Plan collectWithDeleteProjection(TableInfo tableInfo, WhereClause whereClause, Planner.Context plannerContext) {
    // for delete, we always need to collect the `_uid`
    Reference idReference = tableInfo.getReference(DocSysColumns.ID);
    DeleteProjection deleteProjection = new DeleteProjection(new InputColumn(0, DataTypes.STRING));
    Routing routing = plannerContext.allocateRouting(tableInfo, whereClause, Preference.PRIMARY.type());
    RoutedCollectPhase collectPhase = new RoutedCollectPhase(plannerContext.jobId(), plannerContext.nextExecutionPhaseId(), "collect", routing, tableInfo.rowGranularity(), ImmutableList.of(idReference), ImmutableList.of(deleteProjection), whereClause, DistributionInfo.DEFAULT_BROADCAST);
    Collect collect = new Collect(collectPhase, TopN.NO_LIMIT, 0, 1, 1, null);
    return Merge.ensureOnHandler(collect, plannerContext, Collections.singletonList(MergeCountProjection.INSTANCE));
}
Also used : Collect(io.crate.planner.node.dql.Collect) Reference(io.crate.metadata.Reference) InputColumn(io.crate.analyze.symbol.InputColumn) DeleteProjection(io.crate.planner.projection.DeleteProjection) Routing(io.crate.metadata.Routing) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase)

Example 7 with Collect

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

the class InsertPlannerTest method testInsertFromSubQueryReduceOnCollectorGroupByWithCast.

@Test
public void testInsertFromSubQueryReduceOnCollectorGroupByWithCast() throws Exception {
    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("to_string")));
    ColumnIndexWriterProjection columnIndexWriterProjection = (ColumnIndexWriterProjection) collectPhase.projections().get(2);
    assertThat(columnIndexWriterProjection.columnReferences(), contains(isReference("id"), isReference("name")));
    MergePhase mergePhase = merge.mergePhase();
    assertThat(mergePhase.projections(), contains(instanceOf(MergeCountProjection.class)));
}
Also used : MergePhase(io.crate.planner.node.dql.MergePhase) Collect(io.crate.planner.node.dql.Collect) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 8 with Collect

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

the class InsertPlannerTest method testInsertFromQueryWithPartitionedColumn.

@Test
public void testInsertFromQueryWithPartitionedColumn() throws Exception {
    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), isFunction("to_long"));
    assertThat(((Function) toCollect.get(0)).arguments().get(0), isReference("_doc['id']"));
    assertThat((Reference) toCollect.get(1), equalTo(new Reference(new ReferenceIdent(TableDefinitions.PARTED_PKS_IDENT, "date"), RowGranularity.PARTITION, DataTypes.TIMESTAMP)));
}
Also used : Function(io.crate.analyze.symbol.Function) Collect(io.crate.planner.node.dql.Collect) Symbol(io.crate.analyze.symbol.Symbol) Reference(io.crate.metadata.Reference) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) ReferenceIdent(io.crate.metadata.ReferenceIdent) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 9 with Collect

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

the class GlobalAggregateConsumer method globalAggregates.

/**
     * Create a Merge(Collect) plan.
     *
     * iter->partial aggregations on use {@code projectionGranularity} granularity
     */
private static Plan globalAggregates(Functions functions, QueriedTableRelation table, ConsumerContext context, RowGranularity projectionGranularity) {
    QuerySpec querySpec = table.querySpec();
    if (querySpec.groupBy().isPresent() || !querySpec.hasAggregates()) {
        return null;
    }
    // global aggregate: collect and partial aggregate on C and final agg on H
    Planner.Context plannerContext = context.plannerContext();
    validateAggregationOutputs(table.tableRelation(), querySpec.outputs());
    ProjectionBuilder projectionBuilder = new ProjectionBuilder(functions, querySpec);
    SplitPoints splitPoints = projectionBuilder.getSplitPoints();
    AggregationProjection ap = projectionBuilder.aggregationProjection(splitPoints.leaves(), splitPoints.aggregates(), Aggregation.Step.ITER, Aggregation.Step.PARTIAL, projectionGranularity);
    RoutedCollectPhase collectPhase = RoutedCollectPhase.forQueriedTable(plannerContext, table, splitPoints.leaves(), ImmutableList.of(ap));
    Collect collect = new Collect(collectPhase, TopN.NO_LIMIT, 0, ap.outputs().size(), 1, null);
    AggregationProjection aggregationProjection = projectionBuilder.aggregationProjection(splitPoints.aggregates(), splitPoints.aggregates(), Aggregation.Step.PARTIAL, Aggregation.Step.FINAL, RowGranularity.CLUSTER);
    List<Projection> postAggregationProjections = createPostAggregationProjections(querySpec, splitPoints, plannerContext);
    postAggregationProjections.add(0, aggregationProjection);
    return createMerge(collect, plannerContext, postAggregationProjections);
}
Also used : Collect(io.crate.planner.node.dql.Collect) SplitPoints(io.crate.planner.projection.builder.SplitPoints) FilterProjection(io.crate.planner.projection.FilterProjection) AggregationProjection(io.crate.planner.projection.AggregationProjection) Projection(io.crate.planner.projection.Projection) ProjectionBuilder(io.crate.planner.projection.builder.ProjectionBuilder) AggregationProjection(io.crate.planner.projection.AggregationProjection) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase)

Example 10 with Collect

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

the class UpdateConsumer method createPlan.

private static Plan createPlan(Planner.Context plannerContext, Routing routing, TableInfo tableInfo, Reference idReference, Projection updateProjection, WhereClause whereClause) {
    RoutedCollectPhase collectPhase = new RoutedCollectPhase(plannerContext.jobId(), plannerContext.nextExecutionPhaseId(), "collect", routing, tableInfo.rowGranularity(), Collections.singletonList(idReference), Collections.singletonList(updateProjection), whereClause, DistributionInfo.DEFAULT_BROADCAST);
    Collect collect = new Collect(collectPhase, TopN.NO_LIMIT, 0, 1, 1, null);
    return Merge.ensureOnHandler(collect, plannerContext, Collections.singletonList(MergeCountProjection.INSTANCE));
}
Also used : Collect(io.crate.planner.node.dql.Collect) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase)

Aggregations

Collect (io.crate.planner.node.dql.Collect)21 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)18 CrateUnitTest (io.crate.test.integration.CrateUnitTest)17 Test (org.junit.Test)17 MergePhase (io.crate.planner.node.dql.MergePhase)9 Merge (io.crate.planner.Merge)8 Reference (io.crate.metadata.Reference)6 Symbol (io.crate.analyze.symbol.Symbol)3 InputColumn (io.crate.analyze.symbol.InputColumn)2 PositionalOrderBy (io.crate.planner.PositionalOrderBy)2 DeleteProjection (io.crate.planner.projection.DeleteProjection)2 MergeCountProjection (io.crate.planner.projection.MergeCountProjection)2 Projection (io.crate.planner.projection.Projection)2 WriterProjection (io.crate.planner.projection.WriterProjection)2 Function (io.crate.analyze.symbol.Function)1 ColumnIdent (io.crate.metadata.ColumnIdent)1 GeneratedReference (io.crate.metadata.GeneratedReference)1 ReferenceIdent (io.crate.metadata.ReferenceIdent)1 Routing (io.crate.metadata.Routing)1 DocTableInfo (io.crate.metadata.doc.DocTableInfo)1