forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-50403][SQL] Fix parameterized
EXECUTE IMMEDIATE
### What changes were proposed in this pull request? 1. Remove the assert of single parameterized query because it restricts parameterization of `EXECUTE IMMEDIATE`. The assert checks that only single node of the type `ParameterizedQuery` presents in a query, but `EXECUTE IMMEDIATE` adds one `ParameterizedQuery` + `sql()` adds another `ParameterizedQuery`. So, this case is prohibited by the assert though it is a valid use case from user's perspective. 2. Modify parameters binding: stop the bind procedure when face to another parameterized query. For example, the sql text passed to `spark.sql()` contains `EXECUTE IMMEDIATE`, and `sql()` parameters don't affect on the sql query string in `EXECUTE IMMEDIATE`. 3. Allow parameters in `EXECUTE IMMEDIATE` variables. ### Why are the changes needed? Before the changes, the following query fails with the internal error: ```scala scala> spark.sql("execute immediate 'select ?' using 1", Map("param1" -> "1")) org.apache.spark.SparkException: [INTERNAL_ERROR] The Spark SQL phase analysis failed with an internal error. You hit a bug in Spark or the Spark plugins you use. Please, report this bug to the corresponding communities or vendors, and provide the full stack trace. SQLSTATE: XX000 ``` ### Does this PR introduce _any_ user-facing change? Yes, the query above returns proper results instead of the internal error: ```scala scala> spark.sql("execute immediate 'select ?' using 1", Map("param1" -> "1")) val res2: org.apache.spark.sql.DataFrame = [1: int] ``` ### How was this patch tested? By running the new test: ``` $ build/sbt "sql/test:testOnly org.apache.spark.sql.ParametersSuite" ``` ### Was this patch authored or co-authored using generative AI tooling? No. Closes apache#49442 from MaxGekk/fix-params-execute-immediate. Authored-by: Max Gekk <[email protected]> Signed-off-by: Max Gekk <[email protected]>
- Loading branch information
Showing
3 changed files
with
49 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters