Skip to content

Support lower/upper bounds and nan_value_counts for Float32/Float64 in the Iceberg writer - #129812

Merged
asya-ch merged 24 commits into
ClickHouse:masterfrom
cherepasshka:float-lower-upper-bound-for-iceberg-writer
Nov 12, 2026
Merged

asya-ch merged 24 commits into
ClickHouse:masterfrom
cherepasshka:float-lower-upper-bound-for-iceberg-writer

Conversation

@cherepasshka

@cherepasshka cherepasshka commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #125608
Related: #126078
Related: #118112
Related: #109286
Related: #117116
Related: #129827

Changes

  • Float bounds follow the Iceberg spec ("Bounds for Float and Double"): NaN is excluded (uniteRanges skips all-NaN chunks), -0.0 sorts before +0.0 (icebergBoundLess, also for partition values), and Float32 bounds are 4 bytes (Field stores Float32 as Float64, so they were written as 8).
  • nan_value_counts is written for float columns.

Depends on #126078 (merged)

The old reader ignored nan_value_counts, so with NaN excluded from the bounds it pruned a file whose only matching row is NaN (WHERE f != 1.5 on 1.5, nan returned nothing). #126078 fixes the reader: it keeps a file unless its nan_value_counts shows the column has no NaN, and carries the counts over in OPTIMIZE TABLE ... MANIFEST. It is merged, and master is merged into this branch, so iceberg_read_float_nan_pruning passes.

Tests

Compaction and Mutations use the same statistics code as INSERT, so there are no separate tests for them.

Found while testing

Changelog category (leave one):

  • Improvement

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

The Iceberg writer now supports lower_bounds/upper_bounds (excluding NaN and ordering -0.0 before +0.0, as the Iceberg spec requires) and nan_value_counts for Float32 and Float64 columns, so Iceberg readers can prune data files by float columns.


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

Version info

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

