Skip to content

fix(parquet): do not cache an ALP preset built from an empty first page - #11004

Open
Abdallah-Afifi wants to merge 1 commit into
apache:mainfrom
Abdallah-Afifi:fix/alp-empty-first-page-preset
Open

fix(parquet): do not cache an ALP preset built from an empty first page#11004
Abdallah-Afifi wants to merge 1 commit into
apache:mainfrom
Abdallah-Afifi:fix/alp-empty-first-page-preset

Conversation

@Abdallah-Afifi

@Abdallah-Afifi Abdallah-Afifi commented Sep 6, 2026

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

When a column chunk's first data page has no values, build_preset returns the fallback pair (exponent 0, factor 0). flush_buffer cached that for the whole chunk, and select_params short-circuits on a single-candidate preset, so every later page was stuck on an integer scale and every fractional value became an exception.

It's reachable from the normal write path, not just the encoder API: the column writer counts levels rather than values, so a first page of all nulls flushes an empty buffer.

Encoding 3000 values of i * 0.01 (raw f64 would be 24,000 bytes):

before after
values as the first page 3,808 3,808
values after an empty first page 31,258 3,808

Before the fix the chunk ends up bigger than leaving it unencoded. After, a leading empty page costs only its 7-byte header.

What changes are included in this PR?

flush_buffer only caches the preset when the page had values. put already branches on whether the preset is set, so the next page with values builds it.

The issue asks only for regression coverage and @alamb suggested the fix as a follow-up — this has both. Happy to split them if you'd rather.

Are these changes tested?

test_empty_first_page_does_not_poison_preset, which fails on main. Full cargo test -p parquet passes (1558 tests); fmt and clippy clean.

One thing I'd like a second opinion on: with the preset left unset, an all-null first page no longer arms the streaming path, so the second page takes the buffered path. The tests agree that's correct, but it's the part of this I'm least certain about.


Per the AI policy in CONTRIBUTING.md: I used Claude Code to trace the encoder and draft the fix and test. I've reviewed all of it and verified the behaviour myself — the numbers above are measured locally on this branch and on main.

When the first data page of a column chunk has no values, build_preset
falls back to exponent 0 / factor 0. flush_buffer cached that preset for
the whole chunk, so every fractional value in every later page became an
exception.

Only cache the preset once a page actually has values.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

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

The change looks clean to me, i'll wait for workflows to run and for someone else to eventually flag something more.

@Abdallah-Afifi

Copy link
Copy Markdown
Author

The change looks clean to me, i'll wait for workflows to run and for someone else to eventually flag something more.

I think the workflows need maintainer approval to start. Also, should I get on the rest of the subtasks related to ALP encoding? I would be happy to work on that. Thank you!

ryux1

This comment was marked as spam.

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.

[Parquet] Add ALP regression coverage for an empty first page

3 participants