Skip to content

fix(parquet): preserve distinct-count invalidation across page flushes - #11264

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

etseidl merged 1 commit into
apache:mainfrom
HippoBaro:distinct_count

Conversation

@HippoBaro

@HippoBaro HippoBaro commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Caller-supplied distinct counts describe an individual write, while column metadata describes the entire column chunk. Once earlier data makes the column-wide count unknown, a later write cannot safely restore that count using only its own batch statistics.

What changes are included in this PR?

  • Use column and page metrics to detect prior data instead of the page-local encoder value count.
  • Accept a caller-supplied distinct count only when there is no prior data in the column chunk.
  • Update the regression test to force a page boundary and verify that the column-wide distinct count remains absent while page statistics remain correct.

Are these changes tested?

Yes. The updated regression covers distinct-count invalidation across a page flush and checks that page-level statistics are preserved.

Are there any user-facing changes?

There are no public API changes.

Caller-supplied distinct counts describe a write, while column metadata
describes the whole column chunk. Once prior data lacks a usable
distinct count, a later write cannot safely restore one.

The writer currently checks `self.encoder.num_values() == 0` to detect
whether data was already written. That count resets on page flush, so a
later write can incorrectly replace an unknown column-wide count with
its own batch count.

Use column and page metrics instead to detect prior data, and only
accept a supplied distinct count for the first write.

Update the regression test to force a page boundary and verify that the
column-wide distinct count remains absent while page statistics stay
correct.

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

@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. I verified the test fails on main.

cc @Rich-T-kid who may have an opinion here

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

thanks for the cc @etseidl
makes sense to me. This is a neat fix, thanks @HippoBaro

@etseidl

etseidl commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Thanks again @HippoBaro and @Rich-T-kid.

@etseidl
etseidl merged commit a01d14f into apache:main Sep 28, 2026
29 checks passed
@Jefffrey Jefffrey added the bug Squash those bugs label Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Squash those bugs parquet parquet crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parquet: page flushes can restore an invalid column-chunk distinct count

4 participants