← Back to Pull requests

Handle rows-only sides and count-only joins in nested loop joins [databricks] #16518

Open
unknown opened this pull request with 558 lines diff across 6 files
View on GitHub
unknown unknown commented on Oct 22, 2026 17:19 UTC
Author

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 Table when 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.

nestedLoopJoin sends 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 sequence predicate 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 3cdf711de against 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 e26a276bf against 1914a35c3, as built on 3cdf711de, 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 3cdf711de against 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

BroadcastNestedLoopJoinSuite drives nestedLoopJoin for 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 at 2bd784a16, 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 without 12782f8da.

Checklists

Documentation

  • Updated for new or modified user-facing features or behaviors

  • No user-facing change
  • Testing

  • Added or modified tests to cover new code paths

  • Covered by existing tests

  • Not required
  • Performance

  • Tests ran and results are added in the PR description

  • Issue filed with a link in the PR description

  • Not required
  • This PR was built and prepared using an AI assistant.

    Diff: 558 lines (+418 / -140) across 6 files Reviewer: gerashegalov Review duration: 14154m
    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
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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.378
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #16518"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 48.2% (MEDIUM) · Higher = larger blast radius
    48.2%
    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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 25.7% · Safe to merge
    25.7%