Repository navigation
Ignore inverted Parquet statistics instead of failing the query - #128336
Conversation
polars 0.20 writes the statistics of UINT_32 / UINT_64 columns in signed order while declaring TYPE_ORDER, so a column chunk or page holding values on both sides of 2^31 / 2^63 has min_value > max_value. The native reader rejected the whole query with INCORRECT_DATA at four places: row group pruning, page pruning by the column index, the TopN row group shortcut and `optimize_min_max_from_files`. `adjustRangeFromIndexIfNeeded` now reports an inverted range instead of throwing, and every caller takes the fallback it already takes for other unusable statistics: a whole-universe range for row group and page pruning, no shortcut for TopN, reading the data for min/max. Nothing that was read before is pruned now, so results can only get more complete. This is sufficient for the polars case: if all values of a chunk share the top bit, signed and unsigned order agree and the statistics are correct; otherwise the signed minimum has the top bit set and the signed maximum does not, so the unsigned range is always inverted and gets ignored. The test builds the polars footer in place: a ClickHouse-written file with two row groups whose first row group gets its Statistics and ColumnIndex min/max swapped, so the second row group still proves that valid statistics keep pruning. Closes ClickHouse#128302 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding) plus my own review (2 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261031-015109 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261031-010400 |
|
cc @al13n321 @scanhex12, could you review this and add the |
|
Workflow [PR], commit [0b4da4c] Summary: ✅
AI ReviewSummaryThe change treats inverted Parquet statistics as unavailable for row-group pruning, page pruning, TopN shortcuts, and Missing context / blind spots
Final VerdictStatus: ✅ Approve. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units17 translation units recompiled, 167 s compile time in total, 17 of them have a recent master baseline. |
The corpus from ClickHouse#128305 records `INCORRECT_DATA` for the `WHERE u64 > 9223372036854775807` checks of the polars 0.20.31 files, whose UInt64 statistics are written in signed order and are inverted. With inverted statistics ignored, these 9 checks now return the count the writer itself reads back (`ok`). No other line of the corpus tests (05359, 05473-05478) changes. The master merge before this commit brings in the corpus, which did not exist on the branch; without it the merge queue fails 05474. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The inversion check ran on the decoded range. Decoding leaves a bound at infinity when the requested type cannot hold it, so under a type hint the inverted polars statistics can stop looking inverted: a UInt64 chunk with min_value 2^63 and max_value 1 read as `DateTime` decodes to [-inf, 1], and row group and page pruning dropped the row that the read saturates to the `DateTime` maximum (`WHERE u64 > toDateTime(100)` returned nothing; it returns that row with the pruning disabled). Same on master. `IntConverter` now compares the stored values in the column's sort order (signed or unsigned per the logical type), and the row group and column index paths ignore statistics that are inverted there. The TopN and min/max-from-statistics paths already give up when a bound does not decode. The check on the decoded range stays for the other converters. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@fm4v the queue failed on I also added c61dbb6: read with a |
…p-k-file-order Resolves the conflict with ClickHouse#128336 in `Reader.h`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ClickHouse#128336 ignores inverted Parquet statistics, so the 9 polars 0.20.31 `WHERE u64 > 9223372036854775807` checks that ClickHouse#128305 recorded as `INCORRECT_DATA` now return the count the writer reads back. The merge queue landed ClickHouse#128336 without its commit that updated these rows (a87c586), so master fails this test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #128302
Related: #128305
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The native Parquet reader now ignores column chunk and page statistics whose
min_valueis greater thanmax_value(for example theUInt32/UInt64statistics that polars 0.20 writes in signed order) instead of failing the query withINCORRECT_DATA, so such files can be filtered and aggregated. Closes #128302.Description
polars 0.20 writes
UINT_32/UINT_64statistics in signed order while declaringTYPE_ORDER, so a row group or page with values on both sides of 2^31 / 2^63 hasmin_value > max_value. The native reader rejected the query withINCORRECT_DATAat four places: row group pruning, page pruning by the column index, the TopN row group shortcut andoptimize_min_max_from_files; the only workaround was disabling the optimization for the whole query.Reader::adjustRangeFromIndexIfNeedednow returnsfalsefor an inverted range instead of throwing, and each caller takes the fallback it already uses for other unusable statistics: no pruning for that row group or page, no TopN shortcut, reading the data formin/max. Integer statistics are also checked in their stored order before decoding: read asDateTime, the minimum 2^63 decodes to no bound, the decoded range[-inf, 1]no longer looked inverted, and row group and page pruning silently dropped the row (also on master). Nothing that was read before is pruned now.It is enough for the polars files: if all values of a chunk share the top bit, signed and unsigned order agree; otherwise the signed minimum has the top bit set and the signed maximum does not, so the unsigned range is inverted and ignored.
Validation: the new test writes a two-row-group file and swaps
min_value/max_valueof the first row group in the footer statistics and the column index (the polars bytes). On master all four paths fail withINCORRECT_DATAforUInt64andUInt32and theDateTimereads return nothing; with the fix the results are correct and the second row group is still pruned by its valid statistics. The 9 polars 0.20.31 rows of05474_parquet_corpus_writers.reference(#128305) that recordedINCORRECT_DATAnow return the count the writer reads back.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/128336]
Version info
26.11.1.1015-master(included in26.11and later)