Search in sources :

Example 1 with PlanAndMappings

use of io.trino.sql.planner.QueryPlanner.PlanAndMappings in project trino by trinodb.

the class SubqueryPlanner method planQuantifiedComparison.

private PlanBuilder planQuantifiedComparison(PlanBuilder subPlan, ComparisonExpression.Operator operator, Quantifier quantifier, Expression value, Expression subquery, Symbol assignment, Analysis.PredicateCoercions predicateCoercions) {
    PlanAndMappings subqueryPlan = planSubquery(subquery, predicateCoercions.getSubqueryCoercion(), subPlan.getTranslations());
    PlanAndMappings valuePlan = planValue(subPlan, value, predicateCoercions.getValueType(), predicateCoercions.getValueCoercion());
    return new PlanBuilder(valuePlan.getSubPlan().getTranslations(), new ApplyNode(idAllocator.getNextId(), valuePlan.getSubPlan().getRoot(), subqueryPlan.getSubPlan().getRoot(), Assignments.of(assignment, new QuantifiedComparisonExpression(operator, quantifier, valuePlan.get(value).toSymbolReference(), subqueryPlan.get(subquery).toSymbolReference())), valuePlan.getSubPlan().getRoot().getOutputSymbols(), subquery));
}
Also used : ApplyNode(io.trino.sql.planner.plan.ApplyNode) PlanAndMappings(io.trino.sql.planner.QueryPlanner.PlanAndMappings) QuantifiedComparisonExpression(io.trino.sql.tree.QuantifiedComparisonExpression) PlanBuilder.newPlanBuilder(io.trino.sql.planner.PlanBuilder.newPlanBuilder)

Example 2 with PlanAndMappings

use of io.trino.sql.planner.QueryPlanner.PlanAndMappings in project trino by trinodb.

the class SubqueryPlanner method coerceIfNecessary.

private PlanAndMappings coerceIfNecessary(PlanBuilder subPlan, Symbol symbol, Expression value, Type type, Optional<? extends Type> coercion) {
    Symbol coerced = symbol;
    if (coercion.isPresent()) {
        coerced = symbolAllocator.newSymbol(value, coercion.get());
        Assignments assignments = Assignments.builder().putIdentities(subPlan.getRoot().getOutputSymbols()).put(coerced, new Cast(symbol.toSymbolReference(), toSqlType(coercion.get()), false, typeCoercion.isTypeOnlyCoercion(type, coercion.get()))).build();
        subPlan = subPlan.withNewRoot(new ProjectNode(idAllocator.getNextId(), subPlan.getRoot(), assignments));
    }
    return new PlanAndMappings(subPlan, ImmutableMap.of(NodeRef.of(value), coerced));
}
Also used : Cast(io.trino.sql.tree.Cast) Assignments(io.trino.sql.planner.plan.Assignments) ProjectNode(io.trino.sql.planner.plan.ProjectNode) PlanAndMappings(io.trino.sql.planner.QueryPlanner.PlanAndMappings)

Example 3 with PlanAndMappings

use of io.trino.sql.planner.QueryPlanner.PlanAndMappings in project trino by trinodb.

the class SubqueryPlanner method planInPredicate.

/**
 * Plans a correlated subquery for value IN (subQuery)
 *
 * @param originalExpression the original expression from which the IN predicate was derived. Used for subsequent translations.
 */
private PlanBuilder planInPredicate(PlanBuilder subPlan, Expression value, SubqueryExpression subquery, Symbol output, Expression originalExpression, Analysis.PredicateCoercions predicateCoercions) {
    PlanAndMappings subqueryPlan = planSubquery(subquery, predicateCoercions.getSubqueryCoercion(), subPlan.getTranslations());
    PlanAndMappings valuePlan = planValue(subPlan, value, predicateCoercions.getValueType(), predicateCoercions.getValueCoercion());
    return new PlanBuilder(valuePlan.getSubPlan().getTranslations(), new ApplyNode(idAllocator.getNextId(), valuePlan.getSubPlan().getRoot(), subqueryPlan.getSubPlan().getRoot(), Assignments.of(output, new InPredicate(valuePlan.get(value).toSymbolReference(), subqueryPlan.get(subquery).toSymbolReference())), valuePlan.getSubPlan().getRoot().getOutputSymbols(), originalExpression));
}
Also used : ApplyNode(io.trino.sql.planner.plan.ApplyNode) PlanAndMappings(io.trino.sql.planner.QueryPlanner.PlanAndMappings) InPredicate(io.trino.sql.tree.InPredicate) PlanBuilder.newPlanBuilder(io.trino.sql.planner.PlanBuilder.newPlanBuilder)

Aggregations

PlanAndMappings (io.trino.sql.planner.QueryPlanner.PlanAndMappings)3 PlanBuilder.newPlanBuilder (io.trino.sql.planner.PlanBuilder.newPlanBuilder)2 ApplyNode (io.trino.sql.planner.plan.ApplyNode)2 Assignments (io.trino.sql.planner.plan.Assignments)1 ProjectNode (io.trino.sql.planner.plan.ProjectNode)1 Cast (io.trino.sql.tree.Cast)1 InPredicate (io.trino.sql.tree.InPredicate)1 QuantifiedComparisonExpression (io.trino.sql.tree.QuantifiedComparisonExpression)1