← Back to Pull requests

Fix low shuffle merge second source scan counting [databricks] #16884

Closed
unknown closed this pull request without merging on Nov 18, 2026 07:32 UTC
View on GitHub
unknown unknown commented on Nov 16, 2026 03:24 UTC
Author

Fixes #16866.

Description

Low-shuffle MERGE can report that an unchanged source is non-deterministic on Databricks 17.3: without WHEN NOT MATCHED BY SOURCE, Catalyst can prune the non-nullable source-presence marker and its row-count UDF, leaving the second-scan count at zero. With spark.databricks.delta.merge.failIfSourceChanged=true, this incorrectly fails the MERGE.

Count source rows in a non-deterministic filter before the write-pass join, and use a literal source-presence marker. This preserves the source-change sanity check in both the ordinary and CDF write paths shared by DBR 17.3/18.3.

Validation

Built and tested commit dcb8846cd0 (base c824f5e43e) on a single-node AWS g4dn.4xlarge with one T4, DBR 17.3 LTS ML GPU image 17.3.25, Spark 4.0.0, and Scala 2.13:

  • jenkins/databricks/build.sh: passed for 400db173.

  • Full delta_lake_low_shuffle_merge_test.py in nightly mode with four pytest workers: 371 passed, 0 failed, 0 errors, 0 skipped in 25m 57s (16 warnings).

  • New test_delta_low_shuffle_merge_counts_second_source_scan: all eight combinations of PERFILE, MULTITHREADED, COALESCING, and AUTO with CDF off/on passed. It uses an unchanged Delta source, matched updates and unmatched inserts, no WHEN NOT MATCHED BY SOURCE, and failIfSourceChanged=true; existing helpers assert CPU/GPU results and low-shuffle GPU execution.
  • Additional validation:

  • Static sql-plugin source-selection coverage against target snapshot c3175518cd: 35 profiles, no new findings. The shared Delta source roots are selected by both DBR module POMs. DBR 18.3 build/runtime validation has not been run.

  • Upstream CI repair #16964, which closes #16950, is included through the base merge. Its WithRetrySuite passed all 28 tests locally on Spark 3.3.0 / Scala 2.12.21 with a stale mock-task callback seeded. The suite and mock contexts were compiled against the existing local Spark 3.3.0 artifacts for this check.

  • Repository scalastyle: 2,090 files checked, zero errors and warnings. Generated Scala 2.13 build files match the merged source.
  • The modified MERGE command and regression-test file are identical to the tested commit. Target snapshot c3175518cd was merged after that DBR run.

    Blossom premerge 15592 failed in WithRetrySuite and aborted its Databricks branches. The upstream repair is now included; full Blossom validation on the updated base is pending.

    Performance

    GPU source-counter microbenchmark on the same DBR 17.3/T4 node: 100 million range rows, four partitions, GPU hash/modulo/sum aggregation, 100 MiB batches, and a 1536 MiB RMM pool. Each action used a fresh DataFrame and SQL metric. After three warmups per mode, eight paired rounds alternated execution order; timings exclude planning.

    | Source-counter expression | Rows counted | Median action time | Range |
    |---|---:|---:|---:|
    | Pruned presence-marker projection (reproduces the bug) | 0 | 200.1 ms | 179.7–268.2 ms |
    | Retained counter filter | 100,000,000 | 225.5 ms | 213.8–298.1 ms |

    Both modes produced the same aggregate checksum. Restoring counting added 25.4 ms to the median action in this probe. These measurements cover the source-counter expression; full-MERGE throughput was not measured.

    This PR was implemented and validated with AI assistance (Codex).

    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

  • (Please provide the names of the existing tests in the PR description.)
  • Not required
  • Performance

  • Tests ran and results are added in the PR description

  • Issue filed with a link in the PR description

  • Not required
  • Diff: 485 lines (+363 / -122) across 6 files Reviewer: res-life Review duration: 3127m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.47) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 485 lines diff across 6 files
    0.47
    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%
    56%
    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.370
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #16884"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% 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: 47.3% (MEDIUM) · Higher = larger blast radius
    47.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: 56.8% · Lower = rushed or shallow review
    56.8%
    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: 20.5% · Safe to merge
    20.5%