Fix low shuffle merge second source scan counting [databricks] #16884
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
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.370
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #16884"
general
weight: 0.35
res-life
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. Withspark.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(basec824f5e43e) on a single-node AWSg4dn.4xlargewith 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 for400db173.delta_lake_low_shuffle_merge_test.pyin nightly mode with four pytest workers: 371 passed, 0 failed, 0 errors, 0 skipped in 25m 57s (16 warnings).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, noWHEN NOT MATCHED BY SOURCE, andfailIfSourceChanged=true; existing helpers assert CPU/GPU results and low-shuffle GPU execution.Additional validation:
sql-pluginsource-selection coverage against target snapshotc3175518cd: 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.WithRetrySuitepassed 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.The modified MERGE command and regression-test file are identical to the tested commit. Target snapshot
c3175518cdwas merged after that DBR run.Blossom premerge 15592 failed in
WithRetrySuiteand 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
Testing
(Please provide the names of the existing tests in the PR description.)
Performance