Skip to content

refactor(parquet): replace magic 8 literals with named constants#9751

Merged
alamb merged 2 commits into
apache:mainfrom
HippoBaro:no_magic_constant
Apr 21, 2026
Merged

refactor(parquet): replace magic 8 literals with named constants#9751
alamb merged 2 commits into
apache:mainfrom
HippoBaro:no_magic_constant

Conversation

@HippoBaro
Copy link
Copy Markdown
Contributor

@HippoBaro HippoBaro commented Apr 17, 2026

Which issue does this PR close?

Rationale for this change

The literal 8 appeared in two distinct roles throughout RleEncoder, RleDecoder, and their tests.

What changes are included in this PR?

Replacing each with a named constant makes the intent explicit and prevents the two meanings from being confused.

  • BIT_PACK_GROUP_SIZE = 8 The Parquet RLE/bit-packing hybrid format always bit-packs values in multiples of this count (spec: "we always bit-pack a multiple of 8 values at a time"). Every occurrence related to the staging buffer size, the repeat-count threshold that triggers the RLE decision, and the group-count arithmetic in bit-packed headers now uses this name.

  • u8::BITS (= 8, from std) Used wherever a bit-count is divided by 8 to obtain a byte-count (e.g. ceil(bit_width, u8::BITS as usize)). This is a bits-per-byte conversion, a fundamentally different concept from the packing-group size.

No behaviour change.

Are these changes tested?

All tests passing.

Are there any user-facing changes?

None.

The literal `8` appeared in two distinct roles throughout `RleEncoder`,
`RleDecoder`, and their tests. Replacing each with a named constant
makes the intent explicit and prevents the two meanings from being
confused.

* `BIT_PACK_GROUP_SIZE = 8`
  The Parquet RLE/bit-packing hybrid format always bit-packs values in
  multiples of this count (spec: "we always bit-pack a multiple of 8
  values at a time"). Every occurrence related to the staging buffer
  size, the repeat-count threshold that triggers the RLE decision, and
  the group-count arithmetic in bit-packed headers now uses this name.

* `u8::BITS` (= 8, from std)
  Used wherever a bit-count is divided by 8 to obtain a byte-count
  (e.g. `ceil(bit_width, u8::BITS as usize)`). This is a bits-per-byte
  conversion, a fundamentally different concept from the packing-group
  size.

No behaviour change.

Signed-off-by: Hippolyte Barraud <hippolyte.barraud@datadoghq.com>
@jhorstmann
Copy link
Copy Markdown
Contributor

Nice, looks like an improvement.

Copy link
Copy Markdown
Contributor

@etseidl etseidl left a comment

Choose a reason for hiding this comment

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

Looks great to me. Thanks for distinguishing different uses of 8 😄

@alamb
Copy link
Copy Markdown
Contributor

alamb commented Apr 21, 2026

Thanks @HippoBaro @jhorstmann and @etseidl

I took the liberty of merging up from main to resolve a conflict

Screenshot 2026-04-20 at 8 28 58 PM

@HippoBaro
Copy link
Copy Markdown
Contributor Author

HippoBaro commented Apr 21, 2026

Thank you 🙇

@alamb alamb merged commit 52ff63c into apache:main Apr 21, 2026
16 checks passed
@alamb
Copy link
Copy Markdown
Contributor

alamb commented Apr 21, 2026

🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parquet Changes to the parquet crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants