Fall back for ANSI BIGINT SUM in bounded ROWS windows [databricks] #17189
All Vouch review confidence checks passed
Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 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.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #17189"
general
weight: 0.35
thirtiseven
JaCoCo production line coverage: +19 lines (
sql-plugin +19: 16 sharedsrc/main/scala+ 3spark330TryModeShim.scala; single-run fix-line coverage, Spark 3.3.0 / Scala 2.12.21, baseb2e742d1;spark340/spark400db173shim variants outside shim 330).Towards #17072.
Description
With ANSI enabled, bounded
ROWSwindows containingSUM(BIGINT)could return a result when Spark CPU raises an intermediate overflow, e.g.[Long.MaxValue, 1, -1]. Fall back the containingWindowExecto CPU for finite, unequal bounds; sibling aggregates in that node also fall back. Document this compatibility restriction.Single-row and non-ANSI windows retain their existing GPU eligibility. Other input types retain their existing GPU eligibility. Inline small-Decimal rewrites (precision ≤ 8) remain GPU eligible; an optimizer may instead project their unscaled values into BIGINT attributes, which use the same conservative fallback. Other non-running frames that remain on GPU (half-unbounded
ROWSwith positive upper or finite lower bounds, full-unbounded frames, and boundedRANGEframes) and the pure-GPU follow-up (avoiding CPU fallback) remain tracked under #17072.Follow-up commits:
c496856ef: replaces physical-planningSQLConf.get.ansiEnabledlookups withTryModeShim.getEvalMode(sum: Sum)across thespark330(sum.useAnsiAdd),spark340(sum.evalMode), andspark400db173(sum.evalContext.evalMode) shims in both the boundedROWSSUM(BIGINT)fallback guard andSumRuleMeta.convertToGpu, ensuring plans stay consistent with the analyzedSumANSI eval mode even ifspark.sql.ansi.enabledchanges between analysis and execution.c9e7b6937: clarifies the current restriction scope indocs/compatibility.md(explicitly noting that other non-running frames on GPU do not yet preserve intermediate overflow checks), keepsGpuBatchedBoundedWindowExecinexist_classesfor both ANSI modes intest_window_aggs_for_batched_finite_row_windows_{partitioned,unpartitioned}, and assertsnon_exist_classes='WindowExec'underis_apache_runtime()for smallDecimal(precision <= 8)inputs in_bounded_sum_window_plan_classes.Validation
Add 28 regression cases (25 original + 3 post-analysis
spark.sql.ansi.enabledtoggle cases inc496856ef) covering intermediate overflow, NULLs, cancellation order, input types, ANSI settings, post-analysis ANSI mode flips, and frame boundaries, with CPU/GPU result or error parity and execution-plan assertions.After follow-up commits
c496856efandc9e7b6937:c9e7b6937, local RTX 5880 Ada): all 9 modifiedwindow_function_test.pytest functions (test_decimal_sum_window_ansi,test_decimal_sum_window_no_part_ansi,test_window_aggs_for_rows,test_window_aggs_for_negative_rows_{partitioned,unpartitioned},test_window_aggs_for_batched_finite_row_windows_{partitioned,unpartitioned},test_sum_long_ansi_rows_{overflow,negative_overflow}) 252 passed, 2 existing #7429 skips, 0 failed.c496856ef, JDK 17, local RTX 5880 Ada; no JVM code changed inc9e7b6937):WindowFunctionSuite+WindowRetrySuite69 passed, 0 failed, 0 ignored.c496856ef):scripts/check-shim-coverage.shPASS,python3 build/check_shim_compatibility.py coveragePASS (34 buildvers, 4442 requirements, 0 findings), local compiles pass across Spark330,340,400(Scala 2.13), and411(Scala 2.13).mvn verify -N(c9e7b6937): Apache RAT 0 unapproved,with-resource-nesting-audit32/32 passed,scalastyle-all-modules2137 files 0 errors / 0 warnings.aggregator/target/spark330/new-classes, zero class-ID mismatches; unchanged inc9e7b6937which touches only docs and Python ITs):sql-plugin +19covered added production lines (16/30 in sharedsrc/main/scala+ 3/3 executable lines inspark330/TryModeShim.scala); no other applicable JVM production group has added production lines (spark340/spark400db173shim variants are outside shim 330).Previously completed full
WindowFunctionSuiteandWindowRetrySuiteruns (prior commit20fe33d1):| Runtime | Passed | Failed | Canceled |
| --- | ---: | ---: | ---: |
| Spark 3.3.0 / Scala 2.12.21, ANSI off | 64 | 0 | 0 |
| Spark 4.0.5 / Scala 2.13.18, ANSI on | 55 | 0 | 9 |
| Spark 4.0.5 / Scala 2.13.18, ANSI off | 64 | 0 | 0 |
All 25 initial cases passed in each run; the nine cancellations are existing #12700 guards. Python window tests explicitly cover ANSI on/off, require the expected GPU execution or CPU fallback, and compare CPU/GPU results or overflow errors. The same 15-function local IT matrix passed on Spark 3.3.0 / Python 3.10 (258 passed, 2 existing #7429 skips) and Spark 4.0.5 / Python 3.12 (260 passed, 0 skipped), with zero failures. Full premerge CI, including both Databricks jobs, passed on
20fe33d1.Performance
Run one complete Q51-derived query on SF3000 (nominal 3 TB) Parquet data, using quantities instead of prices and
ROWS BETWEEN 6 PRECEDING AND CURRENT ROWfor the two SUM windows. Retain the remaining joins, MAX windows, filtering, ordering, and limit. This custom query scans 2.093 billion fact rows after date pruning; it is not a full TPC-DS suite result.Compare parent
b2e742d1with the production fix at4bf4655con Spark 3.5.3 / JDK 17, 8 × A100 40 GB, one 16-core/16-GiB executor per GPU. ANSI and AQE are enabled, with 200 initial shuffle partitions and GPU allocation capped at 0.3. Measure query creation throughcollect(), with warm filesystem caches and no Spark DataFrame caching. Use before/after/after/before application order, two warmups and three measured executions per application; profiling is separate.| Full-query measurement | Before | After |
| --- | ---: | ---: |
| Median, six samples | 2.013 s | 2.541 s |
| Sample range | 1.734–2.673 s | 2.201–3.922 s |
| Host→GPU copies | 17.517 GiB | 22.896 GiB |
| GPU→Host copies | 7.963 GiB | 10.462 GiB |
Observed median cost: +26.2% (+527 ms). All 27 retained executions match the CPU schema and four ordered result rows. Plans confirm two CPU SUM windows after the fix, with surrounding GPU execution preserved; 130,892,745 rows cross GPU→CPU and back.
Separate CUPTI captures on all eight executors report zero dropped records. Copy totals include scan/shuffle traffic and fallback conversions. Copy events overlap, so they do not directly explain the wall-time increase. Results are specific to this workload/configuration; the timing ranges overlap.
Follow-up commit
c496856efis cold-path only (driver-side planning/tagging O(1) AST field read replacingSQLConf.get.ansiEnabled; executor hot path is unchanged), andc9e7b6937updates only docs and Python integration tests.AI assistance: The implementation, regression tests, and PR description were prepared with Codex and Cursor assistance.
Checklists
Documentation
Testing
(Please provide the names of the existing tests in the PR description.)
Performance