Improvements to decimal conversion#292
Merged
Merged
Conversation
…ues (e.g., Decimal256 with precision 76, scale 38) that previously threw OverflowException — addresses issue apache#247 - Adds a fast path using Int128 on .NET 7+ that avoids BigInteger allocation for values that fit in 128 bits - Replaces the old fractional-part overflow check (which threw) with FractionToDecimal, which gracefully reduces precision to fit within decimal's ~28-digit mantissa
There was a problem hiding this comment.
Pull request overview
This PR improves decimal conversion for Arrow decimal arrays, fixing high-scale conversion overflows (notably Decimal256 precision 76 / scale 38) and adding a .NET 7+ fast path to reduce BigInteger allocations.
Changes:
- Fixes
DecimalUtility.GetDecimalto handle high-scale values more gracefully by reducing fractional precision instead of throwing. - Adds a .NET 7+ (
net8.0in this repo)Int128-based conversion fast path for 128-bit values (and 256-bit values that sign-extend into 128 bits). - Expands test coverage for high-precision/scale
GetValueand introduces a new benchmark for decimal access patterns.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Apache.Arrow/DecimalUtility.cs | Adds Int128 fast path and replaces fractional overflow throwing with truncation-based conversion. |
| src/Apache.Arrow/Arrays/Decimal128Array.cs | Adds TryGetValue convenience API for decimal retrieval. |
| src/Apache.Arrow/Arrays/Decimal256Array.cs | Adds TryGetValue convenience API for decimal retrieval. |
| test/Apache.Arrow.Tests/DecimalUtilityTests.cs | Updates expectations so high-scale Decimal256 conversion no longer throws. |
| test/Apache.Arrow.Tests/Decimal128ArrayTests.cs | Adds high-scale GetValue/TryGetValue tests for Decimal128. |
| test/Apache.Arrow.Tests/Decimal256ArrayTests.cs | Adds high-scale GetValue/TryGetValue tests for Decimal256 (issue #247 scenario). |
| test/Apache.Arrow.Benchmarks/DecimalArrayBenchmark.cs | Adds new BenchmarkDotNet benchmarks for decimal conversions/accessors. |
| .gitignore | Ignores BenchmarkDotNet output artifacts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… the `TryGetValue` path.
adamreeve
reviewed
Mar 24, 2026
Contributor
adamreeve
left a comment
There was a problem hiding this comment.
Looks good thanks Curt, I just have some minor suggestions
adamreeve
approved these changes
Mar 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's Changed
Closes #247.
Partially addresses #96.