← Back to Pull requests

Fallback extreme decimal scale casts to CPU [databricks] #16841

Closed
unknown closed this pull request without merging on Nov 17, 2026 05:28 UTC
View on GitHub
unknown unknown commented on Nov 11, 2026 08:05 UTC
Author

Fixes #16834.

Description

Spark supports DecimalType scales 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 produce NULL where 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. GpuCpuBridgeOptimizerUnitSuite passed 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

  • 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: 392 lines (+294 / -98) across 4 files Reviewer: res-life Review duration: 8482m
    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
    0.43
    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%
    60%
    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.357
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #16841"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 43.1% (MEDIUM) · Higher = larger blast radius
    43.1%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 17% · Safe to merge
    17%