Skip to content

Fix an exception on Iceberg partition pruning of pre-1970 partition values - #119292

Closed
scanhex12 wants to merge 1 commit into
masterfrom
iceberg-pre-epoch-partition-summary-bounds
Closed

scanhex12 wants to merge 1 commit into
masterfrom
iceberg-pre-epoch-partition-summary-bounds

Conversation

@scanhex12

@scanhex12 scanhex12 commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

Related: #118606
Related: #116499
Related: #116604

An Iceberg partition field summary keeps its bounds in the single-value serialization of the partition field's own type, and for the day, month, year and hour transforms that type is a signed int counting units from 1970. ClickHouse models those transforms in the partition key with toRelativeDayNum, toMonthNumSinceEpoch, toYearNumSinceEpoch and toRelativeHourNum, whose result types are unsigned, so ManifestListPruner::canBePruned read a bound from before 1970 as a huge unsigned number. For a manifest that spans 1969 and 2024 the lower bound then came out above the upper bound, and KeyCondition::checkInRange hit chassert(key_order.compareTuples(left_keys, right_keys, used_key_size) <= 0), which aborts a build with assertions.

That is what broke test_storage_iceberg_with_spark/test_partition_pruning_with_functions.py::test_partition_pruning_with_functions_before_epoch on master in Integration tests (amd_tsan, 3/6) and Integration tests (amd_msan, 8/8): #118606 gave toDate32 its monotonicity on a Nullable column, which let the filter of that test reach the pruner. No open issue tracks this failure. The release builds pass because chassert compiles out there and the unusable range keeps the manifest instead of pruning it.

A bound of an unsigned key column is now read as the signed number Iceberg wrote, and a negative one leaves the whole field unknown: the ClickHouse functions standing for those transforms cannot return a negative number - they map every point before 1970 to zero - so nothing about the key's value space follows from such a bound and no range of it may be pruned on. A pair of bounds that still comes out inverted drops the field with a warning instead of being pruned on, which is what ManifestFileIterator already does for the min/max bounds of a data file. One decodable bound of a pair no longer stands on its own either: the other side of the field is unknown then, and KeyCondition takes the whole universe of the column for it anyway.

test_partition_pruning_with_functions_before_epoch covers the abort. The new test_partition_pruning_with_functions_before_epoch_separate_commits commits the pre-1970 rows separately, so the summaries of that manifest are negative on both sides, and pins that such a manifest is not pruned away.

Tested locally with python3 -m ci.praktika run "integration" --test "test_storage_iceberg_with_spark/test_partition_pruning_with_functions.py": 6 passed.

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/119292]

…it is

An Iceberg partition field summary keeps its bounds in the single-value
serialization of the partition field's own type, and for the `day`, `month`,
`year` and `hour` transforms that type is a signed `int` counting units from
1970. ClickHouse models those transforms in the partition key with
`toRelativeDayNum`, `toMonthNumSinceEpoch`, `toYearNumSinceEpoch` and
`toRelativeHourNum`, whose result types are unsigned, so
`ManifestListPruner::canBePruned` read a bound from before 1970 as a huge
unsigned number. For a manifest that spans 1969 and 2024 the lower bound then
came out above the upper bound, and `KeyCondition::checkInRange` hit
`chassert(key_order.compareTuples(left_keys, right_keys, used_key_size) <= 0)`,
which aborts a build with assertions.

That is why
`test_storage_iceberg_with_spark/test_partition_pruning_with_functions.py::test_partition_pruning_with_functions_before_epoch`
started failing on master in `Integration tests (amd_tsan, 3/6)` and
`Integration tests (amd_msan, 8/8)`: the `toDate32` monotonicity that
#118606 gave a `Nullable` column
made the filter of that test reach the pruner.

A bound of an unsigned key column is now read as the signed number Iceberg
wrote, and a negative one leaves the whole field unknown: the ClickHouse
functions that stand for those transforms cannot return a negative number -
they map every point before 1970 to zero - so nothing about the key's value
space follows from such a bound and no range of it may be pruned on.

A pair of bounds that comes out inverted now drops the field with a warning
instead of being pruned on, the same as `ManifestFileIterator` already does
for the min/max bounds of a data file.

Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=290309210c5b2f0e01c13fd0fbae6577fb5cb9cd&name_0=MasterCI&name_1=Integration%20tests%20%28amd_tsan%2C%203%2F6%29

Related: #118606
Related: #116499
Related: #116604

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4a93198]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel) FAIL
05054_nullable_key_todate_monotonicity FAIL cidb
02156_storage_merge_prewhere NOT_FAILED cidb
02402_merge_engine_with_view NOT_FAILED cidb
02918_optimize_count_for_merge_tables NOT_FAILED cidb

AI Review

Summary

This PR fixes the exception path in ManifestListPruner for pre-1970 Iceberg partition-summary values by decoding signed epoch counts before building the key range. The new guard is still too aggressive, though: it turns every negative day / month / year / hour summary into "unknown" instead of mapping it into the clamped ClickHouse key space, so historical manifests lose manifest-list pruning that is still safe and useful.

Findings

⚠️ Majors

  • [src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestListPruning.cpp:59] The new isUInt() path conflates "unsigned result type" with "epoch-count transform that needs clamping". The KeyCondition here is built on toRelativeDayNum, toMonthNumSinceEpoch, toYearNumSinceEpoch, and toRelativeHourNum, and those functions clamp pre-1970 values to 0; they do not make the key undefined. An Iceberg summary [-10, -1] therefore still has the precise ClickHouse range [0, 0], and [-10, 5] still has [0, 5]. Returning {} for any negative bound fixes the assertion, but it also disables manifest-list pruning for historical manifests and mixed 1969/2024 manifests on predicates like toDate32(ts) > toDate32('1970-01-01') or toYear(d) > 1969. Pass the partition transform into this helper and clamp these four epoch-count transforms into the ClickHouse key space instead of rejecting every negative signed count.
Tests
  • ⚠️ The added coverage in tests/integration/test_storage_iceberg_with_spark/test_partition_pruning_with_functions.py only exercises = and >= predicates on the pre-1970 cases. Add a focused manifest-list pruning case with an all-pre-1970 manifest and a strict > predicate so the test fails if negative bounds are dropped instead of clamped.
Final Verdict

Status: ⚠️ Request changes
Preserve clamped pruning semantics for negative epoch-count summaries, and cover that case with a focused manifest-list pruning test.

LLVM Coverage Report

Measured on commit 4a93198.

Metric Baseline Current Δ
Lines 89.00% 89.00% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.30% 81.30% +0.00%

Changed lines: Changed C/C++ lines covered: 33/42 (78.57%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Sep 10, 2026
@scanhex12
scanhex12 marked this pull request as draft September 10, 2026 16:45

std::optional<Field> lower;
std::optional<Field> upper;
if (WhichDataType(non_nullable_type).isUInt())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using isUInt() as the selector is too coarse here. The special case is not "all unsigned keys"; it is the four epoch-count transforms whose ClickHouse implementations clamp pre-1970 results to 0. For those transforms, a negative Iceberg summary bound is still informative: [-10, -1] maps to [0, 0], and [-10, 5] maps to [0, 5] in the key space that KeyCondition sees. Returning {} for any negative value fixes the assertion, but it also disables manifest-list pruning for historical manifests on predicates like toDate32(ts) > toDate32('1970-01-01') or toYear(d) > 1969 that are still safely prunable.

This helper needs the partition transform (or an explicit "clamped epoch-count" flag) instead of inferring from the result type, and the added tests should cover a strict > predicate so this regression is visible.

@clickhouse-gh

clickhouse-gh Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 4a9319850 with master c7a9fe7c9 (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.

Object file sizes

20 object files changed (+21.95 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/ManifestListPruning.cpp.o 109.35 KiB 131.40 KiB +22.05 KiB (+20.17%)

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

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

Job report

@scanhex12

Copy link
Copy Markdown
Member Author

Superseded by #119302, which brings back #118606 together with this fix in one pull request.

master no longer has tests/integration/test_storage_iceberg_with_spark/test_partition_pruning_with_functions.py after #119298, so this pull request cannot stand on its own anymore: the test it extends only exists again on the branch of #119302. The commit here is in #119302 unchanged.

@scanhex12 scanhex12 closed this Sep 11, 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

comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant