Fallback extreme decimal scale casts to CPU [databricks] #16841
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 392 lines diff across 4 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.357
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #16841"
general
weight: 0.35
res-life
Fixes #16834.
Description
Spark supports
DecimalTypescales close to the limits of a 32-bit integer. For extreme scale changes, the GPU cast path performs calculations such as scale negation, whole-number precision, and scale delta using values that can exceed that range. String-to-decimal conversion also combines the parsed exponent with the cuDF scale using 32-bit arithmetic. These cases can produceNULLwhere Spark returns zero or give incompatible ANSI behavior.This change evaluates static decimal scale calculations in a wider type during planning and falls back to CPU execution when GPU arithmetic is unsafe, including decimal fields nested in arrays, maps, and structs. String-to-decimal targets outside Spark's conventional decimal precision range also fall back because planning cannot bound the parsed exponent used by the GPU kernel. Endpoint types that cannot be safely materialized opt out of the CPU expression bridge, causing the enclosing project to fall back. Unsupported casts with safe endpoint types may use the CPU expression bridge and keep the project on GPU. Ordinary decimal casts remain GPU accelerated. There is no new configuration or documented API behavior.
Regression tests cover zero and nonzero values, ANSI and non-ANSI behavior, scale changes immediately beyond the supported GPU range, integer-overflow scale values, parsed-exponent arithmetic, independent source and target bridge guards, CPU bridge execution, whole-project fallback, and nested decimals in arrays, map keys and values, and structs. Map key and value recursion are tested independently for endpoint rejection, safe-endpoint large-delta bridge fallback, and extreme string-to-decimal fallback. The focused Spark 4.0.5 run passed 63 cases. The five scalar and nested string-to-extreme-decimal cases passed on both Spark 3.3.0, where CPU and GPU fallback consistently report underflow, and Spark 4.0.5, where they return matching results.
GpuCpuBridgeOptimizerUnitSuitepassed 24 tests on both Scala 2.12 with Spark 3.3.0 and Scala 2.13 with Spark 4.0.5. Scala 2.12 and Scala 2.13 Scalastyle validation passed. Shim source-selection coverage passed all 4,465 checks, and the combined-tree shim review found no new findings. The[databricks]title tag requests Databricks pre-merge coverage for the GPU plan assertions.A pure GPU implementation for cuDF-representable endpoint scales is tracked by #16851, split into decimal-to-decimal and string-to-decimal workstreams. The general CPU bridge semaphore limitation is tracked separately by #16788.
This change and pull request description were prepared with AI assistance and require human review.
Checklists
Documentation
Testing
(Please provide the names of the existing tests in the PR description.)
Performance