Skip to content

Add integration tests for Iceberg manifest bounds narrower than the column - #118364

Merged
hanfei1991 merged 7 commits into
ClickHouse:masterfrom
groeneai:groeneai-iceberg-short-manifest-bound-width
Sep 16, 2026
Merged

hanfei1991 merged 7 commits into
ClickHouse:masterfrom
groeneai:groeneai-iceberg-short-manifest-bound-width

Conversation

@groeneai

@groeneai groeneai commented Sep 6, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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 master independently 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 against master is the integration test plus a three line comment rewording in ManifestFileIterator.cpp, so nothing user visible changes here and the changelog entry is dropped.

The tests cover the manifest file lower_bounds / upper_bounds path in ManifestFileIterator::processRow, which #115817 does not: its own test exercises manifest list partition bounds after an int to long promotion.

test_iceberg_narrow_manifest_bounds re-declares an Int32 bound in two bytes and asserts that the four data files stay unpruned for WHERE n > 50000, that a String column 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_bounds does the same for fixed[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

  • Merged into: 26.9.1.1592 (included in 26.9 and later)

groeneai and others added 3 commits September 5, 2026 23:27
…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]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-review-bot PR origin: review-bot finding on a groeneai PR labels Sep 6, 2026
@groeneai

groeneai commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review

Three review rounds, the first two followed by a fix and a re-review.

❌ Blocker, fixed: a short fixed[N] bound was exempted from the new width check.
ColumnFixedString::insertData honours the declared length, so it reads nothing outside the payload,
but it zero-fills the rest: a one-byte upper bound 0x01 on a fixed[2] column decodes as 0x0100
while the file's maximum can be 0x01ff, the pair stays ordered so the inverted-bounds guard does not
catch it, and the file is pruned with matching rows in it. The check is now the general predicate over
every fixed-width column, which is also the smaller condition. A regression test writes a fixed[3]
table with pyiceberg and pins it.

⚠️ Major, fixed: the guard's comment claimed that a wider bound always decodes. That holds for
ColumnVector and ColumnDecimal and not for ColumnFixedString, which throws
TOO_LARGE_STRING_SIZE above its width. It now states only the narrower case, which is what the check
is about; why wider bounds are still accepted is in the commit message.

⚠️ Noted, not fixed: an over-long fixed[N] bound throws TOO_LARGE_STRING_SIZE from the same
insertData instead of skipping min/max pruning for that column. Pre-existing, unchanged here, and it
fails loudly rather than returning wrong rows, so it stays outside a change about bounds that are too
narrow.

⚠️ Noted, not changed: every new arm shortens both of a column's bounds, never one alone. The
width check sits in the single decode both bounds go through, and a range is dropped when either side
fails to decode, so a manifest that shortens one bound reaches the same branch with the same outcome.
An arm for it would pin an implementation shape this change does not have.

💡 Bounds wider than the column are still accepted on purpose. Every currently released ClickHouse
writes eight-byte bounds for four-byte columns, and the regression test pins that they keep pruning.

@clickhouse-gh

clickhouse-gh Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2b714aa]

Summary: ✅


AI Review

Summary

Adds regression coverage for Iceberg manifest bounds that are narrower than the current column width, plus a comment rewording in ManifestFileIterator. The new tests exercise both numeric and fixed[N] manifest-file bounds, keep a well-formed sibling column to prove the fallback stays per-column, and the PR metadata correctly marks the change as test-only. I did not find a remaining correctness, coverage, or metadata issue in the current diff.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Measured on commit 2b714aa.

Metric Baseline Current Δ
Lines 89.10% 89.10% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.40% 81.50% +0.10%

Changed lines: Changed C/C++ lines covered: 5/5 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 6, 2026
@groeneai

groeneai commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator Author

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 fixed[N] one), so min/max pruning can drop a data file holding matching rows; the check rejects only short bounds and still accepts the over-long ones every released version writes.

@zlareb1

zlareb1 commented Sep 6, 2026

Copy link
Copy Markdown
Member

TL;DR: the same deserializeFieldFromBinaryRepr this PR guards has a sibling defect for uuid bounds, now filed as #118366 with a rig — the fix here is sound and doesn't cover it, so this is informational, not a request to widen this PR.

The Iceberg spec serializes uuid bounds as 16 big-endian bytes; they pass the new width guard (16 == 16) and take the raw-copy branch, but the Parquet data path decodes the same bytes by reversing each 8-byte half, so the pruning range and the query constant live in different value spaces and WHERE u = '<uuid present in the file>' silently prunes the file holding the row. Reproduced on 26.8.2.7 and a current development build with pyiceberg-written bounds; details and the repro are in the issue.

@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Sep 6, 2026
@groeneai

groeneai commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator Author

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 UUID by the second half while the writers order uuid bounds by unsigned big-endian bytes, so a swapped pair can pass the inverted-bounds guard and still exclude a value the file holds. The same root cause returns 0 rows for a value present in a plain Parquet file at default settings, so the statistics path is a separate change. I will take the Iceberg side as its own pull request.

