Repository navigation
fix(arrow/decimal): handle native word widths in big integer conversions - #1409
Merged
Merged
Conversation
lidavidm
approved these changes
Oct 25, 2026
lidavidm
left a comment
Member
There was a problem hiding this comment.
(Since the changes are unrelated, perhaps we can separate them into two PRs?)
Decimal128 and Decimal256 treated math/big.Word as a 64-bit limb. On 32-bit platforms this truncated and misplaced coefficient bits, and Decimal256.FromBigInt could index past its four-limb array. Combine and split pairs of 32-bit words while preserving the native 64-bit conversion paths. Cover each word boundary and independently check FromBigInt against literal expected coefficients. Generated-by: OpenAI Codex (GPT-6 Astra)
The decimal128/decimal256 big.Int conversion fix has 32-bit-only code paths (bits.UintSize == 32), but the 386 job only ran parquet/file tests, so CI never exercised them. The decimal packages now pass on 386; add them to the job.
zeroshade
force-pushed
the
fix-386-decimal-ree-validate
branch
from
October 26, 2026 15:25
822195d to
458cf82
Compare
zeroshade
added a commit
that referenced
this pull request
Oct 26, 2026
### Rationale for this change Split out of #1409. `ValidateFull` rejects run-end-encoded arrays from the builder. A REE array from `NewRunEndEncodedBuilder` (or a `Concatenate` of such arrays) fails with `expected at least 1 buffers for run_end_encoded<...>, got 0`, on every platform. The REE layout declares one always-null placeholder buffer (`datatype_encoded.go:40`); `NewRunEndEncodedArray` and the IPC reader supply a `nil` placeholder, but the builder and C Data import produce zero buffers. The Arrow spec says REE arrays have no physical buffers, so both representations are legitimate. ### What changes are included in this PR? `arrow/array/validate.go` accepts a REE array (including extension types with REE storage) that has no buffers. Arrays with a `nil` placeholder go through the existing checks as before, and non-nil or extra parent buffers are still rejected. Constructors, layouts, IPC and C Data are unchanged. ### Are these changes tested? Yes. New `TestRunEndEncodedValidateConstructedArrays` checks that builder-produced, empty, sliced, constructor-built, `Concatenate`d and REE-extension arrays pass `ValidateFull`. The builder, `Concatenate`, empty, sliced and extension cases fail before the fix; constructor cases passed already. Existing rejection cases (bad run ends, non-nil/extra parent buffers) still fail validation. `go vet` and `gofmt -l` are clean on `arrow/array`. ### Are there any user-facing changes? Yes: `ValidateFull` accepts run-end-encoded arrays produced by the builder, `Concatenate` and C Data import. No API changes.
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.
Rationale for this change
Found while fixing the 32-bit test failures in #1408.
Decimal conversions are wrong on 32-bit platforms.
decimal128.Numanddecimal256.Numuse 64-bit limbs, but theirbig.Intconversions assumedbig.Wordis also 64 bits. On 386 it is 32 bits, so:decimal128.FromBigIntreadb[0]/b[1]as the low and high limbs (decimal128.go:95–97), misplacing words and dropping the rest;decimal128'stoBigIntPositivebuilt[]big.Word{big.Word(n.lo), big.Word(n.hi)}(decimal128.go:362), truncating each limb;decimal256.FromBigIntcopied word i into limb i (decimal256.go:370), misplacing words and panicking when a value needed more than four native words;decimal256'stoBigIntPositivetruncated its limbs the same way (decimal256.go:379).Anything going through
big.Int(string formatting and parsing, rescaling,GetOneForMarshal, CSV decimal parsing) produced wrong values or spurious precision errors on 386, e.g.TestDecimal128Sliceprinted-1717986918instead of-7.378697629e+18, andTestDecimal128GetOneForMarshalturned1234567890.123456789into437278697.08398250845211745659132109676.The run-end-encoded validation fix that was originally part of this PR has moved to #1421.
What changes are included in this PR?
arrow/decimal128,arrow/decimal256: whenbits.UintSize == 32, combine pairs of 32-bitbig.Words into each 64-bit limb inFromBigInt, and split each limb into two words intoBigIntPositive.bits.UintSizeis a constant, so 64-bit builds compile the existing code unchanged. Also corrects thedecimal128.FromBigIntdoc (it panics above 127 bits, as the code already does).Are these changes tested?
Yes.
GOARCH=386:TestDecimal128Slice,TestDecimal128StringRoundTrip,TestDecimal128GetOneForMarshal,TestDecimal256Slice,TestDecimal256GetOneForMarshal, all nineTestDecimal/TestWithNulls#01precisions,TestDecimalScalarStringCastUsesExactScalingand CSV'sTestReadCSVDecimalColsall failed before and pass now. TheTestDecimalToBigInttests in both packages gain word-boundary cases with independently computed expectations, which fail on 386 without the fix (decimal256 panics).arrow/decimal128,arrow/decimal256andarrow/decimal/...pass in full on 386.arrow/decimal128,arrow/decimal256,arrow/decimal/...pass.go vetandgofmt -lare clean on the changed packages.Are there any user-facing changes?
Yes: decimal values convert correctly on 32-bit platforms. No API changes.