Search in sources :

Example 1 with ScalarAggregationToJoinRewriter

use of com.facebook.presto.sql.planner.optimizations.ScalarAggregationToJoinRewriter in project presto by prestodb.

the class TransformCorrelatedScalarAggregationToJoin method apply.

@Override
public Result apply(LateralJoinNode lateralJoinNode, Captures captures, Context context) {
    PlanNode subquery = lateralJoinNode.getSubquery();
    if (!isScalar(subquery, context.getLookup())) {
        return Result.empty();
    }
    Optional<AggregationNode> aggregation = findAggregation(subquery, context.getLookup());
    if (!(aggregation.isPresent() && aggregation.get().getGroupingKeys().isEmpty())) {
        return Result.empty();
    }
    ScalarAggregationToJoinRewriter rewriter = new ScalarAggregationToJoinRewriter(functionAndTypeManager, context.getVariableAllocator(), context.getIdAllocator(), context.getLookup());
    PlanNode rewrittenNode = rewriter.rewriteScalarAggregation(lateralJoinNode, aggregation.get());
    if (rewrittenNode instanceof LateralJoinNode) {
        return Result.empty();
    }
    return Result.ofPlanNode(rewrittenNode);
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) LateralJoinNode(com.facebook.presto.sql.planner.plan.LateralJoinNode) ScalarAggregationToJoinRewriter(com.facebook.presto.sql.planner.optimizations.ScalarAggregationToJoinRewriter) AggregationNode(com.facebook.presto.spi.plan.AggregationNode)

Aggregations

AggregationNode (com.facebook.presto.spi.plan.AggregationNode)1 PlanNode (com.facebook.presto.spi.plan.PlanNode)1 ScalarAggregationToJoinRewriter (com.facebook.presto.sql.planner.optimizations.ScalarAggregationToJoinRewriter)1 LateralJoinNode (com.facebook.presto.sql.planner.plan.LateralJoinNode)1