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));
}
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)));
}
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)));
}
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);
}
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));
}
Aggregations