Repository navigation
fix: Count parquet size statistics once when the dictionary falls back - #120027
Merged
alexey-milovidov merged 6 commits intoSep 19, 2026
Merged
alexey-milovidov merged 6 commits into
alexey-milovidov merged 6 commits into
Conversation
When the dictionary grows past output_format_parquet_max_dictionary_size the writer discards everything it has encoded and restarts the column chunk without a dictionary. It reset the offsets but not what the discarded pass had accumulated, so unencoded_byte_array_data_bytes, the repetition and definition level histograms and the page and chunk statistics were all counted twice. A String column of toString(number) over numbers(200000) reported 1678196 unencoded bytes where the values hold 1088890. The reader uses that field to size its reads (Reader::estimateAverageStringLengthPerRow), so an inflated value makes it over-estimate the column. ParquetMetadata now also reports size_statistics per column chunk, which is what makes the field observable at all.
This was referenced Sep 14, 2026
02718_parquet_metadata_format dumps the whole schema with SELECT *, in two places, so adding size_statistics to the output changes its reference.
Contributor
|
Workflow [PR], commit [31299b3] Summary: ❌
AI ReviewSummaryThis PR fixes Final Verdict
LLVM Coverage ReportMeasured on commit 31299b3.
Changed lines: Changed C/C++ lines covered: 57/58 (98.28%) · Uncovered code |
The test wrote 05176_fallback.parquet into user_files under a fixed name, so the runs the flaky check starts in parallel truncated and read each other's file, and the test failed with an empty file or timed out. It now writes into CLICKHOUSE_TMP under a name derived from CLICKHOUSE_DATABASE, which is unique per run, and uses clickhouse-local rather than the shared user_files directory.
SizeStatistics is optional in the footer, and arrow only builds one when __isset.size_statistics is set, so a file written before it existed has none. Reporting the tuple unconditionally made that indistinguishable from a column whose histograms are legitimately empty, which for a nested column is wrong metadata. ParquetMetadata now reports have_size_statistics next to the tuple, the way it already reports have_statistics. 02718_parquet_metadata_format reads fixtures that predate the field and now pins it as false for them.
The test only wrote a flat String column, where max_rep and max_def are 0, so the histograms stayed empty and nothing checked that a discarded dictionary pass stops leaking into them. It now also writes an Array(Nullable(String)), which has both kinds of level. The histograms are filled a page at a time, so the leak only appears when the dictionary outgrows its limit after some pages have been written, which is what the small data page size arranges. Without the reset the column reports [25854,19389] and [6464,19390,19389] where it holds [20000,15000] and [5000,15000,15000].
The fields were described by the shape of the column, saying the histograms are empty when it has no levels of that kind. ParquetMetadata reads files from any writer, and one of the fixtures in 02718_parquet_metadata_format has a flat required column whose histograms are [5] and [5] rather than empty. What the arrays hold is whatever the footer recorded.
alexey-milovidov
approved these changes
Sep 19, 2026
Merged
via the queue into
ClickHouse:master
with commit Sep 19, 2026
3698bff
175 of 177 checks passed
1 task
alexey-milovidov
pushed a commit
to groeneai/ClickHouse
that referenced
this pull request
Sep 19, 2026
groeneai
added a commit
to groeneai/ClickHouse
that referenced
this pull request
Sep 21, 2026
Resolves one conflict in src/Processors/Formats/Impl/Parquet/Write.cpp. Master's ClickHouse#120027 (061fa0b) independently added the same page_statistics.clear() / total_statistics.clear() at the dictionary fallback site, plus reset_size_statistics(); its side is a strict superset of the branch's hunk, so master's version is taken verbatim and this branch no longer carries that hunk. KeyCondition.cpp/h and Reader.cpp auto-merged. Verified by hand that the bounds_may_hide_nan check still sits after master's NaN-bound handling in the restructured FUNCTION_IN_RANGE arm, where key_column is still element.getKeyColumn(), so the mask stays indexed by the source key column position it is built for.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Related: #119300
Related: #120028
When the dictionary grows past
output_format_parquet_max_dictionary_size,writeColumnImpldiscards what it has encoded and restarts the column chunk without one. It reset the offsets but not
what the discarded pass had accumulated, so the size statistics counted it twice. The reader sizes
its reads from
unencoded_byte_array_data_bytes(Reader::estimateAverageStringLengthPerRow).ParquetMetadatanow also reportssize_statisticsper column chunk, withhave_size_statisticsbeside it, which is what makes the field observable at all.
toString(number),numbers(200000)repeat(toString(number), 300),numbers(20000)Array(Nullable(String))repetition histogram[25854,19389][20000,15000][20000,15000][6464,19390,19389][5000,15000,15000][5000,15000,15000]Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
Parquetwriting size statistics twice for a column chunk that falls back from dictionary encoding, which madeunencoded_byte_array_data_bytesand the level histograms too large. TheParquetMetadataformat now also reportssize_statisticsfor each column chunk.