@clickhouse-gh

clickhouse-gh Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 2b714aa1c with master a5bc4cc6e (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline.

Job report

@groeneai

groeneai commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 508b6f3

Every 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 CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
AST fuzzer (arm_asan_ubsan) / Server unresponsive: memory limit exceeded Job-level OOM in the fuzzer harness, not reachable from this diff: the fuzzer runs random SQL against a server with no Iceberg tables, and run-fuzzer.sh attaches no gdb on an ASAN build. The report carries no error text at all (8-byte context), which is the reporter defect #112014 fixes. Breadth in 30d: 27 rows across 10 check flavours, 0 from a master run; 2 rows in 60d on this flavour. #112014 (mine, open)
Mergeable Check, PR praktika aggregators, red only because of the row above #112014 (mine, open)
CH Inc sync - CH Inc sync (private, not actionable by me)

Bugfix validation (integration tests, amd64 / aarch64) is green and has no line above. The two test_iceberg_inverted_* rows that CIDB records as failures there are that check's inverted per-test status: those two are expected to pass on unpatched master, while the two test_iceberg_narrow_* regression tests do fail without the fix, which is what the check asserts.

Session id: cron:our-pr-ci-monitor:20260906-073116

…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.
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 449c515

Every 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 Finish Workflow, and the eight Bugfix validation (integration tests, *) FAIL rows in the CI database belong to jobs whose own status is skipped.

Check / test Reason Owner
Finish Workflow / Post Hooks / new_tests_check.py the gate read the stale pr-bugfix label PR-caused by design and owned by this PR (#118364): the resolution is the corrected changelog category, which the label pre-hook applies on the next workflow run
Mergeable Check derived red from the row above (Failed: Workflow Post Hook) PR-caused by design and owned by this PR (#118364): the resolution is the corrected changelog category, which the label pre-hook applies on the next workflow run
PR praktika rollup of the row above PR-caused by design and owned by this PR (#118364): the resolution is the corrected changelog category, which the label pre-hook applies on the next workflow run

Mechanism, read at source. new_tests_check.py gates on the pr-bugfix label read live (gh pr view 118364 --json labels, 02:29:31Z), and because this PR adds integration tests it then requires at least one per-arch Bugfix validation at OK or XFAIL. The production-side guard landed on master in #115817, so the bug no longer reproduces on master HEAD and all four per-arch jobs reported SKIPPED, two of them with Bug does not reproduce on this arch. The label itself is derived by the pr_labels_and_category.py pre-hook from the PR body as captured in the triggering event payload (_Environment reads GITHUB_EVENT_PATH), not from a live read, so the category correction posted at 23:23Z cannot reach a run that started at 22:06Z, and re-running that workflow replays the same payload.

What clears it: any new synchronize event re-derives the labels, and against the current body the CI parser returns Not for changelog (changelog entry is not required) -> pr-not-for-changelog, after which the post hook returns Not a bug fix PR - skip. Dropping pr-bugfix by hand has the same effect. I hold triage permission only, so I cannot re-run the workflow myself, and I am not pushing over the master merge sitting on this branch.

Session id: cron:clickhouse-maint-slot-13:20260913-024100

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog and removed pr-bugfix Pull request with bugfix, not backported by default labels Sep 13, 2026
@hanfei1991 hanfei1991 self-assigned this Sep 13, 2026
@hanfei1991

Copy link
Copy Markdown
Member

@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.

@groeneai groeneai changed the title Do not prune Iceberg data files on manifest bounds narrower than the column Add integration tests for Iceberg manifest bounds narrower than the column Sep 14, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

Done: retitled to "Add integration tests for Iceberg manifest bounds narrower than the column", merged master (eb882b42c458) and pushed d3f7a79, which starts a fresh CI run. The changelog category was already switched to Not for changelog on 2026-09-12, so the metadata matches the title now.

The diff is test only because the production guard reached master independently in #115817 (083fda43bd9d5). What is left here is regression coverage for the manifest file lower_bounds / upper_bounds path in ManifestFileIterator::processRow, which #115817 does not exercise: a narrow Int32 bound and a narrow fixed[3] bound must not prune. One arm pins the deliberate asymmetry of that guard, which rejects only bounds narrower than the column, so an eight byte bound declared for a four byte column still prunes.

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 skipped and none failed, while Mergeable Check still reported Failed: 98. The full run from this push replaces it.

`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.
@hanfei1991
hanfei1991 added this pull request to the merge queue Sep 16, 2026
Merged via the queue into ClickHouse:master with commit 6bf465b Sep 16, 2026
177 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 16, 2026
@clickhouse-gh clickhouse-gh Bot added comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... and removed comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... groeneai-origin-review-bot PR origin: review-bot finding on a groeneai PR pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants