Search in sources :

Example 6 with ApplyNode

use of io.trino.sql.planner.plan.ApplyNode in project trino by trinodb.

the class PruneApplyCorrelation method apply.

@Override
public Result apply(ApplyNode applyNode, Captures captures, Context context) {
    Set<Symbol> subquerySymbols = extractUnique(applyNode.getSubquery(), context.getLookup());
    List<Symbol> newCorrelation = applyNode.getCorrelation().stream().filter(subquerySymbols::contains).collect(toImmutableList());
    if (newCorrelation.size() < applyNode.getCorrelation().size()) {
        return Result.ofPlanNode(new ApplyNode(applyNode.getId(), applyNode.getInput(), applyNode.getSubquery(), applyNode.getSubqueryAssignments(), newCorrelation, applyNode.getOriginSubquery()));
    }
    return Result.empty();
}
Also used : Symbol(io.trino.sql.planner.Symbol) ApplyNode(io.trino.sql.planner.plan.ApplyNode)

Example 7 with ApplyNode

use of io.trino.sql.planner.plan.ApplyNode in project trino by trinodb.

the class CheckSubqueryNodesAreRewritten method optimize.

@Override
public PlanNode optimize(PlanNode plan, Session session, TypeProvider types, SymbolAllocator symbolAllocator, PlanNodeIdAllocator idAllocator, WarningCollector warningCollector) {
    searchFrom(plan).where(ApplyNode.class::isInstance).findFirst().ifPresent(node -> {
        ApplyNode applyNode = (ApplyNode) node;
        throw error(applyNode.getCorrelation(), applyNode.getOriginSubquery());
    });
    searchFrom(plan).where(CorrelatedJoinNode.class::isInstance).findFirst().ifPresent(node -> {
        CorrelatedJoinNode correlatedJoinNode = (CorrelatedJoinNode) node;
        throw error(correlatedJoinNode.getCorrelation(), correlatedJoinNode.getOriginSubquery());
    });
    return plan;
}
Also used : CorrelatedJoinNode(io.trino.sql.planner.plan.CorrelatedJoinNode) ApplyNode(io.trino.sql.planner.plan.ApplyNode)

Aggregations

ApplyNode (io.trino.sql.planner.plan.ApplyNode)7 PlanBuilder.newPlanBuilder (io.trino.sql.planner.PlanBuilder.newPlanBuilder)3 Symbol (io.trino.sql.planner.Symbol)3 Expression (io.trino.sql.tree.Expression)3 QuantifiedComparisonExpression (io.trino.sql.tree.QuantifiedComparisonExpression)3 PlanAndMappings (io.trino.sql.planner.QueryPlanner.PlanAndMappings)2 Assignments (io.trino.sql.planner.plan.Assignments)2 InPredicate (io.trino.sql.tree.InPredicate)2 Map (java.util.Map)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Captures (io.trino.matching.Captures)1 Pattern (io.trino.matching.Pattern)1 RowType (io.trino.spi.type.RowType)1 Type (io.trino.spi.type.Type)1 TypeAnalyzer (io.trino.sql.planner.TypeAnalyzer)1 Rule (io.trino.sql.planner.iterative.Rule)1 Assignment (io.trino.sql.planner.plan.Assignments.Assignment)1 CorrelatedJoinNode (io.trino.sql.planner.plan.CorrelatedJoinNode)1 Patterns.applyNode (io.trino.sql.planner.plan.Patterns.applyNode)1 PlanNode (io.trino.sql.planner.plan.PlanNode)1