Check that ApplyNode is used only for non scalar subqueries
LateralJoin is preferred to be used in case of scalar subqueries.
package com.facebook.presto.sql.planner.plan;
import com.facebook.presto.sql.planner.Symbol;
+import com.facebook.presto.sql.tree.ExistsPredicate;
+import com.facebook.presto.sql.tree.Expression;
+import com.facebook.presto.sql.tree.InPredicate;
+import com.facebook.presto.sql.tree.QuantifiedComparisonExpression;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableList;
@@ -55,9 +59,6 @@ public class ApplyNode
* - expression: input_symbol_X < ALL (subquery_symbol_Y)
* - meaning: if input_symbol_X is smaller than all subquery values represented by subquery_symbol_Y
* <p>
- * Example 3:
- * - expression: subquery_symbol_Y
- * - meaning: subquery is scalar (might be enforced), therefore subquery_symbol_Y can be used directly in the rest of the plan
*/
private final Assignments subqueryAssignments;
@@ -76,6 +77,9 @@ public class ApplyNode
requireNonNull(correlation, "correlation is null");
checkArgument(input.getOutputSymbols().containsAll(correlation), "Input does not contain symbols from correlation");
+ checkArgument(
+ subqueryAssignments.getExpressions().stream().allMatch(ApplyNode::isSupportedSubqueryExpression),
+ "Unexpected expression used for subquery expression");
this.input = input;
this.subquery = subquery;
@@ -83,6 +87,13 @@ public class ApplyNode
this.correlation = ImmutableList.copyOf(correlation);
}
+ private static boolean isSupportedSubqueryExpression(Expression expression)
+ {
+ return expression instanceof InPredicate ||
+ expression instanceof ExistsPredicate ||
+ expression instanceof QuantifiedComparisonExpression;
+ }
+
@JsonProperty("input")
public PlanNode getInput()
{
