Skip to content

[Parquet] Implement num distinct values for parquet writer - #10654

Merged
etseidl merged 6 commits into
apache:mainfrom
Rich-T-kid:rich-t-kid/parquet-write-nvd
Aug 19, 2026
Merged

[Parquet] Implement num distinct values for parquet writer#10654
etseidl merged 6 commits into
apache:mainfrom
Rich-T-kid:rich-t-kid/parquet-write-nvd

Conversation

@Rich-T-kid

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

see #8608, #10650 & apache/datafusion#24114

What changes are included in this PR?

Adds set_write_row_group_number_distinct_values to WriterProperties, which when enabled causes the ArrowWriter to track the exact number of distinct non-null values per column across the full row group and write it into the column chunk statistics footer as distinct_count. Tracking is implemented by hashing each non-null value using XxHash64 into a per-column HashSet that persists across batch writes and is finalized in close(). The flag defaults to false so there is no impact on existing writers.

Are these changes tested?

yes, see test.

Are there any user-facing changes?

yes, users will not be able to write distinct_count meta data to parquet files.

@github-actions github-actions Bot added the parquet Changes to the parquet crate label Aug 12, 2026
@Rich-T-kid
Rich-T-kid force-pushed the rich-t-kid/parquet-write-nvd branch from cda6e4a to 5111139 Compare August 12, 2026 13:09
Comment thread parquet/src/file/properties.rs
@Rich-T-kid
Rich-T-kid force-pushed the rich-t-kid/parquet-write-nvd branch from 5111139 to 5676cca Compare August 12, 2026 13:16
@etseidl etseidl changed the title [Parquet] Implement nvd for parquet writer [Parquet] Implement num distinct values for parquet writer Aug 12, 2026
@Rich-T-kid
Rich-T-kid requested a review from etseidl August 14, 2026 13:54
Comment thread parquet/src/arrow/arrow_writer/mod.rs
Comment thread parquet/src/arrow/arrow_writer/mod.rs
Comment thread parquet/src/arrow/arrow_writer/mod.rs
@Rich-T-kid
Rich-T-kid force-pushed the rich-t-kid/parquet-write-nvd branch from 48c40aa to d1fa404 Compare August 14, 2026 14:27
@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

@etseidl could you please take a look at this when you get a chance

@etseidl

etseidl commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Yes, sorry @Rich-T-kid, still catching up from some time off 😅

@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

Yes, sorry @Rich-T-kid, still catching up from some time off 😅

@etseidl no worries! sorry about the ping

@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 @Rich-T-kid, I think this looks good.

Am I right in thinking this will only work for the arrow writer (i.e. the row-based API will not populate the distinct count)? If so, we might want to note that in the docs.

@etseidl

etseidl commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

@etseidl no worries! sorry about the ping

And feel free to ping me any time, it's no bother...I'm scatterbrained 😅

@Rich-T-kid
Rich-T-kid force-pushed the rich-t-kid/parquet-write-nvd branch from d1fa404 to 4db4725 Compare August 18, 2026 22:39
@github-actions github-actions Bot added arrow Changes to the arrow crate arrow-array labels Aug 18, 2026
@Rich-T-kid
Rich-T-kid force-pushed the rich-t-kid/parquet-write-nvd branch from 4db4725 to 62d6619 Compare August 18, 2026 22:41
@github-actions github-actions Bot removed arrow Changes to the arrow crate arrow-array labels Aug 18, 2026
@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

Thanks @Rich-T-kid, I think this looks good.

Am I right in thinking this will only work for the arrow writer (i.e. the row-based API will not populate the distinct count)? If so, we might want to note that in the docs.

thanks @etseidl. 62d6619 should address your comments

@etseidl

etseidl commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

I'll give this a day before merging to allow others to take a look if they wish. Thanks again!

@etseidl

etseidl commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Hearing no objections, the PR is merged. Thanks @Rich-T-kid

@etseidl
etseidl merged commit 3320517 into apache:main Aug 19, 2026
18 checks passed
Rich-T-kid added a commit to Rich-T-kid/arrow-rs that referenced this pull request Aug 26, 2026
)

# Which issue does this PR close?

- Closes apache#8608.
- Closes apache#10650

# Rationale for this change

see apache#8608, apache#10650 & apache/datafusion#24114

# What changes are included in this PR?
Adds `set_write_row_group_number_distinct_values` to WriterProperties,
which when enabled causes the ArrowWriter to track the exact number of
distinct non-null values per column across the full row group and write
it into the column chunk statistics footer as `distinct_count`. Tracking
is implemented by hashing each non-null value using XxHash64 into a
per-column HashSet<u64> that persists across batch writes and is
finalized in `close()`. **The flag defaults to false so there is no
impact on existing writers.**

# Are these changes tested?
yes, see test.

# Are there any user-facing changes?
yes, users will not be able to write `distinct_count` meta data to
parquet files.
Rich-T-kid added a commit to Rich-T-kid/arrow-rs that referenced this pull request Aug 28, 2026
)

# Which issue does this PR close?

- Closes apache#8608.
- Closes apache#10650

# Rationale for this change

see apache#8608, apache#10650 & apache/datafusion#24114

# What changes are included in this PR?
Adds `set_write_row_group_number_distinct_values` to WriterProperties,
which when enabled causes the ArrowWriter to track the exact number of
distinct non-null values per column across the full row group and write
it into the column chunk statistics footer as `distinct_count`. Tracking
is implemented by hashing each non-null value using XxHash64 into a
per-column HashSet<u64> that persists across batch writes and is
finalized in `close()`. **The flag defaults to false so there is no
impact on existing writers.**

# Are these changes tested?
yes, see test.

# Are there any user-facing changes?
yes, users will not be able to write `distinct_count` meta data to
parquet files.
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.

Populate and read distinct_count from parquet column statistics Implement (optional) distinct count population in Parquet statistics

2 participants