use of io.trino.sql.tree.QuantifiedComparisonExpression.Quantifier in project trino by trinodb.
the class SubqueryPlanner method planQuantifiedComparison.
private PlanBuilder planQuantifiedComparison(PlanBuilder subPlan, Cluster<QuantifiedComparisonExpression> cluster, Analysis.SubqueryAnalysis subqueries) {
// Plan one of the predicates from the cluster
QuantifiedComparisonExpression quantifiedComparison = cluster.getRepresentative();
ComparisonExpression.Operator operator = quantifiedComparison.getOperator();
Quantifier quantifier = quantifiedComparison.getQuantifier();
Expression value = quantifiedComparison.getValue();
SubqueryExpression subquery = (SubqueryExpression) quantifiedComparison.getSubquery();
subPlan = handleSubqueries(subPlan, value, subqueries);
Symbol output = symbolAllocator.newSymbol(quantifiedComparison, BOOLEAN);
Analysis.PredicateCoercions predicateCoercions = analysis.getPredicateCoercions(quantifiedComparison);
switch(operator) {
case EQUAL:
switch(quantifier) {
case ALL:
subPlan = planQuantifiedComparison(subPlan, operator, quantifier, value, subquery, output, predicateCoercions);
return new PlanBuilder(subPlan.getTranslations().withAdditionalMappings(ImmutableMap.of(scopeAwareKey(quantifiedComparison, analysis, subPlan.getScope()), output)), subPlan.getRoot());
case ANY:
case SOME:
// A = ANY B <=> A IN B
subPlan = planInPredicate(subPlan, value, subquery, output, quantifiedComparison, predicateCoercions);
return new PlanBuilder(subPlan.getTranslations().withAdditionalMappings(mapAll(cluster, subPlan.getScope(), output)), subPlan.getRoot());
}
break;
case NOT_EQUAL:
switch(quantifier) {
case ALL:
{
// A <> ALL B <=> !(A IN B)
subPlan = planInPredicate(subPlan, value, subquery, output, quantifiedComparison, predicateCoercions);
return addNegation(subPlan, cluster, output);
}
case ANY:
case SOME:
{
// A <> ANY B <=> min B <> max B || A <> min B <=> !(min B = max B && A = min B) <=> !(A = ALL B)
// "A <> ANY B" is equivalent to "NOT (A = ALL B)" so add a rewrite for the initial quantifiedComparison to notAll
subPlan = planQuantifiedComparison(subPlan, EQUAL, Quantifier.ALL, value, subquery, output, predicateCoercions);
return addNegation(subPlan, cluster, output);
}
}
break;
case LESS_THAN:
case LESS_THAN_OR_EQUAL:
case GREATER_THAN:
case GREATER_THAN_OR_EQUAL:
subPlan = planQuantifiedComparison(subPlan, operator, quantifier, value, subquery, output, predicateCoercions);
return new PlanBuilder(subPlan.getTranslations().withAdditionalMappings(mapAll(cluster, subPlan.getScope(), output)), subPlan.getRoot());
case IS_DISTINCT_FROM:
}
// all cases are checked, so this exception should never be thrown
throw new IllegalArgumentException(format("Unexpected quantified comparison: '%s %s'", operator.getValue(), quantifier));
}
Aggregations