Repository navigation
Use Iceberg uuid manifest bounds for pruning only when they are equal - #118380
Conversation
A SELECT over an Iceberg table with a uuid column could silently return fewer rows than the table holds, whenever the manifests were written by a conforming external engine (Spark, Trino, pyiceberg). No error, nothing above DEBUG. deserializeFieldFromBinaryRepr sent uuid down its raw-copy branch, where ColumnVector<UUID>::insertData is data.emplace_back(unalignedLoad<T>(pos)): no byte swap, and the length argument ignored. Two mismatches then stack. First, the value space. The Iceberg spec serializes a uuid value as 16 big-endian bytes, while both data paths convert (decodeParquetUUID and readColumnWithUUIDFromFixedBinaryData each reverse the two 8-byte halves on little-endian). So the bound decoded to a different value from the one the data path and the query constant produce. Second, the sort order, which is why the byte swap alone is not the fix. A conforming writer orders the lower/upper pair by unsigned big-endian byte comparison, but ClickHouse orders UUID by its second half, on purpose and documented. For A=...0001, C=...ffff-ffffffffffff and B=00000001-...0002 in one data file, pyiceberg declares lower=A, upper=B because byte-wise A < C < B. ClickHouse orders those A < B < C, so C sits above the upper bound while A < B still holds, meaning the inverted-pair guard does not fire either, and WHERE u = toUUID(C) prunes the very file that holds C. A correctly byte-swapped pair loses the same row. Since the declared pair is not an interval in the column's own order, the bound is dropped instead: the detect-and-drop shape this function already uses for decimal and Variant. The column contributes no pruning range and the file is read. Nothing is lost on ClickHouse-written tables, because canDumpIcebergStats returns false for UUID and dumpFieldToBytes has no UUID case, so ClickHouse never wrote a uuid bound. If pruning is wanted later, lower == upper is the only exactly sound case. The new integration test needs three values in one data file, since a one-row-per-file rig has lower == upper where a swap is exact and only the byte order is exercised. It also disables the Parquet statistics push-downs, which prune on the same UUID statistics of the data file itself: that is a separate defect, tracked as ClickHouse#118371. Closes: ClickHouse#118366 Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings), plus my own cold pass
Severity: ❌ blocker / The issue reporter agreed with this shape Session id: cron:clickhouse-review-slot-11:20260906-044000 |
|
Workflow [PR], commit [38fa997] Summary: ✅
AI ReviewSummaryThis PR correctly stops treating external Iceberg data-file Findings
Final Verdict
|
|
cc @scanhex12 @arsenmuk, could you review this? An Iceberg |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units11 translation units recompiled, 38 s compile time in total, 11 of them have a recent master baseline. |
CI finish ledger - 7b35b86Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
CI ran on the master merge pushed to this branch at 2026-09-08T03:45:40Z, so the failing head is Session id: cron:our-pr-ci-monitor:20260908-103036 |
|
Dear @scanhex12, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
…nifest-bounds Master moved the bound deserialization out of `ManifestFileIterator.cpp` into `IcebergFieldParseHelpers.cpp`, so the `UUID` guard now lives in the moved `deserializeFieldFromBinaryRepr`. It also covers the manifest list partition summaries that master decodes with the same function. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 6846ab5Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261009-213010 |
A `uuid` bound pair is ordered by unsigned byte comparison, which is not the order of ClickHouse `UUID`, so the pair as a whole is still unusable. When both bounds are equal, the pair describes the single value the column holds in that file, and decoding the 16 big-endian bytes gives that value exactly. Such a file is pruned again on that point, for example a single-row data file or a column that is constant within the file. The decoding loads both halves big-endian into the high and low words of the `UUID`, which is what the data path does for `FIXED_LEN_BYTE_ARRAY` uuid values. The test now asserts that the single-value file is pruned for a predicate on another value and kept for its own value. Requested in review: ClickHouse#118380 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Head branch was pushed to by a user without write access
| /// The spec serializes a `uuid` bound as 16 big-endian bytes and orders the pair by unsigned | ||
| /// byte comparison, while ClickHouse orders `UUID` by its second half. The two orders | ||
| /// disagree, so even a byte-swapped pair can exclude a value the file holds. | ||
| if (non_nullable_type->getTypeId() == TypeIndex::UUID) |
There was a problem hiding this comment.
This restores the exact-point case only for data-file min/max stats. ManifestListPruning::boundsOfPartitionFieldSummary still decodes UUID partition summaries via deserializeFieldFromBinaryRepr (ManifestListPruning.cpp:74-75), so the unconditional std::nullopt here turns even lower_bound == upper_bound into "no bounds" on the manifest-list path.
That regresses use_iceberg_partition_pruning for UUID partition keys: a manifest entry whose summary is an exact UUID point can no longer be skipped as a whole, even though the same point case is now considered sound for data-file pruning. Please reuse deserializeUUIDPointFromBinaryRepr (or factor the pair-aware logic out) in boundsOfPartitionFieldSummary as well, and add a focused test for a partitioned Iceberg table so this surface stays covered.
CI finish ledger - bb7be10Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261010-163006 |
|
Fixing PR for 02963_remote_read_small_buffer_size_bug (Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel)) created: #125092 |
ClickHouse#118380 added `deserializeUUIDPointFromBinaryRepr` for data file bounds while this branch carried its own 16-byte decoder. Keep a single decoder: the point helper now checks that both bounds are equal and delegates to `deserializeUUIDFromBinaryRepr`, and the manifest list pruner calls the point helper instead of repeating the equality check. With ClickHouse#118380 in the base, the example from ClickHouse#123961 (`WHERE u = ...` on a table that keeps the default `uuid` column metrics) returns its rows, so the test asserts it too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #118366
Related: #118371, #118364
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed Iceberg min/max pruning skipping a data file that holds matching rows, when the file's
uuidbound was written by an external engine (Spark, Trino, pyiceberg). Such a bound now prunes only when its lower and upper bounds are equal. This fixes the Iceberg manifest bounds only: theuuidstatistics of the Parquet data file itself are a separate defect, so a query at default settings can still miss rows. Closes #118366.Description
A
uuidmanifest bound cannot be aRangeover a ClickHouseUUIDcolumn, for two reasons:deserializeFieldFromBinaryReprraw-copies them intoColumnVector<UUID>, whoseinsertDatadoes not swap, while both data paths do (decodeParquetUUID,readColumnWithUUIDFromFixedBinaryData), so the bound differs from the value a query constant produces.UUIDby its second half (docs/reference/data-types/uuid.mdx), so the declared pair is not an interval in the column's own order.Because of 2, applying the byte swap is necessary but not sufficient. Measured with pyiceberg 0.11.1 on one data file holding
the writer declares
lower = A,upper = B(byte-wiseA < C < B). ClickHouse orders theseA < B < C:Cis above the upper bound, yetA < Bholds, so the inverted-pair guard does not fire. On masterWHERE u = toUUID(C)returns nothing, as does a correctly byte-swapped implementation, though the file holds the row.So the pair is dropped, as for
decimalandVariant, unless its bounds are equal: that point, decoded with the swap, is exactly the value the file holds. ClickHouse-written tables lose nothing:canDumpIcebergStatsreturns false forUUID.Two related surfaces are deliberately untouched. The same root cause in the Parquet reader's
uuidstatistics is #118371, which prunes these files' row groups too, so a default-settings query still missesC. Auuidpartition column is #123961: its values are never decoded, so filtering on it throws. The manifest-list pruner shares this helper, so on such a table master's silent row loss (every manifest pruned) becomes that error; an equal-bounds summary cannot help, as the files it keeps throw too.Workflow [PR]
Sync PR [sync-upstream/pr/118380]
Version info
26.10.1.2221-master(included in26.10and later)