Skip to content

fix(parquet/pqarrow): fix Decimal256 sign extension #711

Merged
zeroshade merged 1 commit intoapache:mainfrom
dimakuz:fix/decimal256-parquet-truncation
Mar 13, 2026
Merged

fix(parquet/pqarrow): fix Decimal256 sign extension #711
zeroshade merged 1 commit intoapache:mainfrom
dimakuz:fix/decimal256-parquet-truncation

Conversation

@dimakuz
Copy link
Contributor

@dimakuz dimakuz commented Mar 13, 2026

bigEndianToDecimal256 in column_readers.go has a bug in the partial-word sign extension path: it shifts by wordLen (byte count) instead of wordLen*8 (bit count).

Rationale for this change

Found while reading a parquet file w/ a certain Decimal256 using go-arrow

What changes are included in this PR?

fix for bigEndianToDecimal256

Are these changes tested?

Yes, round-trip test included

Are there any user-facing changes?

None

…imal256

bigEndianToDecimal256 in column_readers.go has a bug in the partial-word
sign extension path: it shifts by wordLen (byte count) instead of
wordLen*8 (bit count). This is a copy-paste error from
bigEndianToDecimal128 which correctly uses `* 8`.

The bug corrupts negative Decimal256 values when the Parquet byte width
is not a multiple of 8. For example, Decimal256 with precision 40 uses
17 bytes (DecimalSize(40) = 17). Reading such values back splits into
iterations of 8 + 8 + 1 bytes, and the 1-byte partial word triggers the
broken shift, mangling the sign extension.
@dimakuz dimakuz requested a review from zeroshade as a code owner March 13, 2026 15:39
@zeroshade zeroshade merged commit efc538a into apache:main Mar 13, 2026
26 of 27 checks passed
@dimakuz dimakuz deleted the fix/decimal256-parquet-truncation branch March 13, 2026 18:35
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