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

   ### What changes were proposed in this pull request?
   
   This PR aims to fix `EXPLAIN` to not invoke a stored procedure when the 
explained statement is `EXECUTE IMMEDIATE` whose SQL string is `CALL`.
   
   `ExplainCommand.run` stages only the `Call` nodes in the explained plan 
(`stageForAnalysis`). However, `EXECUTE IMMEDIATE` parses and analyzes its SQL 
string while the explained plan is analyzed, and the `InvokeProcedures` rule 
invokes the inner `CALL` there. This PR wraps the analysis and planning in 
`ExplainCommand.run` with `InvokeProcedures.withoutInvocation`, which the 
`parse_sql` ANALYZE mode already uses to analyze statements without running 
`CALL`.
   
   ### Why are the changes needed?
   
   `EXPLAIN` should show a plan without running it. `EXPLAIN EXECUTE IMMEDIATE` 
no longer runs command payloads like `DROP TABLE` or `INSERT` (SPARK-59689), 
but it still runs `CALL`.
   
   **BEFORE**
   
   ```
   spark-sql (default)> EXPLAIN EXECUTE IMMEDIATE 'CALL cat.ns.proc(1)';
   == Physical Plan ==
   CommandResult <empty>
      +- LocalTableScan <empty>
   ```
   
   The procedure is invoked once.
   
   **AFTER**
   
   ```
   spark-sql (default)> EXPLAIN EXECUTE IMMEDIATE 'CALL cat.ns.proc(1)';
   == Physical Plan ==
   Call cat.ns.proc(1)
   ```
   
   The procedure is not invoked.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. `EXPLAIN EXECUTE IMMEDIATE 'CALL ...'` no longer invokes the procedure. 
The issue exists since 
[v4.0.0](https://github.com/apache/spark/releases/tag/v4.0.0) (2025-05-19) 
through [v4.3.0](https://github.com/apache/spark/releases/tag/v4.3.0) 
(2026-10-27).
   
   Since the result columns of a procedure are known only after it runs, 
`EXPLAIN EXECUTE IMMEDIATE 'CALL ...' INTO v` now reports 
`ASSIGNMENT_ARITY_MISMATCH` in its output instead of invoking the procedure.
   
   ### How was this patch tested?
   
   Pass the CIs with the newly added test case in `ProcedureSuite`.
   
   ### 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