Repository navigation
Feat(parquet) : Introduce support for optionally writing Distinct Values to statistics #25576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jayzhan211
merged 10 commits into
apache:main
from
Rich-T-kid:rich-T-kid/Introduce-roundtrip-ndv
Oct 9, 2026
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b9df4d6
feat: use StatisticsConverter::row_group_distinct_counts for NDV extr…
Rich-T-kid 3ad4cd8
feat: add write_row_group_number_distinct_values parquet config option
Rich-T-kid 0dbb380
fix: change NDV row-group precision from Exact to Inexact and fix CI
Rich-T-kid 568a166
fix: restore Exact precision for single-row-group NDV and round-trip …
Rich-T-kid aa3c063
fix
Rich-T-kid 3ed9076
fix: update clickbench.slt to reflect Inexact NDV physical plan
Rich-T-kid e61aeb2
address review
Rich-T-kid 7450603
fix: use proto tag 40 for write_row_group_number_distinct_values
Rich-T-kid efeb978
fix proto issue
Rich-T-kid 233a1c4
fix: regenerate proto to sync write_row_group_number_distinct_values …
Rich-T-kid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: add write_row_group_number_distinct_values parquet config option
Add a new ParquetOptions field that enables writing NDV (number of distinct values) statistics per column when writing parquet files, backed by the new arrow-rs WriterPropertiesBuilder::set_write_row_group_number_distinct_values API. Includes proto serialization and a SQL logic roundtrip test.
- Loading branch information
commit 3ad4cd80e8d9bfda0de712ff3e6f8c7d08676dc4
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| # Roundtrip test for write_row_group_number_distinct_values. | ||
| # | ||
| # Writes a parquet file with NDV tracking enabled and verifies that | ||
| # DataFusion reads back the distinct count from the parquet statistics. | ||
|
|
||
| statement ok | ||
| set datafusion.explain.physical_plan_only = true; | ||
|
|
||
| statement ok | ||
| set datafusion.explain.show_statistics = true; | ||
|
|
||
| statement ok | ||
| set datafusion.execution.collect_statistics = true; | ||
|
|
||
| ###### | ||
| # Without the option (default), distinct counts are absent. | ||
| ###### | ||
|
|
||
| query I | ||
| COPY (VALUES (1), (2), (3), (1)) | ||
| TO 'test_files/scratch/parquet_ndv_write/no_ndv.parquet' | ||
| STORED AS PARQUET; | ||
| ---- | ||
| 4 | ||
|
|
||
| statement ok | ||
| CREATE EXTERNAL TABLE no_ndv | ||
| STORED AS PARQUET | ||
| LOCATION 'test_files/scratch/parquet_ndv_write/no_ndv.parquet'; | ||
|
|
||
| # Distinct count should be absent (no NDV written to the file) | ||
| query TT | ||
| EXPLAIN SELECT * FROM no_ndv; | ||
| ---- | ||
| physical_plan DataSourceExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/sqllogictest/test_files/scratch/parquet_ndv_write/no_ndv.parquet]]}, projection=[column1], file_type=parquet, statistics=[Rows=Exact(4), Bytes=Exact(32), [(Col[0]: Min=Exact(Int64(1)) Max=Exact(Int64(3)) Null=Exact(0) ScanBytes=Exact(32))]] | ||
|
|
||
| statement ok | ||
| DROP TABLE no_ndv; | ||
|
|
||
| ###### | ||
| # With write_row_group_number_distinct_values = true, distinct count is written | ||
| # and read back as Exact (single row group). | ||
| ###### | ||
|
|
||
| statement ok | ||
| set datafusion.execution.parquet.write_row_group_number_distinct_values = true; | ||
|
|
||
| query I | ||
| COPY (VALUES (1), (2), (3), (1)) | ||
| TO 'test_files/scratch/parquet_ndv_write/with_ndv.parquet' | ||
| STORED AS PARQUET; | ||
| ---- | ||
| 4 | ||
|
|
||
| statement ok | ||
| CREATE EXTERNAL TABLE with_ndv | ||
| STORED AS PARQUET | ||
| LOCATION 'test_files/scratch/parquet_ndv_write/with_ndv.parquet'; | ||
|
|
||
| # Distinct count should now be Exact(3) — 3 distinct values among 4 rows | ||
| query TT | ||
| EXPLAIN SELECT * FROM with_ndv; | ||
| ---- | ||
| physical_plan DataSourceExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/sqllogictest/test_files/scratch/parquet_ndv_write/with_ndv.parquet]]}, projection=[column1], file_type=parquet, statistics=[Rows=Exact(4), Bytes=Exact(32), [(Col[0]: Min=Exact(Int64(1)) Max=Exact(Int64(3)) Null=Exact(0) Distinct=Exact(3) ScanBytes=Exact(32))]] | ||
|
|
||
| statement ok | ||
| DROP TABLE with_ndv; | ||
|
|
||
| # Reset settings | ||
| statement ok | ||
| RESET datafusion.execution.parquet.write_row_group_number_distinct_values; | ||
|
|
||
| statement ok | ||
| RESET datafusion.explain.show_statistics; | ||
|
|
||
| statement ok | ||
| RESET datafusion.explain.physical_plan_only; | ||
|
|
||
| statement ok | ||
| RESET datafusion.execution.collect_statistics; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.