Search in sources :

Example 1 with DecorrelatedNode

use of io.prestosql.sql.planner.optimizations.PlanNodeDecorrelator.DecorrelatedNode in project hetu-core by openlookeng.

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.getLookup());
    Optional<DecorrelatedNode> decorrelatedNodeOptional = planNodeDecorrelator.decorrelateFilters(subquery, lateralJoinNode.getCorrelation());
    return decorrelatedNodeOptional.map(decorrelatedNode -> {
        Expression joinFilter = combineConjuncts(decorrelatedNode.getCorrelatedPredicates().orElse(TRUE_LITERAL), lateralJoinNode.getFilter());
        return Result.ofPlanNode(new JoinNode(context.getIdAllocator().getNextId(), lateralJoinNode.getType().toJoinNodeType(), lateralJoinNode.getInput(), decorrelatedNode.getNode(), ImmutableList.of(), lateralJoinNode.getOutputSymbols(), joinFilter.equals(TRUE_LITERAL) ? Optional.empty() : Optional.of(castToRowExpression(joinFilter)), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of()));
    }).orElseGet(Result::empty);
}
Also used : Patterns.lateralJoin(io.prestosql.sql.planner.plan.Patterns.lateralJoin) LateralJoin.correlation(io.prestosql.sql.planner.plan.Patterns.LateralJoin.correlation) ExpressionUtils.combineConjuncts(io.prestosql.sql.ExpressionUtils.combineConjuncts) ImmutableMap(com.google.common.collect.ImmutableMap) Rule(io.prestosql.sql.planner.iterative.Rule) Pattern.nonEmpty(io.prestosql.matching.Pattern.nonEmpty) PlanNodeDecorrelator(io.prestosql.sql.planner.optimizations.PlanNodeDecorrelator) LateralJoinNode(io.prestosql.sql.planner.plan.LateralJoinNode) Pattern(io.prestosql.matching.Pattern) PlanNode(io.prestosql.spi.plan.PlanNode) TRUE_LITERAL(io.prestosql.sql.tree.BooleanLiteral.TRUE_LITERAL) Captures(io.prestosql.matching.Captures) ImmutableList(com.google.common.collect.ImmutableList) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) Optional(java.util.Optional) DecorrelatedNode(io.prestosql.sql.planner.optimizations.PlanNodeDecorrelator.DecorrelatedNode) Expression(io.prestosql.sql.tree.Expression) JoinNode(io.prestosql.spi.plan.JoinNode) PlanNodeDecorrelator(io.prestosql.sql.planner.optimizations.PlanNodeDecorrelator) PlanNode(io.prestosql.spi.plan.PlanNode) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) Expression(io.prestosql.sql.tree.Expression) LateralJoinNode(io.prestosql.sql.planner.plan.LateralJoinNode) JoinNode(io.prestosql.spi.plan.JoinNode) DecorrelatedNode(io.prestosql.sql.planner.optimizations.PlanNodeDecorrelator.DecorrelatedNode)

Example 2 with DecorrelatedNode

use of io.prestosql.sql.planner.optimizations.PlanNodeDecorrelator.DecorrelatedNode in project hetu-core by openlookeng.

the class ScalarAggregationToJoinRewriter method rewriteScalarAggregation.

public PlanNode rewriteScalarAggregation(LateralJoinNode lateralJoinNode, AggregationNode aggregation) {
    List<Symbol> correlation = lateralJoinNode.getCorrelation();
    Optional<DecorrelatedNode> source = planNodeDecorrelator.decorrelateFilters(lookup.resolve(aggregation.getSource()), correlation);
    if (!source.isPresent()) {
        return lateralJoinNode;
    }
    Symbol nonNull = planSymbolAllocator.newSymbol("non_null", BooleanType.BOOLEAN);
    Assignments scalarAggregationSourceAssignments = Assignments.builder().putAll(AssignmentUtils.identityAsSymbolReferences(source.get().getNode().getOutputSymbols())).put(nonNull, castToRowExpression(TRUE_LITERAL)).build();
    ProjectNode scalarAggregationSourceWithNonNullableSymbol = new ProjectNode(idAllocator.getNextId(), source.get().getNode(), scalarAggregationSourceAssignments);
    return rewriteScalarAggregation(lateralJoinNode, aggregation, scalarAggregationSourceWithNonNullableSymbol, source.get().getCorrelatedPredicates(), nonNull);
}
Also used : Symbol(io.prestosql.spi.plan.Symbol) Assignments(io.prestosql.spi.plan.Assignments) ProjectNode(io.prestosql.spi.plan.ProjectNode) DecorrelatedNode(io.prestosql.sql.planner.optimizations.PlanNodeDecorrelator.DecorrelatedNode)

Aggregations

DecorrelatedNode (io.prestosql.sql.planner.optimizations.PlanNodeDecorrelator.DecorrelatedNode)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Captures (io.prestosql.matching.Captures)1 Pattern (io.prestosql.matching.Pattern)1 Pattern.nonEmpty (io.prestosql.matching.Pattern.nonEmpty)1 Assignments (io.prestosql.spi.plan.Assignments)1 JoinNode (io.prestosql.spi.plan.JoinNode)1 PlanNode (io.prestosql.spi.plan.PlanNode)1 ProjectNode (io.prestosql.spi.plan.ProjectNode)1 Symbol (io.prestosql.spi.plan.Symbol)1 ExpressionUtils.combineConjuncts (io.prestosql.sql.ExpressionUtils.combineConjuncts)1 Rule (io.prestosql.sql.planner.iterative.Rule)1 PlanNodeDecorrelator (io.prestosql.sql.planner.optimizations.PlanNodeDecorrelator)1 LateralJoinNode (io.prestosql.sql.planner.plan.LateralJoinNode)1 LateralJoin.correlation (io.prestosql.sql.planner.plan.Patterns.LateralJoin.correlation)1 Patterns.lateralJoin (io.prestosql.sql.planner.plan.Patterns.lateralJoin)1 OriginalExpressionUtils.castToRowExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression)1 TRUE_LITERAL (io.prestosql.sql.tree.BooleanLiteral.TRUE_LITERAL)1 Expression (io.prestosql.sql.tree.Expression)1