Repository navigation
Add integration tests for Iceberg manifest bounds narrower than the column - #118364
hanfei1991 merged 7 commits into
Conversation
…column An Iceberg lower_bounds/upper_bounds payload is decoded by deserializeFieldFromBinaryRepr with column->insertData(str.data(), str.length()). For every fixed-width mapping that column is a ColumnVector or a ColumnDecimal, and both ignore the length: ColumnVector::insertData is data.emplace_back(unalignedLoad<T>(pos)) with the length parameter unnamed, and unalignedLoad is memcpy(&res, address, sizeof(res)). A bound declared in fewer bytes than the column's value is therefore read as sizeof(value) bytes, and the surplus bytes were never part of the serialized payload, so the range built from it is not the range the manifest declares. KeyCondition then prunes data files on it and rows go missing. Measured on a four-file IcebergLocal table of Int32 values above 100000, with field 1's bounds re-declared in two bytes: SELECT ... WHERE n > 50000 returned 0 of its 400 matching rows, 20 runs out of 20, because each truncated bound orders below 50000 and all four files were pruned. With this change the query returns 400 rows and prunes nothing. The check rejects only bounds that are too short, and deliberately keeps accepting bounds that are too long. Every currently released ClickHouse writes eight-byte bounds for four-byte columns, and ClickHouse#117072 was closed on the stated basis that ColumnVector::insertData ignores the buffer length so those bounds still decode. A symmetric length != width check would stop pruning for every table those releases wrote; the regression test pins that with an eight-byte bound on an Int32 column that must keep pruning. The predicate is asked of the column rather than the type on purpose. DataTypeUUID does not override isValueRepresentedByNumber, so a type-level gate would miss UUID although its column is a ColumnVector<UUID>; and DataTypeArray reports isValueUnambiguouslyRepresentedInFixedSizeContiguousMemoryRegion while leaving getSizeOfValueInMemory to throw, so a type-level width lookup could turn a manifest read into an exception. isFixedAndContiguous is true for exactly ColumnVector, ColumnDecimal and ColumnFixedString. FixedString is excluded because ColumnFixedString::insertData honours the length and zero-pads, so no byte outside the payload is read there. This leaves the two branches of the function asymmetric, which is intended. Iceberg serializes decimals as minimum-length two's-complement big-endian, so a short decimal payload is the normal encoding: measured, ClickHouse itself writes one- and two-byte bounds for a Decimal64(2) column. The decimal branch therefore rejects the opposite direction, str.size() > sizeof(NativeType). Fixed-width encodings reject too short; the variable-length minimal encoding rejects too long. Fixed at the decode rather than at the call sites, so all six callers inherit it, including the row lineage path that decodes with DataTypeUInt64. On nullopt every caller already falls back conservatively, so the guard can only ever reduce pruning. Related: ClickHouse#118299 Co-Authored-By: Claude Opus 5 <[email protected]>
The width guard in the previous commit exempted `FixedString`, on the grounds that `ColumnFixedString::insertData` honours the declared length and therefore reads nothing outside the payload. That is true and it is not sufficient, so the exemption is removed here. `ColumnFixedString::insertData` copies `length` bytes and then `memset`s the remaining `n - length` to zero. A bound declared in fewer bytes than the column still decodes to a value the writer never stored, and to a smaller one: on a `fixed[2]` column a one-byte upper bound `0x01` becomes `0x0100` while the file's true maximum can be `0x01ff`. The pair stays ordered, so the inversion check does not reach it, `KeyCondition` receives a range that ends below rows the file holds, and `mayBeTrueInRange` prunes a data file containing matching rows. Same wrong result as a numeric bound read past its payload, reached by zero filling instead. Dropping the clause makes the condition the general predicate rather than a special case. Every column `isFixedAndContiguous` admits ignores the declared length in one way or the other: `ColumnVector` and `ColumnDecimal` by reading `sizeof(value)` bytes past the payload, `ColumnFixedString` by zero filling the rest. All three are unusable when the bound is narrower than the value, and the one-sided comparison is unchanged, so a wider bound still decodes to the value the writer stored. `getIcebergType` rejects `FixedString`, so ClickHouse cannot write such a table and the regression test writes it with `pyiceberg` on the S3 backend, as the decimal test in the same file already does for the same reason. With field 1's `fixed[3]` bounds re-declared in two bytes, `SELECT f, n FROM icebergS3(...) WHERE f > '190'` read six of its seven matching rows before this change and reads seven after it. An over-long `fixed[N]` bound is left alone: `ColumnFixedString::insertData` throws `TOO_LARGE_STRING_SIZE` for it, which is pre-existing, fails loudly, and is a different question from pruning on an untrustworthy range. Related: ClickHouse#118299 Co-Authored-By: Claude Opus 5 <[email protected]>
The comment added with the guard claimed that "a wider bound still decodes to the value the writer stored". That is true for `ColumnVector` and `ColumnDecimal`, which read `sizeof(value)` bytes regardless of the declared length, and false for `ColumnFixedString`, the class the sentence before it introduces: `ColumnFixedString::insertData` opens with `if (length > n) throw Exception(ErrorCodes::TOO_LARGE_STRING_SIZE, ...)`, so an over-long `fixed[N]` bound does not decode at all. The last paragraph of the previous commit message says exactly that, so the comment contradicted it. The opening clause was imprecise for the same class for the opposite reason: `ColumnFixedString` does not ignore the declared length, it `memcpy`s `length` bytes and `memset`s the remaining `n - length` to zero. The replacement states only the non-obvious domain property the guard rests on, which holds for all three classes `isFixedAndContiguous` admits: a bound narrower than the column decodes to a value the writer never stored. Why the comparison is one-sided is backward compatibility with the widths released writers emit, which belongs in a commit message and is already stated at length in the previous one. Comment-only. With `///` lines stripped the file is byte-identical to the previous commit, so no behaviour, no generated code and no test result changes. Related: ClickHouse#118299 Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model reviewThree review rounds, the first two followed by a fix and a re-review. ❌ Blocker, fixed: a short
💡 Bounds wider than the column are still accepted on purpose. Every currently released ClickHouse |
|
Workflow [PR], commit [2b714aa] Summary: ✅
AI ReviewSummaryAdds regression coverage for Iceberg manifest bounds that are narrower than the current column width, plus a comment rewording in Final Verdict
LLVM Coverage ReportMeasured on commit 2b714aa.
Changed lines: Changed C/C++ lines covered: 5/5 (100.00%) · Uncovered code |
|
cc @hanfei1991 @kssenii, could you review this? An Iceberg manifest bound declared in fewer bytes than its column decodes to a value the writer never stored (bytes past the payload for a numeric column, zero fill for a |
|
TL;DR: the same The Iceberg spec serializes |
|
Agreed, not widening this pull request. I verified #118366 and posted the analysis there (#118366 (comment)): the per-half swap moves the bound into the right value space but not into the right order, because ClickHouse sorts |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline. |
CI finish ledger - 508b6f3Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
Session id: cron:our-pr-ci-monitor:20260906-073116 |
…ort-manifest-bound-width
…ort-manifest-bound-width Master extracted the bound deserialization out of `ManifestFileIterator.cpp` into `IcebergFieldParseHelpers`, and the extracted copy already carries everything this branch changed: the `compensate_rounding` parameter, the width guard on the unscaled bytes, the overflow guard on the widened bound (same comment), and the narrower-than-column guard - the last expressed as `haveMaximumSizeOfValue` / `getSizeOfValueInMemory` rather than `isFixedAndContiguous` / `sizeOfValueIfFixed`. So the branch's local definitions are dropped rather than kept: leaving them in made every call ambiguous between the header's declaration and the file-local one (four hard errors). What remains of the branch is its integration test.
CI finish ledger - 449c515Every failure below has an owner. All three are the same PR-caused cause, and no test failed at this head: the only failing job is
Mechanism, read at source. What clears it: any new Session id: cron:clickhouse-maint-slot-13:20260913-024100 |
|
@groeneai This PR only add tests, but according to the title of the PR I thought it's bug fix. Please change the title to show it's test only change. and Merge master and re-run CI. |
…ort-manifest-bound-width
|
Done: retitled to "Add integration tests for Iceberg manifest bounds narrower than the column", merged The diff is test only because the production guard reached The red at the previous head was not a test failure: that CI was a re-run (attempt 2) in which 126 of the 172 jobs came back |
`deserializeFieldFromBinaryRepr` returns no value for a fixed-width bound shorter than the column because `insertData` of a fixed-size column ignores the length and would read past the buffer. Iceberg stores a bound as its writer encoded it, so after a promotion (`int` -> `long`) a well formed manifest carries a bound narrower than the column is now. The comment above the `LOG_DEBUG` asserted the opposite, which contradicts the contract it relies on, and it named only the scale 38 decimal case among the reasons this branch is reached.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Description
Regression coverage only. The decoder guard this pull request was opened for reached
masterindependently in #115817 (083fda43bd9d5, "Do not read a partition bound past its buffer"), which is an ancestor of this branch after the master merge. What is left againstmasteris the integration test plus a three line comment rewording inManifestFileIterator.cpp, so nothing user visible changes here and the changelog entry is dropped.The tests cover the manifest file
lower_bounds/upper_boundspath inManifestFileIterator::processRow, which #115817 does not: its own test exercises manifest list partition bounds after aninttolongpromotion.test_iceberg_narrow_manifest_boundsre-declares anInt32bound in two bytes and asserts that the four data files stay unpruned forWHERE n > 50000, that aStringcolumn still well formed in the same manifest entry keeps pruning, and that the dropped bound names its column in the log. It also pins the asymmetry: an eight byte bound for a four byte column, which every released ClickHouse writes, must keep pruning.test_iceberg_narrow_fixed_manifest_boundsdoes the same forfixed[3], where a short bound is zero filled rather than completed from bytes outside the payload, so it stays ordered and the inverted bounds guard does not reach it.Each test starts from a control that fails if pruning stopped altogether.
Reported by
clickhouse-gh[bot]: #118299 (comment)Workflow [PR]
Sync PR [sync-upstream/pr/118364]
Version info
26.9.1.1592(included in26.9and later)