Skip to content

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

Closed
dimakuz wants to merge 1 commit intoapache:mainfrom
dimakuz:fix/decimal256-parquet-truncation
Closed

fix(parquet/pqarrow): fix Decimal256 sign extension #710
dimakuz wants to merge 1 commit intoapache:mainfrom
dimakuz:fix/decimal256-parquet-truncation

Conversation

@dimakuz
Copy link
Contributor

@dimakuz dimakuz commented Mar 13, 2026

…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.

Rationale for this change

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

…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:37
@dimakuz dimakuz closed this Mar 13, 2026
@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.

1 participant