← Back to Pull requests

[SPARK-60282][SQL] Fix hidden USING columns from join inputs in ASOF JOIN and single-pass JOIN #59591

Closed
unknown closed this pull request without merging on Oct 20, 2026 11:48 UTC
View on GitHub
unknown unknown commented on Oct 19, 2026 10:37 UTC
Author

What changes were proposed in this pull request?


Two fixes for hidden USING columns (like d.k after r LEFT JOIN d USING (k)), one in each analyzer:

- Fixed-point: an ASOF JOIN with USING now passes up the hidden columns of its inputs. Added one shared helper for regular USING and ASOF one ->NaturalAndUsingJoinResolution.buildUsingJoinProject.
- Single-pass: when a join merges the ID mappings of its two sides, it now also keeps the IDs of hidden columns. Before, if a copy of the same table was on the other side, the merged mapping sent d.k to the copy's k. Anything that maps d.k again then read the wrong column: an ASOF JOIN MATCH_CONDITION, or d..

### Why are the changes needed?
Each bug makes dual-run fail. In single-pass, they also fail the query at run time or return wrong rows.

  CREATE OR REPLACE TEMP VIEW using_left(k, lts) AS VALUES (1, 10), (2, 20), (8, 30);
  CREATE OR REPLACE TEMP VIEW using_right(k, rts) AS VALUES (1, 5), (2, 12), (8, 15);
  CREATE OR REPLACE TEMP VIEW using_keys(k) AS VALUES (1), (2);

  SELECT l.lts, d.k
  FROM using_left l ASOF JOIN (using_right r LEFT JOIN using_keys d USING (k))
    MATCH_CONDITION (l.lts >= r.rts) USING (k);
  

Before: fixed-point fails with UNRESOLVED_COLUMN for d.k. After: (10, 1), (20, 2), (30, NULL).

  SELECT x.k
  FROM (using_right r LEFT JOIN using_keys d USING (k))
  ASOF JOIN using_keys x MATCH_CONDITION (d.k >= x.k);
  

Before: single-pass plans AsOfJoin (x.k >= x.k) and the query fails with INTERNAL_ERROR_ATTRIBUTE_NOT_FOUND. After: (1), (2).

  SELECT d.*
  FROM (using_right r LEFT JOIN using_keys d USING (k)) JOIN using_keys y ON y.k = 1;
  

Before: single-pass returns 1, 1, 1 (the copy's k). After: 1, 2, NULL.

### Does this PR introduce _any_ user-facing change?
Yes. The queries above now return the right rows instead of failing or returning wrong ones.

### How was this patch tested?
New queries FVT-ASOF-2-043 to 052 in join-asof-semantics.sql, and two queries in using-join.sql. Tests run both analyzers and compare their plans. Without the fixed-point fix, 043 to 045 and 047 to 049 fail. Without the single-pass fix in AsOfJoinResolver, 046, 047 and 050 fail. Without it in JoinResolver, 051, 052 and the nt2.
query in using-join.sql fail.

### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code

Diff: 313 lines (+234 / -79) across 3 files Reviewer: mihailoale-db Review duration: 1511m
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 313 lines diff across 3 files
0.40
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.344
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #59591"
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: 40.3% (MEDIUM) · Higher = larger blast radius
40.3%
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: 15.9% · Safe to merge
15.9%
Repository