[SPARK-60664][SQL] Remap metadata columns in runtime group filters of group-based UPDATE with subqueries #59893
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 507 lines diff across 6 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.373
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #59893"
general
weight: 0.35
szehon-ho
What changes were proposed in this pull request?
This PR aims to fix
RowLevelOperationRuntimeGroupFilteringto remap the metadata columns that the UPDATE condition references, in addition to the table columns, when it builds a runtime group filter.A group-based UPDATE whose condition has a subquery is rewritten as a
Unionthat reads the table twice (RewriteUpdateTable.buildReplaceDataWithUnionPlan), andDeduplicateRelationsgives the second read new expression IDs, including its metadata attributes. The group filter of each read is the UPDATE condition with the attributes replaced by name with those of that read. However, onlywrite.table.output(the table columns) has been replaced. When the analyzer resolves a metadata column such as_partitionfrom the metadata output of the target relation, it is not in that output, so the group filter of the second read keeps the expression ID of the first read.For example,
EXPLAIN EXTENDEDshows the following for the second read._partition#30belongs to the first read.With this PR, the group filter uses the metadata attribute of its own read.
The table columns are mapped as before, including the
_LEGACY_ERROR_TEMP_3075check.Why are the changes needed?
The dangling reference makes such an UPDATE fail at execution with an internal error. The scan of the group filter subquery prunes
_partition, and the post-scanFiltercannot bind the reference.This happens when the UPDATE is resolved in a single analyzer iteration, e.g., when no implicit cast is required. Otherwise,
AddMetadataColumnsadds the metadata columns to the target relation in a later iteration, and they are mapped as table columns.Does this PR introduce _any_ user-facing change?
Yes. Such UPDATE statements fail with an internal error without this PR. The UPDATE branch of this rule has mapped only the table columns since SPARK-43975 (Apache Spark 3.5.0).
How was this patch tested?
Pass the CIs with the newly added test case. Without this fix, the test fails like the following.
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5