dongjoon-hyun opened a new pull request, #60632:
URL: https://github.com/apache/spark/pull/60632

   ### What changes were proposed in this pull request?
   
   `InvokeProcedures` leaves a `Call` unexecuted, for `CheckAnalysis` to 
reject, when an argument holds an aggregate function, a window function or a 
generator. It does so by adding 
`PlanHelper.specialExpressionsInUnsupportedOperator(c).isEmpty` to the guard of 
the `case c: Call`. This is the same check `CheckAnalysis` runs on every 
operator.
   
   ### Why are the changes needed?
   
   `InvokeProcedures` runs in the analyzer `Resolution` batch. It optimizes the 
`Call` and invokes the procedure, so `CheckAnalysis` never sees the arguments. 
The optimizer folds away an invalid argument, and the procedure runs. For 
example:
   
   ```sql
   CALL cat.ns.sum(IF(true OR max(1) > 0, 1, 2), 2)
   CALL cat.ns.sum(IF(true OR row_number() OVER (ORDER BY 1) > 0, 1, 2), 2)
   ```
   
   Both invoke the procedure and return 3, while `EXPLAIN CALL` and `SELECT` 
reject the same expressions with `UNSUPPORTED_EXPR_FOR_OPERATOR`.
   
   Released Spark 4.0.5, 4.1.4, 4.2.1 and 4.3.0 are all affected. In unit 
tests, `spark.sql.planChangeValidation` (enabled by `Utils.isTesting`) makes 
the `CALL` fail with `PLAN_VALIDATION_FAILED_RULE_EXECUTOR` instead. With it 
off, as in production, the procedure runs.
   
   This is the same bypass that apache/spark#60628 fixes for subquery 
arguments, which was kept to subqueries there.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. A `CALL` with an aggregate function, a window function or a generator 
in an argument now fails analysis with the same error as `EXPLAIN CALL` and 
`SELECT`, instead of invoking the procedure when the optimizer folds the 
expression away. Without the fix, such an argument that does not fold fails 
with an error that is not an analysis error. The release probes fail with 
`IllegalArgumentException: args must be foldable` for `CALL cat.ns.sum(max(1), 
2)`. The error is now `UNSUPPORTED_EXPR_FOR_OPERATOR`. A procedure that relied 
on this invalid input being accepted, which is not valid SQL elsewhere, no 
longer runs.
   
   ### How was this patch tested?
   
   Added a test to `ProcedureSuite`. It uses a procedure that throws if 
invoked. It fails without the fix (`PLAN_VALIDATION_FAILED_RULE_EXECUTOR`) and 
passes with it.
   
   ```
   build/sbt 'sql/testOnly *.ProcedureSuite *.StaticProcedureSuite 
*.ParseSqlAnalyzeSuite'
   ```
   
   All 96 tests pass. `build/sbt sql/scalastyle sql/Test/scalastyle` reports no 
errors.
   
   The change merges cleanly with apache/spark#60392 (checked with `git 
merge-file`). With apache/spark#60628, whichever merges second needs a trivial 
rebase: both edit the `plans.logical` import line and the lines of the `case c: 
Call` guard.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Sonnet 5.5
   


-- 
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]

Reply via email to