franciscoabsampaio opened a new pull request, #58932:
URL: https://github.com/apache/spark/pull/58932

   ### What changes were proposed in this pull request?
   
   `ParserInterface.parsePlanWithParameters` had a default implementation that 
discarded the `ParameterContext` and called `parsePlan(sqlText)`. Only 
`SparkSqlParser` overrides it, so any parser injected through 
`SparkSessionExtensions.injectParser` silently dropped the parameter values.
   
   The default now marks the parsed plan for parameter binding during analysis, 
using the same `ParameterizedQuery` nodes the analyzer already applies in 
legacy mode, so implementations that only override `parsePlan` keep working 
with parameterized SQL.
   
   ### Why are the changes needed?
   
   Since SPARK-53573 moved parameter handling into a parser pre-processor, 
`spark.sql(query, args)` fails with `UNBOUND_SQL_PARAMETER` on any session that 
sets `spark.sql.extensions`, for both positional and named parameters, in 
classic Spark and through Spark Connect. Delta Lake and Apache Iceberg both 
inject a parser, so parameterized SQL - the recommended defence against SQL 
injection - is unusable for their users on 4.1.x.
   
   ### Does this PR introduce any user-facing change?
   
   Yes. Parameterized SQL works again on sessions with an injected parser. 
Parameter markers are bound wherever the parser produces a parameter 
expression; parsers that want markers in every position a literal is allowed 
should override `parsePlanWithParameters`, as `SparkSqlParser` does.
   
   ### How was this patch tested?
   
   New test in `SparkSessionExtensionSuite` covering positional and named 
parameters through an injected parser, unbound markers still being rejected, 
and legacy mode. It fails without the change with `UNBOUND_SQL_PARAMETER`. Also 
ran `ParametersSuite`, `LegacyParameterSubstitutionSuite`, 
`SparkSessionExtensionSuite`, `SparkConnectWithSessionExtensionSuite` and 
`SparkConnectPlannerSuite`, plus scalastyle.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Opus 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