[SPARK-59672][SQL] Bind SQL parameters when a custom parser is injected - #58932
Open
franciscoabsampaio wants to merge 1 commit into
Open
franciscoabsampaio wants to merge 1 commit into
franciscoabsampaio wants to merge 1 commit into
Conversation
### 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 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
franciscoabsampaio
force-pushed
the
SPARK-parameterized-sql-injected-parser
branch
from
September 20, 2026 09:09
642c22c to
96939fc
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
ParserInterface.parsePlanWithParametershad a default implementation that discarded theParameterContextand calledparsePlan(sqlText). OnlySparkSqlParseroverrides it, so any parser injected throughSparkSessionExtensions.injectParsersilently dropped the parameter values.The default now marks the parsed plan for parameter binding during analysis, using the same
ParameterizedQuerynodes the analyzer already applies in legacy mode, so implementations that only overrideparsePlankeep 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 withUNBOUND_SQL_PARAMETERon any session that setsspark.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, asSparkSqlParserdoes.How was this patch tested?
New test in
SparkSessionExtensionSuitecovering positional and named parameters through an injected parser, unbound markers still being rejected, and legacy mode. It fails without the change withUNBOUND_SQL_PARAMETER. Also ranParametersSuite,LegacyParameterSubstitutionSuite,SparkSessionExtensionSuite,SparkConnectWithSessionExtensionSuiteandSparkConnectPlannerSuite, plus scalastyle.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5