Skip to content

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

Open
HippoBaro wants to merge 1 commit intoapache:mainfrom
HippoBaro:no_magic_constant
Open

refactor(parquet): replace magic 8 literals with named constants#9751
HippoBaro wants to merge 1 commit intoapache: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>
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.

1 participant