Skip to content

fix: Avoid incorrect min/max stats for BYTE_ARRAY decimals of unequal byte lengths - #10861

Merged
alamb merged 1 commit into
apache:mainfrom
neilconway:neilc/fix-byte-array-decimal-stats
Aug 27, 2026
Merged

fix: Avoid incorrect min/max stats for BYTE_ARRAY decimals of unequal byte lengths#10861
alamb merged 1 commit into
apache:mainfrom
neilconway:neilc/fix-byte-array-decimal-stats

Conversation

@neilconway

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

compare_greater_byte_array_decimals sign-extends the shorter value when comparing two's-complement byte arrays of different lengths. When the longer value's extra leading bytes were all sign-extension bytes, the final comparison dropped exactly one byte from each side and then lexicographically compares the remaining byte slices. This is incorrect when the byte slices are of different lengths.

This can result in exact row-group/page stats with incorrect values (e.g., swapped min and max).

Align the tails by skipping the length difference on the longer side only, matching parquet-mr.

What changes are included in this PR?

  • Fix bug in byte array comparison
  • Add tests

Are these changes tested?

Yes; new tests added.

Are there any user-facing changes?

No.

AI usage

Bug found and fix written with Claude Code Fable 5; I reviewed and understand the resulting code.

`compare_greater_byte_array_decimals` sign-extends the shorter value when
comparing two's-complement byte arrays of different lengths. When the
longer value's extra leading bytes were all sign-extension bytes, the
final comparison dropped exactly one byte from each side and then
lexicographically compares the remaining byte slices. This is incorrect
when the byte slices are of different lengths.

This can result in exact row-group/page stats with incorrect values
(e.g., swapped min and max).

Align the tails by skipping the length difference on the longer side
only, matching parquet-mr.

Closes apache#10860.
@github-actions github-actions Bot added the parquet Changes to the parquet crate label Aug 26, 2026
@Jefffrey Jefffrey added the bug label Aug 27, 2026
@alamb

alamb commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

FYI @etseidl

@etseidl etseidl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this dizzying 😅. Thanks @neilconway!

@alamb
alamb merged commit 4cc296b into apache:main Aug 27, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug parquet Changes to the parquet crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parquet writer produces wrong min/max statistics for BYTE_ARRAY DECIMAL columns

4 participants