Search in sources :

Example 1 with FilterProjection

use of io.crate.planner.projection.FilterProjection in project crate by crate.

the class GlobalAggregateConsumer method addAggregations.

/**
     * Add aggregation/having/topN projections to the plan.
     * Either directly or by wrapping it into a Merge plan.
     */
static Plan addAggregations(QuerySpec qs, ProjectionBuilder projectionBuilder, SplitPoints splitPoints, Planner.Context plannerContext, Plan plan) {
    ResultDescription resultDescription = plan.resultDescription();
    if (resultDescription.limit() > TopN.NO_LIMIT || resultDescription.orderBy() != null) {
        plan = Merge.ensureOnHandler(plan, plannerContext);
        resultDescription = plan.resultDescription();
    }
    WhereClause where = qs.where();
    if (where != WhereClause.MATCH_ALL) {
        FilterProjection whereFilter = ProjectionBuilder.filterProjection(splitPoints.toCollect(), where);
        plan.addProjection(whereFilter, null, null, null, null);
    }
    List<Projection> postAggregationProjections = createPostAggregationProjections(qs, splitPoints, plannerContext);
    if (ExecutionPhases.executesOnHandler(plannerContext.handlerNode(), resultDescription.nodeIds())) {
        AggregationProjection finalAggregation = projectionBuilder.aggregationProjection(splitPoints.toCollect(), splitPoints.aggregates(), Aggregation.Step.ITER, Aggregation.Step.FINAL, RowGranularity.CLUSTER);
        plan.addProjection(finalAggregation, null, null, splitPoints.aggregates().size(), null);
        for (Projection postAggregationProjection : postAggregationProjections) {
            plan.addProjection(postAggregationProjection, null, null, null, null);
        }
        return plan;
    } else {
        AggregationProjection partialAggregation = projectionBuilder.aggregationProjection(splitPoints.toCollect(), splitPoints.aggregates(), Aggregation.Step.ITER, Aggregation.Step.PARTIAL, RowGranularity.CLUSTER);
        plan.addProjection(partialAggregation, null, null, splitPoints.aggregates().size(), null);
        AggregationProjection finalAggregation = projectionBuilder.aggregationProjection(splitPoints.aggregates(), splitPoints.aggregates(), Aggregation.Step.PARTIAL, Aggregation.Step.FINAL, RowGranularity.CLUSTER);
        postAggregationProjections.add(0, finalAggregation);
    }
    return createMerge(plan, plannerContext, postAggregationProjections);
}
Also used : FilterProjection(io.crate.planner.projection.FilterProjection) FilterProjection(io.crate.planner.projection.FilterProjection) AggregationProjection(io.crate.planner.projection.AggregationProjection) Projection(io.crate.planner.projection.Projection) AggregationProjection(io.crate.planner.projection.AggregationProjection)

Aggregations

AggregationProjection (io.crate.planner.projection.AggregationProjection)1 FilterProjection (io.crate.planner.projection.FilterProjection)1 Projection (io.crate.planner.projection.Projection)1