← Back to Pull requests

[SPARK-58933][SQL][FOLLOWUP] Keep InsertIntoStatement as the parsed plan for static INSERT targets #59750

Closed
unknown closed this pull request without merging on Oct 24, 2026 09:26 UTC
View on GitHub
unknown unknown commented on Oct 23, 2026 13:18 UTC
Author

What changes were proposed in this pull request?

This is a follow-up to #58378 that partially reverts it. The parser again produces InsertIntoStatement for static and literal IDENTIFIER('...') INSERT targets. The temporary UnresolvedInsert node is used only for a non-literal IDENTIFIER(expr) target, as introduced by #58204. Parser-level consumers (SQL statement classification, parse_sql, and pipeline flow registration) handle both shapes again.

These parts of #58378 are kept:

Early resolution of a dynamic INSERT target runs inside the analysis planning tracker, and its failures are reported through QueryPlanningTracker.setAnalysisFailed.
The parse_sql CTE-shadow exemption stays limited to INSERT targets, so CTE-shadowed DELETE, UPDATE, and MERGE targets are not reported as catalog target tables. The exemption now applies to the InsertIntoStatement target, so WITH t AS (...) INSERT INTO t ... still reports t as a target.

In addition, CheckAnalysis raises an internal error if an UnresolvedInsert reaches it without being lowered to InsertIntoStatement.

This should be merged to master and branch-4.x, where #58378 landed. branch-4.3 has #58204 but not #58378, so it already has the restored behavior.

Why are the changes needed?

InsertIntoStatement is the parsed INSERT plan that existing parser-level consumers, extensions, and plan-based tooling match on. Only a dynamic IDENTIFIER target needs analyzer traversal of the target before the INSERT can be lowered. Parsing every INSERT as UnresolvedInsert forces all of these consumers to handle a new intermediate node for the common static case, without any benefit for that case. Scoping the temporary node to dynamic targets keeps the plan-shape change limited to the statements that need it.

Does this PR introduce _any_ user-facing change?

No change relative to a released Spark version. Within unreleased master and branch-4.x, the parsed plan of a static-target INSERT (for example, in EXPLAIN EXTENDED) shows InsertIntoStatement again, as in branch-4.3.

How was this patch tested?

Updated the existing tests and golden files to the restored plan shape, and added tests for the parsed shape of a literal IDENTIFIER('...') target and for the CheckAnalysis invariant check. Then ran:

build/sbt -Phive \
  "catalyst/testOnly org.apache.spark.sql.catalyst.parser.PlanParserSuite org.apache.spark.sql.catalyst.parser.DDLParserSuite org.apache.spark.sql.catalyst.parser.IdentifierClauseParserSuite org.apache.spark.sql.catalyst.analysis.AnalysisSuite" \
  "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 org.apache.spark.sql.connector.AppendDataTransactionSuite" \
  "sql/testOnly org.apache.spark.sql.SQLQueryTestSuite -- -z explain.sql -z explain-aqe.sql -z identifier-clause.sql" \
  "pipelines/testOnly org.apache.spark.sql.pipelines.graph.SqlPipelineSuite org.apache.spark.sql.pipelines.graph.SqlQueryOriginSuite"

All tests passed.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Isaac (Claude Opus 5.5)

This pull request and its description were written by Isaac.

Diff: 417 lines (+312 / -105) across 5 files Reviewer: cloud-fan Review duration: 1208m
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 417 lines diff across 5 files
0.45
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.361
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #59750"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 45.0% (MEDIUM) · Higher = larger blast radius
45.0%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 17.8% · Safe to merge
17.8%
Repository