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));
}
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));
}
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));
}
Aggregations