Handle rows-only sides and count-only joins in nested loop joins [databricks] #16518
All Vouch review confidence checks passed
Residual risk 0.26 = Change Risk (0.48) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 558 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 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.378
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #16518"
general
weight: 0.35
gerashegalov
Fixes #16028.
Contributes to #15991.
Description
A conditional broadcast nested loop join fails on the GPU with
Cannot convert a rows-only ColumnarBatch to a cudf Tablewhen its condition reads nothing from one side.Column pruning leaves that side with rows and no columns, as in
SELECT count(*) FROM t1 WHERE NOT EXISTS (SELECT 1 FROM t2 WHERE t1.a > 5).Spark 4.0 reaches more join types, because SPARK-46707 made it keep a predicate that can throw, such as
sequence, in the join condition.(see table below).This PR also fixes a second bug in the same operator. A join with no condition that only counts rows got the count wrong over an empty build. LEFT SEMI counted every stream row, and LEFT ANTI and the outer joins counted none, the reverse of Spark.
nestedLoopJoinsends a rows-only side to a degenerate path, as #7786 and #13817 do for other join types, which filters the side with columns once and then cross joins it, keeps or drops stream rows, or adds an exists column. The count-only path derives each stream row's output rows from the build row count. An inner join over an empty build skips the condition, as Spark does.| Case | Spark | On main | With this PR |
|---|---|---|---|
| LEFT ANTI whose condition reads only the left side, as in the query above | 3.3 and later | Fails with the error above | Matches the CPU |
| LEFT ANTI from a NOT EXISTS whose predicate folds to false, with no columns on either side | 3.3 and later | Fails with the error above | Matches the CPU |
| Inner and Cross on either build side, and LEFT SEMI and LEFT ANTI building right, whose condition keeps a
sequencepredicate over one side | 4.0 and later | Fails with the error above | Matches the CPU || Existence join building right whose condition reads only the subquery side | 4.0 and later | Fails with the error above | Matches the CPU |
| LEFT SEMI, LEFT ANTI, LEFT OUTER and RIGHT OUTER with no condition that only count rows, over an empty build with AQE off | 3.3 and later | Wrong count | Matches the CPU |
| Outer joins with a rows-only side, and existence joins with a rows-only build | 3.3 and later | Their own degenerate paths | Unchanged |
| Joins with columns on both sides, and existence joins building left | 3.3 and later | The conditional iterators | Unchanged |
Performance
Spark 3.5.3, RTX A5000, 8 rounds of a real pair and a null pair per build, 10 timed queries each:
| Query | Before, median | After, median | After against before, per pair | Null pairs |
|---|---|---|---|---|
| LEFT ANTI, condition on both sides, 10,000,000 by 10,000 rows, main
3cdf711deagainst this PR built on it | 1313.6 ms | 1314.3 ms | -4.0 to +10.8 ms, median +2.6 ms, slower in 6 of 8, sign test p = 0.29 | -5.2 to +9.2 ms || The issue's LEFT ANTI with a rows-only build, same sizes, the undone padded
e26a276bfagainst1914a35c3, as built on3cdf711de, whose code for this query this PR keeps | 2694.5 ms | 38.6 ms | 55 to 79 times faster, faster in 8 of 8, p = 0.008 | -9.9 to +26.6 ms || Count-only LEFT SEMI, 100,000,000 rows in 64 partitions by 10,000, main
3cdf711deagainst this PR built on it | 25.3 ms | 27.5 ms | -3.9 to +5.9 ms, median +3.6 ms, slower in 7 of 8, p = 0.07 | -18.1 to +10.0 ms |Both median differences against main sit inside their null pairs' range. The count-only join now reads the build row count per task, a cost 8 pairs cannot separate from noise. An inner join over an empty build now skips one filter per stream batch.
Tests
BroadcastNestedLoopJoinSuitedrivesnestedLoopJoinfor nine join shapes with a rows-only build, a rows-only stream, or both. Integration tests cover each failing case in the table above. Against main at2bd784a16, 15 of the first 22 suite tests fail on Spark 3.5.3, and 44 of the 68 integration cases on Spark 4.0.2. Nine more check that an empty rows-only build skips the condition, and the four Inner and Cross ones fail without12782f8da.Checklists
Documentation
Testing
Performance
This PR was built and prepared using an AI assistant.