← Back to Pull requests

fix: accept signed minima in ANSI decimal casts to INT and BIGINT #7806

Open
unknown opened this pull request with 373 lines diff across 4 files
View on GitHub
unknown unknown commented on Dec 01, 2026 00:05 UTC
Author

Closes #7805.

Why are the changes needed?

ANSI casts from DECIMAL to INT and BIGINT reject the signed minimum. The old check compares the absolute value after truncation to MAX. The magnitude of MIN is MAX + 1, even though MIN fits.

What changes are included in this PR?

Use the destination's signed range after truncation. Only values that truncate to MIN can change. The planner, codegen dispatcher, legacy casts and TRY casts are unchanged.

For INT, truncated values in [-INT_MAX, INT_MAX] return immediately. INT_MIN and out-of-range values reach the existing boundary checks. The BIGINT kernel keeps its checked conversion.

There is one narrow exception for INT. Before SPARK-60843, Spark rounds an expanded decimal through DOUBLE. Within half an ulp (2⁻²²) above −2147483649, that rounds to −2147483649 and raises CAST_OVERFLOW. The kernel preserves the previous overflow in this interval using integer arithmetic. Arrow carries the unscaled value, precision and scale, but loses Spark's compact/expanded distinction. A compact decimal in this interval can still raise overflow when Spark would return INT_MIN. Preserving that distinction across projections and handling Spark versions with exact truncation remain outside this change.

How are these changes tested?

The Parquet SQL fixture exercises INT_MIN and BIGINT_MIN, fractional inputs truncating to MIN, and overflow one integer below each. It also checks the exact DOUBLE midpoint for INT and the decimal one unit above it at scale 22. The successful query requires a native cast. The midpoint test fails with the original unguarded Rust change.

All eight fixture runs passed before the fast path on Spark 3.5.9, 4.0.4, 4.1.3 and 4.2.0, with dictionary encoding on and off. I reran the fixture after the fast path on Spark 3.5.9 and 4.1.3 with both encodings. All four passed. The 43 Rust numeric conversion tests also passed. An optimized Arrow probe compared the new kernel with the previous revision across 3,969 boundary cases, including nulls and legacy casts. Every result and error matched.

A separate 31-query Spark 4.1.3 check produced identical results, errors and routing to 6e2408a. All 31 normalized physical plans matched that revision and the PR base. The 12 preexisting differences from Spark are unchanged.

The optimized Arrow 59.3.2 microbenchmark measured the base, the previous revision (6e2408a), and the fast path on three pinned CPU cores. Times are median nanoseconds per input row, including nulls. Each core ran 36 measured rounds after six warmups, alternating the order of the three kernels.

| Cast | Base | Previous revision | Fast path |
| --- | ---: | ---: | ---: |
| DECIMAL(38,18) to INT, non-null | 10.25 | 10.88 | 10.21 |
| DECIMAL(38,18) to INT, 20% null | 8.63 | 9.15 | 8.62 |
| DECIMAL(38,18) to BIGINT, non-null | 10.23 | 9.92 | 9.93 |

These measurements cover the cast kernel only.

Diff: 373 lines (+279 / -94) across 4 files Reviewer: comphead Review duration: 2788m
All Vouch review confidence checks passed
Residual risk 0.24 = Change Risk (0.43) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 373 lines diff across 4 files
0.43
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
42%
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.354
Shallow Review Depth shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #7806"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 43.0% 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: 42.8% (MEDIUM) · Higher = larger blast radius
42.8%
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: 43.0% · Lower = rushed or shallow review
43.0%
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: 24.4% · Safe to merge
24.4%