Skip to content

refactor(parquet): simplify guarded row-group byte-limit arithmetic - #11269

Merged
etseidl merged 1 commit into
apache:mainfrom
HippoBaro:simpler_rg_guard
Sep 28, 2026
Merged

etseidl merged 1 commit into
apache:mainfrom
HippoBaro:simpler_rg_guard

Conversation

@HippoBaro

@HippoBaro HippoBaro commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

The row-group byte-limit calculation already runs under a guard that ensures the buffered row count is nonzero. Using checked division for that first calculation repeats the guard, while a separate zero-average filter and fallback value make the remaining-budget calculation more complicated than necessary.

Simplify the arithmetic while preserving the existing split and flush decisions.

What changes are included in this PR?

  • Calculate average row bytes directly under the existing nonzero buffered-row guard.
  • Divide the remaining byte budget by that average using checked_div.
  • Remove the separate zero-average filter and redundant fallback value.

Are these changes tested?

All tests passing.

Are there any user-facing changes?

No.

Use the existing nonzero buffered-row guard to calculate average row
bytes directly. Divide the remaining byte budget by that average with
`checked_div`, replacing the separate zero-average filter and redundant
fallback value.

Preserve the existing split and flush behavior, including skipping the
estimate-based split when average row bytes round down to zero. Keep
the byte-budget calculation an estimate rather than a hard bound on
serialized row-group size.

Signed-off-by: Hippolyte Barraud <[email protected]>

@Rich-T-kid Rich-T-kid 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.

net positive in my opinion.

👍

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

Thanks @HippoBaro. Took me awhile...I should have read the PR description more closely 😅

Comment on lines +404 to +405
let avg_row_bytes = current_bytes / buffered_rows;
if let Some(rows_that_fit) = (max_bytes - current_bytes).checked_div(avg_row_bytes)

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.

This looks right. buffered_rows is always > 0, so we enter the branch only if avg_row_bytes > 0 due to the filter. Now we instead rely on checked_div for the avg_row_bytes > 0 condition.

@etseidl

etseidl commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Thanks for the review @Rich-T-kid.

@etseidl
etseidl merged commit c6eb173 into apache:main Sep 28, 2026
29 checks passed
@alamb alamb added the development-process Internal changes; PRs with this label are excluded from changelog label Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

development-process Internal changes; PRs with this label are excluded from changelog parquet parquet crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants