[SPARK-60978][SQL] Fix wrong results by DSv2 DELETE, UPDATE and MERGE when column names differ only by case #60155
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.50) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 629 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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.386
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #60155"
general
weight: 0.35
spark-test
What changes were proposed in this pull request?
This PR aims to fix a correctness issue of DSv2 row-level DELETE, UPDATE and MERGE.
RewriteRowLevelCommand.findColOrdinalnow looks for the column with exactly the given name first, and falls back toconf.resolveronly when there is no such column.The fallback is still needed because a connector may refer to a column in a different case, e.g. the row ID
pkof a columnPK.V2ExpressionUtils.resolveRefgives the resolved attribute the name of the reference.Why are the changes needed?
This is a correctness issue. When a table has columns whose names differ only by case, such as
salaryandSALARY, an UPDATE, a MERGE or a group-based DELETE in a case-insensitive session, which is the default, writes the value of one column into the other without any error. The statement does not need to refer to these columns, so nothing is ambiguous.RewriteRowLevelCommandbuilds the row projections ofReplaceDataandWriteDeltaby looking up the ordinal of each table column in the query output by name.findColOrdinalreturned the first column thatconf.resolvermatches, soSALARYgot the ordinal ofsalary. For example, the row projection of the UPDATE below uses the ordinals[1, 2, 2, 4]instead of[1, 2, 3, 4].The results above are read with
spark.sql.caseSensitive=true.SALARYisNOT NULLandsalaryis nullable, the UPDATE fails with a misleadingINSERT_COLUMN_ARITY_MISMATCH.TOO_MANY_DATA_COLUMNSerror instead.Does this PR introduce _any_ user-facing change?
Yes. An UPDATE, a MERGE or a group-based DELETE on a table whose column names differ only by case now writes each column's own value, and the
NOT NULLcase above succeeds. If such columns also differ in type or nullability, the scan side needs SPARK-60979 (#60156) as well. This is a long-standing issue in the released versions, including v4.3.0 (2026-10-27).How was this patch tested?
Pass the CIs with newly added test cases.
SPARK-60978: update keeps columns whose names differ only by casefails without this PR in the five UPDATE suites.SPARK-60978: delete keeps columns whose names differ only by casefails without this PR in the group-based DELETE suites.SPARK-60978: merge keeps columns whose names differ only by casefails without this PR in every MERGE suite.SPARK-60978: update with a row ID column whose name differs in casechecks the fallback toconf.resolverin the delta-based UPDATE suites. It fails iffindColOrdinalmatches exact names only.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5