cherepasshka and others added 18 commits November 5, 2026 20:29
`canDumpIcebergStats` rejected all float types unconditionally; allow
them, excluding NaN per the Iceberg spec. Fix a latent `dumpFieldTo
bug along the way: `Field` has no `Float32` slot, so
`field.safeGet<Float32>()` returns a `Float64`, causing an 8-byte dump
instead of 4 — narrow with `static_cast<Float32>` first. Also fix
`DataFileStatistics::uniteRanges`, which let an all-NaN chunk's range
win a bound across chunks/files via `Range::less`'s "NaN is greatest"
rule; exclude it instead.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
`DataFileStatistics` tracked `null_counts` but never NaN, so
`nan_value_counts` was never written to the manifest. Count NaN per
column in `update`/`merge`, using `isNaN()` (`Common/NaNUtils.h`) for
consistency with `ColumnVector::getExtremes`. Track which columns are
actually Float32/Float64 (`is_float_column`) so `getNanCounts()` can
omit the entry entirely for non-float columns, rather than reporting
a meaningless 0.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
The Iceberg spec orders -0.0 before +0.0 as a bound, but
`ColumnVector::getExtremes` and `accurateLess` treat them as equal, so
the winner of a tie depended on scan order. Fix the sign of a zero
extreme in `getExtremeRangeFromColumn` and break ties by sign in
`uniteRanges`.

Move the multi-chunk cases of `05507` to `INSERT ... SELECT`:
`INSERT ... VALUES` always arrives as a single chunk, so they never
reached `uniteRanges`.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The multi-chunk cases rely on insert squashing keeping one-row blocks
apart, which holds only for formats that do not prefer large blocks.
With ORC the blocks would be merged back and the cases would silently
stop exercising `uniteRanges`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`ManifestPartitionSummary::add` compared with `accurateLess`, so a
-0.0/+0.0 tie went to whichever partition came first in hash order.
Share the sign-aware comparison as `icebergBoundLess` and use it there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add non-Nullable and +-inf cases to `05507` and `05509`, and move the
multi-chunk case of `05509` to `INSERT ... SELECT`: like in `05507`,
`INSERT ... VALUES` arrived as one chunk, so counts were never summed
across chunks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fix two wrong claims: `toString` does render the sign of -0.0, and the
case labels of `05508` covered two cases each.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The numbers 05507-05509 were taken by tests from master.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
Float64 now has bounds, so case D no longer checked that the filter
skips only the column the bounds predicate rejects. No other column
type can take its place: the writer converts small integers, Bool and
DateTime to types with bounds before collecting statistics, and UUID
cannot be inserted. An all-NaN Float64 column restores the check: it
is dumpable but has no valid bound.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Also rename `fixSignedZeroExtremes` to `fixFloatSignedZeroExtremes`:
it only does anything for float columns.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Like `getExtremeRangeFromColumn` already was, instead of wrapping them
in an anonymous namespace.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep the helpers as static functions where they were, so
`getExtremeRangeFromColumn` stays at its place on master. In the bounds
tests, print bounds as (field id, value) pairs and drop the hex dumps:
`toString` shows the sign of zero, and a wrong Float32 width shows up in
the decoded values.

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

Reuse `Field::isNaN` and `isFloatZeroField` and count NULLs with
`countBytesInFilter`. A `nan_value_counts` entry is now written only if
every chunk had a `Float32`/`Float64` column there: otherwise the column
was counted as 0 NaN, which tells readers there is none. Read `Float32`
bounds as `Float64` explicitly before narrowing them, and clarify
comments in the code and the float tests after review.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Check that Spark (Iceberg Java) reads the `Float32`/`Float64` bounds and
`nan_value_counts` written by ClickHouse: NaN is excluded, -0.0 sorts
before +0.0, and a `Float32` bound is 4 bytes.

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

cla-assistant Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@cla-assistant

cla-assistant Bot commented Nov 6, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Nov 6, 2026
They are written now, without NaN, and NaN goes to `nan_value_counts`.

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

Copy link
Copy Markdown
Contributor Author

This PR depends on #126078: with NaN excluded from the bounds, the current reader, which ignores nan_value_counts, prunes files whose only matching rows are NaN. #126078 fixes the reader: it keeps a file unless its nan_value_counts shows the column has no NaN. iceberg_read_float_nan_pruning fails until then.

Findings outside the scope of this PR, found while working on it:

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Nov 7, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8be099d]

Summary: ✅


AI Review

Summary

The PR adds Iceberg bounds and nan_value_counts for Float32 and Float64, excludes NaN from bounds, preserves signed-zero ordering, and fixes the four-byte encoding of Float32 bounds. No actionable findings remain after reviewing the full diff, current code, and all prior discussion. The behavior matches the Iceberg specification.

Consumers traced for the newly emitted statistics:

  • generateManifestFile filters absent/NaN bounds and serializes each supported column type.
  • ManifestFileIterator decodes bounds using the manifest schema; ManifestFilesPruner uses NaN counts to select conservative pruning.
  • ManifestPartitionSummary orders signed zeros; ManifestListPruner leaves NaN-bearing summaries unconstrained.
  • Manifest-only compaction preserves raw bounds and NaN counts; data compaction and mutations use DataFileStatistics.
  • The Spark interoperability test independently decodes the written metrics.

The four new stateless tests, the updated partial-statistics test, and the Spark compatibility test passed at 1096a783694c17b576961d0c3d6d383f67d4f22a. The current head changes only a comment and structured documentation relative to that commit. See the stateless report and Spark test report.

Missing context / blind spots
  • ⚠️ The current head's targeted tests are pending. Their completion will provide confirmation for 8be099d4667b9dc43ca9c33c9c69aad01ec8ebac; no local build or tests were run.
Final Verdict

✅ Approve — no code changes requested. No new inline findings were posted.

@clickhouse-gh clickhouse-gh Bot added pr-improvement Pull request with some product improvements external Author is not a member of the ClickHouse organization labels Nov 7, 2026
Required by the style check.

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

clickhouse-gh Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 8be099d46 with master b656997bd (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.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.60, programs/clickhouse-keeper ×0.84 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 6.3 s 12.9 s +9.1 s (+243%)
programs/clickhouse _ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… 3.6 s 7.2 s +5.0 s (+233%)
Compile time of recompiled translation units

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

Job report

@asya-ch asya-ch self-assigned this Nov 11, 2026

@asya-ch asya-ch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good! Clear and addresses the edge cases from the spec. I just have a couple small nits, let me know what you think.

- ClickHouse cannot write to an Iceberg table that uses a `decimal`, `fixed`, `timestamp_ns`, or `timestamptz_ns` column as a direct partition field. The operation fails with an unsupported-type exception.
- For data files containing types whose bounds ClickHouse cannot serialize, such as `Float32`, `Float64`, and `UUID`, ClickHouse omits the lower and upper bounds of those columns from the Iceberg manifest entry. Column sizes and null counts are still included, and the data remains correct, but readers cannot use manifest-level min-max pruning for those files.
- For data files containing types whose bounds ClickHouse cannot serialize, such as `UUID`, ClickHouse omits the lower and upper bounds of those columns from the Iceberg manifest entry. Column sizes and null counts are still included, and the data remains correct, but readers cannot use manifest-level min-max pruning for those files.
- For `Float32` and `Float64` columns, NaN is excluded from the lower and upper bounds, as the Iceberg spec requires, and is counted in `nan_value_counts` instead. A column that holds only NaN and NULL values has no bounds.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: I would remove this second bullet point. It is not a limitation on the ClickHouse side, we are just following the spec.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: Could you please change the Float to UUID here? This comment is now outdated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, sure

if (!chunk.hasRows())
return;
size_t num_columns = chunk.getNumColumns();
if (null_counts.empty())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

question: Why switch the condition from null_counts.empty() to ranges.empty()? It's not a problem, just curious.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I found ranges.empty() more readable: this condition runs only for the first chunk, and the main thing it does is set the initial ranges from that chunk's extremes, while the null and NaN counters are just sized and zeroed alongside them.

@asya-ch
asya-ch added this pull request to the merge queue Nov 12, 2026
Merged via the queue into ClickHouse:master with commit 8d9b821 Nov 12, 2026
203 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 12, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 15, 2026
Master gained two key encoders that read a `Nullable` null-map byte as a
value, and both must agree with the rest of this PR:

- `HashedJoinKey::buildRows` (ClickHouse#129328) copies the bytes that `hash128`
  hashes, and its own contract is that every way of building a key gives
  exactly `hash128`. This PR makes `ColumnNullable::updateHashWithValue`
  hash `byte != 0`, so after the merge the copied raw byte broke that
  contract: on the merged tree `SELECT count() FROM t l JOIN t r ON l.s <=> r.s`
  over a Native null map with bytes 0, 1 and 2 aborts on the debug check
  in `buildRange` (AVX2 and NEON builds). It now copies `byte != 0`: 500
  rows, where master gives 300.
- `encodeFixedSizeKeys` (ClickHouse#124907) packs NULL into a one-bit field, so a
  byte 2 set the lowest bit of the column before it. With
  `transform_null_in = 1` and a set spilled to disk, `(0, NULL)` was found
  in `{(1, 0)}`: master 10 rows, 0 in memory. The right side is read back
  from the canonical in-memory keys, so only the probe side carried the
  raw byte.

Both are bit-identical on 0/1 maps. 05210 covers both cases, and gains
a `groupUniqArray(tuple(s))` case for the arena key encoder
(`serializeValueIntoArena`), which no case reached: reverting it left
05210 green, now it gives 3 keys where 2 are correct.

05210 also pins `optimize_if_transform_const_strings_to_lowcardinality`
to 0: the runner randomizes it since ClickHouse#80263, and with it `if` returns
`LowCardinality(Nullable(String))`, which has no `.null` subcolumn, so
the `if` case failed with UNKNOWN_IDENTIFIER on half the runs.

05211 is removed: ClickHouse#129812 made the Iceberg null count use
`countBytesInFilter`, so that reader is master's now and the merge drops
it from this PR (05211 passes on master).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 23, 2026
…t-list-bucket-partition-summary

Conflict in IcebergWrites.cpp, two hunks:
- The summary write loop: master (ClickHouse#129812) only reworded the comment on
  its `bounds_unavailable` check. Kept this branch's form, which has no
  check: `canWritePartitionSummary` already returns early for a manifest
  with such a field.
- The manifest-list carry-forward: master (ClickHouse#130800) rebuilds each count
  in the new list's shape with `copy_count`. Took master's counts and
  kept this branch's guarded copy of `partitions`.

Conflict in ChunkPartitioner.h: master added `[[nodiscard]]` to
`getResultTypes`; kept it together with this branch's comment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 23, 2026
Since ClickHouse#129812 the Iceberg writer serializes `Float32`/`Float64` bounds,
including in the manifest-list partition summary, so the tuple holding
1.5 now gets a bounded summary instead of none. No other partition type
that ClickHouse can write lacks a bound serialization any more (`UUID`
partitions are rejected at INSERT), so the test now asserts the real
bound and keeps the NaN case, which still has no bound and must keep its
summary.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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... external Author is not a member of the ClickHouse organization pr-improvement Pull request with some product improvements 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.

Iceberg writer writes no lower_bounds / upper_bounds for Float32 / Float64 columns

4 participants