viirya commented on code in PR #60460:
URL: https://github.com/apache/spark/pull/60460#discussion_r4568271981
##########
sql/core/src/main/scala/org/apache/spark/sql/catalyst/analysis/InvokeProcedures.scala:
##########
@@ -39,7 +39,10 @@ class InvokeProcedures(session: SparkSession) extends
Rule[LogicalPlan] {
}
private def invokeProcedures(plan: LogicalPlan): LogicalPlan = plan
resolveOperators {
- case c: Call if c.resolved && c.bound && c.execute &&
c.checkArgTypes().isSuccess =>
+ // A CALL with an IN or correlated EXISTS subquery in an argument is left
for CheckAnalysis to
+ // reject. The optimizer would rewrite the subquery into a join under the
`Call`.
+ case c: Call if c.resolved && c.bound && c.execute &&
c.checkArgTypes().isSuccess &&
+ !c.args.exists(SubqueryExpression.hasInOrCorrelatedExistsSubquery) =>
Review Comment:
This checks the analyzed arguments, but an IN subquery can also reach
`Call.args` during optimization. With this PR applied, the following still
fails with `INTERNAL_ERROR`:
```sql
CALL cat.ns.sum(1, (SELECT CAST(1 IN (SELECT 1) AS INT)))
```
`OptimizeOneRowRelationSubquery` inlines the uncorrelated one-row subquery,
which moves the `ListQuery` into the arguments. After that,
`RewritePredicateSubquery` rewrites the `Call` as in the top-level case.
CheckAnalysis accepts this statement because the IN is inside a `Project`.
Could `RewritePredicateSubquery` also leave a `Call` alone, the way
`RewriteWithExpression` already does? I tried adding `case c: Call => c` before
the `UnaryNode` case. The query above then fails with `NON_FOLDABLE_ARGUMENT`,
the same error as `(SELECT count(*) FROM range(3) WHERE id IN (SELECT 1))::INT`
already gets on master. Keeping this guard would still give the top-level case
the same error as `EXPLAIN CALL`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]