Uh oh!
There was an error while loading. Please reload this page.
[SPARK-58933][SQL] Simplify and fix parsed INSERT target handling - #58378
Closed
cloud-fan wants to merge 3 commits into
Closed
[SPARK-58933][SQL] Simplify and fix parsed INSERT target handling#58378cloud-fan wants to merge 3 commits into
cloud-fan wants to merge 3 commits into
Conversation
zhengruifeng
approved these changes
Aug 28, 2026
cloud-fan
commented
Aug 28, 2026
ContributorAuthor
thanks for review, merging to master/4.x/4.3/4.2 |
cloud-fan added a commit
that referenced
this pull request
Aug 28, 2026
### What changes were proposed in this pull request? This follow-up to #58204 simplifies and corrects parsed INSERT target handling: * Make the SQL parser always produce `UnresolvedInsert` for table-target INSERT statements. A static target is represented by `UnresolvedInsertTarget`, while a dynamic `IDENTIFIER` expression remains in `PlanWithUnresolvedIdentifier`. The analyzer lowers either form to `InsertIntoStatement` once the target identifier is ready for relation resolution. * Update parser-oriented consumers, including SQL statement classification, `parse_sql` lineage collection, and pipeline flow registration, to handle the single parsed INSERT shape. `InsertIntoStatement` handling remains where plans can be created programmatically or have already been lowered by analysis. * Scope the `parse_sql` CTE-shadow exemption specifically to `UnresolvedInsertTarget`. DELETE, UPDATE, and MERGE targets continue to follow CTE substitution semantics. * Run early dynamic INSERT target resolution inside the analysis planning tracker and report its failures through `QueryPlanningTracker.setAnalysisFailed`. ### Why are the changes needed? The parser previously produced `InsertIntoStatement` for static targets and `UnresolvedInsert` for dynamic targets. Parser consumers therefore had to understand both shapes even though `UnresolvedInsert` is only an intermediate node and is lowered immediately after its target is ready. Using one parsed representation makes that boundary explicit and removes duplicated matching logic. The target-role exemption added by #58204 was also broader than required. A CTE-shadowed DELETE, UPDATE, or MERGE target could be reported as a catalog target even though CTE substitution replaces that relation. In addition, early dynamic target resolution was absent from analysis timing and failure reporting. ### Does this PR introduce _any_ user-facing change? Yes, within unreleased master only. `parse_sql` no longer reports CTE-shadowed DELETE, UPDATE, or MERGE targets as catalog target-table references. There is no change relative to a released Spark version. ### How was this patch tested? Added and updated regression coverage, then ran: ```bash build/sbt \ "catalyst/testOnly org.apache.spark.sql.catalyst.parser.PlanParserSuite org.apache.spark.sql.catalyst.parser.DDLParserSuite org.apache.spark.sql.catalyst.parser.IdentifierClauseParserSuite" \ "sql/testOnly org.apache.spark.sql.ParametersSuite org.apache.spark.sql.catalyst.parser.ParseSqlResultSuite org.apache.spark.sql.execution.QueryExecutionSuite org.apache.spark.sql.execution.command.v2.CreateFlowCommandSuite" \ pipelines/compile ``` All 284 Catalyst tests and 204 SQL tests passed, and the pipelines module compiled successfully. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: OpenAI Codex (GPT-5) Closes#58378 from cloud-fan/fix-identifier-dml-followup. Authored-by: Wenchen Fan <wenchen@databricks.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com> (cherry picked from commit 900b44e) Signed-off-by: Wenchen Fan <wenchen@databricks.com>
cloud-fan
commented
Aug 28, 2026
ContributorAuthor
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 freeto 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?
This follow-up to #58204 simplifies and corrects parsed INSERT target handling:
UnresolvedInsertfor table-target INSERT statements. Astatic target is represented by
UnresolvedInsertTarget, while a dynamicIDENTIFIERexpression remains in
PlanWithUnresolvedIdentifier. The analyzer lowers either form toInsertIntoStatementonce the target identifier is ready for relation resolution.parse_sqllineagecollection, and pipeline flow registration, to handle the single parsed INSERT shape.
InsertIntoStatementhandling remains where plans can be created programmatically or havealready been lowered by analysis.
parse_sqlCTE-shadow exemption specifically toUnresolvedInsertTarget. DELETE,UPDATE, and MERGE targets continue to follow CTE substitution semantics.
failures through
QueryPlanningTracker.setAnalysisFailed.Why are the changes needed?
The parser previously produced
InsertIntoStatementfor static targets andUnresolvedInsertfordynamic targets. Parser consumers therefore had to understand both shapes even though
UnresolvedInsertis only an intermediate node and is lowered immediately after its target isready. Using one parsed representation makes that boundary explicit and removes duplicated
matching logic.
The target-role exemption added by #58204 was also broader than required. A CTE-shadowed DELETE,
UPDATE, or MERGE target could be reported as a catalog target even though CTE substitution replaces
that relation. In addition, early dynamic target resolution was absent from analysis timing and
failure reporting.
Does this PR introduce any user-facing change?
Yes, within unreleased master only.
parse_sqlno longer reports CTE-shadowed DELETE, UPDATE, orMERGE targets as catalog target-table references. There is no change relative to a released Spark
version.
How was this patch tested?
Added and updated regression coverage, then ran:
All 284 Catalyst tests and 204 SQL tests passed, and the pipelines module compiled successfully.
Was this patch authored or co-authored using generative AI tooling?
Generated-by: OpenAI Codex (GPT-5)