Repository navigation
Support lower/upper bounds and nan_value_counts for Float32/Float64 in the Iceberg writer - #129812
Conversation
`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]>
…-bound-for-iceberg-writer
The numbers 05507-05509 were taken by tests from master. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-bound-for-iceberg-writer
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]>
|
|
They are written now, without NaN, and NaN goes to `nan_value_counts`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
This PR depends on #126078: with NaN excluded from the bounds, the current reader, which ignores Findings outside the scope of this PR, found while working on it:
|
|
Workflow [PR], commit [8be099d] Summary: ✅
AI ReviewSummaryThe PR adds Iceberg bounds and Consumers traced for the newly emitted statistics:
The four new stateless tests, the updated partial-statistics test, and the Spark compatibility test passed at Missing context / blind spots
Final Verdict✅ Approve — no code changes requested. No new inline findings were posted. |
Required by the style check. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units19 translation units recompiled, 165 s compile time in total, 19 of them have a recent master baseline. |
…-bound-for-iceberg-writer
asya-ch
left a comment
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
nit: I would remove this second bullet point. It is not a limitation on the ClickHouse side, we are just following the spec.
There was a problem hiding this comment.
nit: Could you please change the Float to UUID here? This comment is now outdated.
| if (!chunk.hasRows()) | ||
| return; | ||
| size_t num_columns = chunk.getNumColumns(); | ||
| if (null_counts.empty()) |
There was a problem hiding this comment.
question: Why switch the condition from null_counts.empty() to ranges.empty()? It's not a problem, just curious.
There was a problem hiding this comment.
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.
…mment Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
…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]>
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]>
Closes: #125608
Related: #126078
Related: #118112
Related: #109286
Related: #117116
Related: #129827
Changes
uniteRangesskips all-NaN chunks),-0.0sorts before+0.0(icebergBoundLess, also for partition values), andFloat32bounds are 4 bytes (FieldstoresFloat32asFloat64, so they were written as 8).nan_value_countsis 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.5on1.5, nanreturned nothing). #126078 fixes the reader: it keeps a file unless itsnan_value_countsshows the column has no NaN, and carries the counts over inOPTIMIZE TABLE ... MANIFEST. It is merged, and master is merged into this branch, soiceberg_read_float_nan_pruningpasses.Tests
iceberg_insert_float_bounds,iceberg_insert_float_partition_bounds,iceberg_insert_float_nan_value_counts: bounds, partition summary and NaN counts, including NULL, infinities,±0.0, non-Nullable columns and multi-chunk inserts.iceberg_read_float_nan_pruning: reading back with min/max pruning. Parquet pushdown is off there, as it drops NaN rows by itself (Parquet statistics pruning silently drops NaN rows: min/max stats exclude NaN by spec but predicates matching NaN are pruned against them #118110, fixed in Fix Parquet pruning dropping rows that hold a NaN, and write the mandatory nan_count statistic #116725).iceberg_insert_partial_statistics_boundscase D now uses an all-NaNFloat64column, asFloat64has bounds now.test_storage_iceberg_with_spark/test_writes_float_bounds.py: compatibility test, Spark reads the bounds andnan_value_countswritten by ClickHouse.CompactionandMutationsuse the same statistics code asINSERT, so there are no separate tests for them.Found while testing
Float32column is unreadable after an insert; Fix Iceberg manifest partition value encoding #109286 fixes it.OPTIMIZE TABLEgives every rewritten data file the manifest's summed statistics (OPTIMIZE TABLE stamps manifest-wide Iceberg stats on every data_file entry #117116),nan_value_countsincluded.Changelog category (leave one):
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.0before+0.0, as the Iceberg spec requires) andnan_value_countsforFloat32andFloat64columns, so Iceberg readers can prune data files by float columns.Workflow [PR]
Sync PR [sync-upstream/pr/129812]
Version info
26.11.1.2133-master(included in26.11and later)