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

@HippoBaro HippoBaro commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

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.

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

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

@alamb

alamb commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

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

HippoBaro commented Apr 21, 2026

Copy link
Copy Markdown
Contributor Author

Thank you 🙇

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

alamb commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

🚀

Rich-T-kid pushed a commit to Rich-T-kid/arrow-rs that referenced this pull request Jun 2, 2026
…pache#9751)

# Which issue does this PR close?

- Spawn off from apache#9653 
- Contributes to apache#9731

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

Signed-off-by: Hippolyte Barraud <hippolyte.barraud@datadoghq.com>
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
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