Skip to content

test(arrow/array): make run-end-encoded concat tests valid on 32-bit platforms - #1408

Merged
zeroshade merged 1 commit into
apache:mainfrom
zeroshade:fix-ree-concat-386
Oct 26, 2026
Merged

zeroshade merged 1 commit into
apache:mainfrom
zeroshade:fix-ree-concat-386

Conversation

@zeroshade

Copy link
Copy Markdown
Member

Rationale for this change

TestConcatRunEndEncodedInt64FinalRunEndClamp panics on 386 (GOARCH=386 go test ./arrow/array -run TestConcatRunEndEncodedInt64FinalRunEndClamp):

panic: arrow/array: index out of range
    arrow/array/data.go:245  (NewSliceData)
    arrow/array/concat_test.go:1231

The test builds its input with RunEndEncodedBuilder.Append(math.MaxInt64), which makes an array whose length is math.MaxInt64. Array lengths are int, so on 32-bit targets the length wraps negative and array.NewSlice(big, 0, 1) panics while building the input: the test never reaches Concatenate. That is exactly the platform it was written for, since #1219's original bug (an int(e) conversion of the run end) only overflowed when int is 32 bits.

Two related tests, TestConcatAlmostOverflowRunEndEncoding/int64 and TestConcatOverflowRunEndEncoding/int64, have the same problem: they build inputs whose logical lengths are near 2^62, which cannot exist with 32-bit int.

These panics are not visible in CI, which only cross-builds for 386.

What changes are included in this PR?

Test-only changes in arrow/array/concat_test.go:

  • TestConcatRunEndEncodedInt64FinalRunEndClamp builds the one-element input directly with NewRunEndEncodedArray: run ends [math.MaxInt64], logical length 1. That is the same shape as a one-element slice of a MaxInt64-length run, and it is valid on 32-bit. The test now also checks the concatenated run ends ([5, 6]) and values ([1, 2]), not just the length.
  • The two *OverflowRunEndEncoding tests skip their int64 case when tt.max > math.MaxInt, i.e. only where the inputs cannot be constructed. The int16 and int32 cases still run everywhere.

Are these changes tested?

Not addressed here: arrow/array still has other, unrelated 386 failures in the decimal tests (e.g. TestDecimal128Slice, TestDecimal256Slice), which fail the same way on main.

Are there any user-facing changes?

No.

…platforms

TestConcatRunEndEncodedInt64FinalRunEndClamp built its input with
RunEndEncodedBuilder.Append(math.MaxInt64), which makes an array whose
length is math.MaxInt64. Array lengths are ints, so on 386 the length wraps
negative and NewSlice panics while building the input; the test never
reached Concatenate on the 32-bit targets it was written for. Build the
one-element input directly with a run end of math.MaxInt64 and logical
length 1, and also check the concatenated run ends and values.

TestConcatAlmostOverflowRunEndEncoding/int64 and
TestConcatOverflowRunEndEncoding/int64 need inputs with logical lengths
near 2^62, which cannot exist when int is 32 bits; skip them there.
@zeroshade
zeroshade merged commit 28128ef into apache:main Oct 26, 2026
23 checks passed
zeroshade added a commit that referenced this pull request Oct 26, 2026
…ons (#1409)

### Rationale for this change

Found while fixing the 32-bit test failures in #1408.

Decimal conversions are wrong on 32-bit platforms. `decimal128.Num` and
`decimal256.Num` use 64-bit limbs, but their `big.Int` conversions
assumed `big.Word` is also 64 bits. On 386 it is 32 bits, so:

- `decimal128.FromBigInt` read `b[0]`/`b[1]` as the low and high limbs
(`decimal128.go:95–97`), misplacing words and dropping the rest;
- `decimal128`'s `toBigIntPositive` built `[]big.Word{big.Word(n.lo),
big.Word(n.hi)}` (`decimal128.go:362`), truncating each limb;
- `decimal256.FromBigInt` copied word *i* into limb *i*
(`decimal256.go:370`), misplacing words and panicking when a value
needed more than four native words;
- `decimal256`'s `toBigIntPositive` truncated 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. `TestDecimal128Slice`
printed `-1717986918` instead of `-7.378697629e+18`, and
`TestDecimal128GetOneForMarshal` turned `1234567890.123456789` into
`437278697.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`:** when `bits.UintSize ==
32`, combine pairs of 32-bit `big.Word`s into each 64-bit limb in
`FromBigInt`, and split each limb into two words in `toBigIntPositive`.
`bits.UintSize` is a constant, so 64-bit builds compile the existing
code unchanged. Also corrects the `decimal128.FromBigInt` doc (it panics
above 127 bits, as the code already does).
- **CI:** the 386 job also runs the decimal packages' tests.

### Are these changes tested?

Yes.

- **On `GOARCH=386`:** `TestDecimal128Slice`,
`TestDecimal128StringRoundTrip`, `TestDecimal128GetOneForMarshal`,
`TestDecimal256Slice`, `TestDecimal256GetOneForMarshal`, all nine
`TestDecimal/TestWithNulls#01` precisions,
`TestDecimalScalarStringCastUsesExactScaling` and CSV's
`TestReadCSVDecimalCols` all failed before and pass now. The
`TestDecimalToBigInt` tests in both packages gain word-boundary cases
with independently computed expectations, which fail on 386 without the
fix (decimal256 panics). `arrow/decimal128`, `arrow/decimal256` and
`arrow/decimal/...` pass in full on 386.
- **amd64:** `arrow/decimal128`, `arrow/decimal256`, `arrow/decimal/...`
pass.
- `go vet` and `gofmt -l` are clean on the changed packages.

### Are there any user-facing changes?

Yes: decimal values convert correctly on 32-bit platforms. No API
changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants