Skip to content

Do not let Iceberg min/max pruning drop rows that hold a NaN - #126078

Merged
alesapin merged 5 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-118112-iceberg-nan-manifest-pruning
Nov 9, 2026
Merged

alesapin merged 5 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-118112-iceberg-nan-manifest-pruning

Conversation

@groeneai

@groeneai groeneai commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fixed a filtered query over an Iceberg table missing rows that hold a NaN in a Float32/Float64 column, for example WHERE x != 3 skipping a data file that holds 3, NaN, 3. Iceberg float bounds leave NaN out, so min/max pruning dropped such a file on a negated or chained predicate. It now prunes on such predicates only when the manifest's nan_value_counts shows the column holds no NaN, and it ignores a bound that is NaN. Closes #118112.

Description

Closes: #118112
Related: #116725

On 26.3.42.3, 26.8.18.2 and 26.9.16.11, SELECT count() FROM icebergLocal(...) WHERE x != 3 SETTINGS input_format_parquet_filter_push_down = 0 returns 0 instead of 1 for a pyiceberg-written file holding x = [3, NaN, 3].

By the Iceberg spec float lower_bounds/upper_bounds exclude NaN, which is counted only in nan_value_counts. ClickHouse never read that field and evaluated the filter as if the bounds covered every value, so a negated atom (!=, NOT (x < 10), NOT IN) or a chain (round(x) != 3) pruned the file. Separately, a (NaN, NaN) bound pair, which Iceberg Java writes for an ORC file whose first value is NaN, passes the inverted-bounds check from #116604 and prunes the file on x = 3.

For float columns the pruner now also builds a condition relaxed by KeyCondition::relaxAtomsOverNaNHidingColumns, as MergeTree minmax does, and uses it unless the file's nan_value_counts for the column is 0 (Iceberg Java's mayContainNaN). Bounds with a NaN endpoint are dropped. OPTIMIZE TABLE ... MANIFEST now carries nan_value_counts over. The price: for files without nan_value_counts (pyiceberg), negated and chained float predicates no longer prune; positive comparisons still do. At full defaults the Parquet row-group layer also drops the row (#118110); #116725 fixes that.

Validation: the new test_iceberg_nan_manifest_bounds fails on master at every assertion except the control; test_optimize_manifest_files_preserves_stats gains a double column and fails on master with nan_value_counts dropped: 0.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.1773-master (included in 26.11 and later)

groeneai and others added 2 commits October 15, 2026 16:09
Iceberg float lower_bounds/upper_bounds exclude NaN by spec, and NaN
presence is recorded only in the optional nan_value_counts (field 137).
ClickHouse never read that field, and the manifest pruner evaluated a
plain KeyCondition over the bounds as if they covered every value. A
hidden NaN satisfies no ordering comparison, so it makes a negated atom
true (`!=`, `NOT (x < 10)`, `NOT IN`) and a monotonic chain can map it
anywhere (`round(x) != 3`): such predicates pruned a data file holding
the NaN and its rows were lost. Reproduced on 26.3.42.3, 26.8.18.2,
26.9.16.11 and master with a pyiceberg-written file `x = [3, NaN, 3]`:
`WHERE x != 3` returned 0 with pruning on and 1 with it off.

Parse nan_value_counts into ColumnInfo. For a column whose type may hide
a NaN, the pruner also builds a copy of the min/max condition relaxed by
KeyCondition::relaxAtomsOverNaNHidingColumns, the mechanism MergeTree
minmax, skip indexes and the statistics pruner already use for
NaN-excluding bounds, and uses it unless the data file's
nan_value_counts for the column is 0 (Iceberg Java's mayContainNaN).
Positive comparisons keep pruning.

The inverted-bounds check from ClickHouse#116604 orders NaN last, so `(NaN, 5)` is
already dropped as inverted, but an upper NaN bound (`(5, NaN)`,
`(NaN, NaN)`, which Iceberg Java's ORC metrics report when a file's
first value is NaN) passed and pruned on `x = 3`. Drop a column's bounds
when either endpoint is NaN.

OPTIMIZE TABLE ... MANIFEST copies the source entries' statistics
verbatim; carry nan_value_counts over as well, otherwise compaction would
demote every column of a table written by Iceberg Java to the relaxed
condition.

Closes ClickHouse#118112

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…resence

The compaction stats test inserted no NaN, so every source
nan_value_counts entry was 0 and the test read only the map length. The
reader treats a count of exactly 0 as proof that strict min/max pruning
is safe, so a rewrite that zeroed a positive count, or copied the null
count into the NaN map, passed the test and would re-enable the wrong
prune. One source file now holds a NaN, and the per-file NaN counts of
the rewritten manifest must equal those of the source manifests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 2 rounds, 2 findings) plus my own cold review.

# Sev Finding Verdict Evidence / action
1 ⚠️ test_optimize_manifest_files_preserves_stats checks only the length of nan_value_counts, and its fixture holds no NaN, so a rewrite that zeroes a positive count would pass AGREE, fixed in 4a3bdd0b41c one source file gets a NaN; the per-file count map is compared before and after the rewrite
2 ❌ manifest-list pruning reads a null contains_nan as "no NaN" DISAGREE no writer emits NaN-free partition bounds with a null contains_nan: Iceberg Java, pyiceberg, iceberg-rust and iceberg-go always set it on a NaN; ClickHouse sets it and writes no float partition bounds; pre-contains_nan Java keeps NaN as the upper bound, which the key condition already refuses to prune on
3 💡 the NaN-endpoint guard also drops a (finite, NaN) pair, which the key condition already answers safely DISAGREE dropping bounds can only disable pruning, so it is correctness-safe; it matches the existing disposition for untrustworthy bounds

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-48:20261015-165600

@clickhouse-gh

clickhouse-gh Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1181255]

Summary: ✅


AI Review

Summary

Reviewed PR #126078 at 1181255a1afa84afee4f08a8634c01e3030b3c7f, including all prior discussion, the complete diff, and the surrounding pruning, deserialization, and manifest rewrite paths. The change prevents Iceberg manifest pruning from losing matching NaN rows, ignores NaN bounds, and preserves nan_value_counts during manifest compaction. No actionable findings remain.

Missing context / blind spots
  • ⚠️ Integration and bugfix-validation jobs for the current head are still pending. On preceding head 1fb8a58a4d6a60eadb32149c8468128a34ebe08b, both focused regression tests passed in targeted integration CI, and bugfix validation confirmed their intended failures on the baseline. Completion of the current-head jobs closes this remaining validation gap. Tests were not run locally during this review.
Final Verdict

Status: ✅ Approve. No new inline findings; current-head CI still needs to finish.

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

Copy link
Copy Markdown
Collaborator Author

cc @scanhex12 @SmitaRKulkarni, could you review this and add can be tested (I cannot set labels right now)? Iceberg float bounds exclude NaN, so the manifest min/max pruner now relaxes negated and chained float predicates unless the data file's nan_value_counts is 0, and ignores a bound that is NaN.

@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Oct 15, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 15, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 4a3bdd0

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
Upgrade check (amd_release) / Error message in clickhouse-server.log not from this PR (it changes only Iceberg manifest pruning): after the upgrade, a dictionary whose source query references x fails to load with UNKNOWN_IDENTIFIER (Unknown expression or function identifier x. In scope x = 1); first occurrence in the last 30 days a fix task is created (investigating at full effort, fixing-PR link to follow here)
Mergeable Check, PR praktika rollups of the row above a fix task is created (the one for the first row)

CIDB has no other FAIL or ERROR row from the finished run on this head.

Session id: cron:our-pr-ci-monitor:20261015-230015

@groeneai

Copy link
Copy Markdown
Collaborator Author

Fixing PR for the Upgrade check (amd_release) dictionary UNKNOWN_IDENTIFIER error created: #126169

alexey-milovidov pushed a commit to JayPokale/ClickHouse that referenced this pull request Oct 19, 2026
The stress phase runs many tests in one shared database per worker, and a
test that is stopped before its last statement leaves its row policies
behind. A database-level one (`02703_row_policy_for_database.sh`:
`ON * USING x=1 TO ALL` on `test_1`) filters every table of that database,
so after the upgrade the eager dictionary of `04365_dictionary_lazy_load`
over `test_1.src`, which has no column `x`, fails to load in the background
with `UNKNOWN_IDENTIFIER` and the log scan fails the job (seen on ClickHouse#126078).
The old server fails the same way, so it is leftover test state, not an
upgrade incompatibility. 15 row policies were alive when the old server
stopped in that run, two of them created by the AST fuzzer.

Drop every row policy not defined in `users.xml` before the upgrade and
fail the job when one survives, as is done for leftover mutations
(ClickHouse#120978). Neutralizing them instead does not work: the test config sets
`throw_on_unmatched_row_policies`, so a table whose policies apply to
nobody throws for every reader. The statements are generated server-side
from `system.row_policies.name`, so no name passes through the shell.

The drop takes away the policies that happened to cross the upgrade, so
one is created deliberately (`k < 3` on a 10-row table) and the new
server has to apply it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-iceberg-nan-manifest-pruning

Resolve conflicts with master's extraction of getDataFileHyperrectangles and the require_ready_sets argument of the min/max KeyCondition: the NaN-bound guard moves into getDataFileHyperrectangles, and the NaN-relaxed condition copies the condition built with master's arguments.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 1181255a1 with master c8383042c (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

9 object files changed (+44.86 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFilesPruning.cpp.o 251.02 KiB 284.99 KiB +33.97 KiB (+13.53%)

719 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

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

Job report

@alesapin alesapin self-assigned this Nov 3, 2026
…-iceberg-nan-manifest-pruning

Master ClickHouse#123553 moved the per-column bound decoding of
getDataFileHyperrectangles into decodeColumnBounds, which returns
std::optional<ColumnBounds>. The NaN-bound guard now lives there, so it
returns std::nullopt instead of continuing the old loop, and it also
covers the new getDataFileColumnBounds caller (manifest column
statistics), which must not report a NaN as a column minimum or maximum.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

groeneai commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author

Merged master: #123553 moved the bound decoding into decodeColumnBounds, so this branch no longer compiled on top of current master although GitHub showed no conflict. The NaN-bound guard now returns std::nullopt there, which also keeps a NaN out of the new manifest column statistics. No other change.

@groeneai

groeneai commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 1fb8a58

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
Integration tests (arm_binary, 2/4) / test_read_temporary_tables_on_failure/test.py::test_different_versions not from this PR (it changes only Iceberg manifest pruning): DID NOT RAISE at test.py:27. Since #127149 the server cancels a query whose client was killed, so the test's slot-holding query is gone and max_concurrent_queries_for_user = 1 no longer refuses the next one. The same failure is on master since that merge #129151 (mine, open)
Mergeable Check, PR praktika rollups of the row above #129151 (mine, open)

Apart from the expected Bugfix validation (integration tests, *) rows (this PR's tests failing on master inside green checks), CIDB has no other FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20261104-030003

@alesapin

alesapin commented Nov 4, 2026

Copy link
Copy Markdown
Member

@groeneai we have conflicts :( Please merge master again.

…-iceberg-nan-manifest-pruning

Master ClickHouse#128880 moved the per-entry statistics copy of the manifest-only
rewrite (OPTIMIZE TABLE ... MANIFEST) into getColumnStatisticsForRewrite.
The nan_value_counts carry now lives in that helper; no other change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

groeneai commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

Merged master in 1181255. The only conflict was in Compaction.cpp: #128880 moved the per-file statistics copy into getColumnStatisticsForRewrite, so the nan_value_counts carry now lives there. No other change; test_iceberg_inverted_manifest_bounds.py and test_manifest_compaction.py pass locally on the merged tree.

cherepasshka added a commit to cherepasshka/ClickHouse that referenced this pull request Nov 6, 2026
Fails until PR ClickHouse#126078 is merged: without it, min/max pruning drops a
file whose only matching row is NaN, now that float bounds are written.
The expected output is the correct one, checked with that PR applied
locally, so the test fails until then.

Related: ClickHouse#126078

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alesapin
alesapin added this pull request to the merge queue Nov 9, 2026
Merged via the queue into ClickHouse:master with commit 70c040f Nov 9, 2026
186 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 9, 2026
cherepasshka added a commit to cherepasshka/ClickHouse that referenced this pull request Nov 10, 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... pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

4 participants