Search in sources :

Example 1 with SplitPoints

use of io.crate.planner.projection.builder.SplitPoints 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)

Aggregations

Collect (io.crate.planner.node.dql.Collect)1 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)1 AggregationProjection (io.crate.planner.projection.AggregationProjection)1 FilterProjection (io.crate.planner.projection.FilterProjection)1 Projection (io.crate.planner.projection.Projection)1 ProjectionBuilder (io.crate.planner.projection.builder.ProjectionBuilder)1 SplitPoints (io.crate.planner.projection.builder.SplitPoints)1