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

   ### What changes were proposed in this pull request?
   
   This PR aims to fix `CALL` to fail with an `AnalysisException` instead of 
`IllegalArgumentException` when an argument does not fold to a constant even 
after optimization.
   
   `InvokeProcedures` evaluates every argument once before it calls the 
procedure, and it guarded this with `require(args.forall(_.foldable), "args 
must be foldable")`. However, an argument can pass binding, type coercion and 
`checkArgTypes`, and still remain non-foldable after optimization, e.g. a 
nondeterministic expression like `rand()` or `uuid()`, or a scalar subquery 
that the optimizer cannot inline.
   
   To fix it, `InvokeProcedures` now throws the existing 
`NON_FOLDABLE_ARGUMENT` error (SQLSTATE `42K08`) with the name and type of the 
parameter of the first non-foldable argument.
   
   ### Why are the changes needed?
   
   Since Apache Spark 4.0.0 
([v4.0.0](https://github.com/apache/spark/releases/tag/v4.0.0), 2025-05-19), 
such a `CALL` fails with an `IllegalArgumentException` without an error 
condition. `QueryExecution.isInternalError` does not wrap 
`IllegalArgumentException`, so users see the raw exception.
   
   ```sql
   -- `sum(in1 INT, in2 INT)` procedure of `ProcedureSuite`
   CALL cat.ns.sum(1, CAST(rand() * 10 AS INT));
   ```
   
   **BEFORE**
   
   ```
   java.lang.IllegalArgumentException: requirement failed: args must be foldable
   ```
   
   **AFTER**
   
   ```
   org.apache.spark.sql.AnalysisException: [NON_FOLDABLE_ARGUMENT] The function 
`sum` requires the parameter `in2` to be a foldable expression of the type 
"INT", but the actual argument is a non-foldable. SQLSTATE: 42K08
   ```
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. A `CALL` with a non-foldable argument now fails with 
`AnalysisException` (`NON_FOLDABLE_ARGUMENT`) instead of 
`IllegalArgumentException`. A `CALL` with foldable arguments is not affected.
   
   ### How was this patch tested?
   
   Pass the CIs with the newly added test case, which fails without this fix.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Opus 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