Search in sources :

Example 1 with DecorrelatedNode

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

the class ScalarAggregationToJoinRewriter method rewriteScalarAggregation.

public PlanNode rewriteScalarAggregation(LateralJoinNode lateralJoinNode, AggregationNode aggregation) {
    List<VariableReferenceExpression> correlation = lateralJoinNode.getCorrelation();
    Optional<DecorrelatedNode> source = planNodeDecorrelator.decorrelateFilters(lookup.resolve(aggregation.getSource()), correlation);
    if (!source.isPresent()) {
        return lateralJoinNode;
    }
    VariableReferenceExpression nonNull = variableAllocator.newVariable("non_null", BooleanType.BOOLEAN);
    Assignments scalarAggregationSourceAssignments = Assignments.builder().putAll(identitiesAsSymbolReferences(source.get().getNode().getOutputVariables())).put(nonNull, castToRowExpression(TRUE_LITERAL)).build();
    ProjectNode scalarAggregationSourceWithNonNullableVariable = new ProjectNode(idAllocator.getNextId(), source.get().getNode(), scalarAggregationSourceAssignments);
    return rewriteScalarAggregation(lateralJoinNode, aggregation, scalarAggregationSourceWithNonNullableVariable, source.get().getCorrelatedPredicates(), nonNull);
}
Also used : VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Assignments(com.facebook.presto.spi.plan.Assignments) ProjectNode(com.facebook.presto.spi.plan.ProjectNode) DecorrelatedNode(com.facebook.presto.sql.planner.optimizations.PlanNodeDecorrelator.DecorrelatedNode)

Example 2 with DecorrelatedNode

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

the class TransformCorrelatedLateralJoinToJoin method apply.

@Override
public Result apply(LateralJoinNode lateralJoinNode, Captures captures, Context context) {
    PlanNode subquery = lateralJoinNode.getSubquery();
    PlanNodeDecorrelator planNodeDecorrelator = new PlanNodeDecorrelator(context.getIdAllocator(), context.getVariableAllocator(), context.getLookup());
    Optional<DecorrelatedNode> decorrelatedNodeOptional = planNodeDecorrelator.decorrelateFilters(subquery, lateralJoinNode.getCorrelation());
    return decorrelatedNodeOptional.map(decorrelatedNode -> Result.ofPlanNode(new JoinNode(lateralJoinNode.getSourceLocation(), context.getIdAllocator().getNextId(), lateralJoinNode.getType().toJoinNodeType(), lateralJoinNode.getInput(), decorrelatedNode.getNode(), ImmutableList.of(), lateralJoinNode.getOutputVariables(), decorrelatedNode.getCorrelatedPredicates().map(OriginalExpressionUtils::castToRowExpression), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of()))).orElseGet(Result::empty);
}
Also used : JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) PlanNodeDecorrelator(com.facebook.presto.sql.planner.optimizations.PlanNodeDecorrelator) DecorrelatedNode(com.facebook.presto.sql.planner.optimizations.PlanNodeDecorrelator.DecorrelatedNode) LateralJoinNode(com.facebook.presto.sql.planner.plan.LateralJoinNode) ImmutableMap(com.google.common.collect.ImmutableMap) OriginalExpressionUtils(com.facebook.presto.sql.relational.OriginalExpressionUtils) Rule(com.facebook.presto.sql.planner.iterative.Rule) Captures(com.facebook.presto.matching.Captures) Pattern.nonEmpty(com.facebook.presto.matching.Pattern.nonEmpty) Patterns.lateralJoin(com.facebook.presto.sql.planner.plan.Patterns.lateralJoin) LateralJoin.correlation(com.facebook.presto.sql.planner.plan.Patterns.LateralJoin.correlation) Pattern(com.facebook.presto.matching.Pattern) PlanNode(com.facebook.presto.spi.plan.PlanNode) ImmutableList(com.google.common.collect.ImmutableList) Optional(java.util.Optional) PlanNodeDecorrelator(com.facebook.presto.sql.planner.optimizations.PlanNodeDecorrelator) PlanNode(com.facebook.presto.spi.plan.PlanNode) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) LateralJoinNode(com.facebook.presto.sql.planner.plan.LateralJoinNode) DecorrelatedNode(com.facebook.presto.sql.planner.optimizations.PlanNodeDecorrelator.DecorrelatedNode) OriginalExpressionUtils(com.facebook.presto.sql.relational.OriginalExpressionUtils)

Aggregations

DecorrelatedNode (com.facebook.presto.sql.planner.optimizations.PlanNodeDecorrelator.DecorrelatedNode)2 Captures (com.facebook.presto.matching.Captures)1 Pattern (com.facebook.presto.matching.Pattern)1 Pattern.nonEmpty (com.facebook.presto.matching.Pattern.nonEmpty)1 Assignments (com.facebook.presto.spi.plan.Assignments)1 PlanNode (com.facebook.presto.spi.plan.PlanNode)1 ProjectNode (com.facebook.presto.spi.plan.ProjectNode)1 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)1 Rule (com.facebook.presto.sql.planner.iterative.Rule)1 PlanNodeDecorrelator (com.facebook.presto.sql.planner.optimizations.PlanNodeDecorrelator)1 JoinNode (com.facebook.presto.sql.planner.plan.JoinNode)1 LateralJoinNode (com.facebook.presto.sql.planner.plan.LateralJoinNode)1 LateralJoin.correlation (com.facebook.presto.sql.planner.plan.Patterns.LateralJoin.correlation)1 Patterns.lateralJoin (com.facebook.presto.sql.planner.plan.Patterns.lateralJoin)1 OriginalExpressionUtils (com.facebook.presto.sql.relational.OriginalExpressionUtils)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Optional (java.util.Optional)1