Repository navigation
Write theta-sketch NDV statistics on Iceberg commits - #131249
Conversation
Every commit ClickHouse makes to an Iceberg table writes a Puffin file of apache-datasketches-theta-v1 sketches, one per column, and registers it in the metadata statistics of its snapshot, as Spark's compute_table_stats does: INSERT and ALTER UPDATE union the parent's sketches with the written rows, ALTER DELETE, DROP PARTITION and OPTIMIZE ... MANIFEST keep the parent's, OPTIMIZE rebuilds them. expire_snapshots drops the statistics of expired snapshots. Values are hashed as Spark hashes them, through the new IColumn::computeMurmurHash3Into. Enabled by the experimental setting iceberg_write_table_statistics_ndv (off by default). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tistics # Conflicts: # src/Storages/ObjectStorage/DataLakes/Iceberg/Mutations.cpp
|
Workflow [PR], commit [f0d5fab] Summary: ✅
AI Review
|
… statistics The Puffin footer reader stays in `PuffinBlockInputFormat` and now accepts every blob type: the deletion-vector checks apply only to deletion-vector blobs, so `PuffinMetadata` lists the theta sketch blobs of Spark and Trino statistics files. `Puffin` still reads deletion vectors only and now checks every blob's type once, right after the footer, so a `LIMIT` that stops at a deletion vector still rejects a file that also holds other blobs. `readPuffinFooter`, `readPuffinBlobBytes` and `PUFFIN_MAGIC` are exported, and `PuffinBlob::toJSON` gives the blob metadata JSON shared by the footer and the table metadata `blob-metadata`. `PuffinFile` adds `PuffinReader` (the footer, then blobs decompressed from zstd / lz4 with a 64 MiB cap) and `PuffinWriter`. The Iceberg NDV statistics write and read their Puffin files through them (replacing `PuffinThetaSketches`), read the parent file's footer and blob ranges instead of the whole file, and union only the parent snapshot's own blobs. The theta blob type is one constant, used by the NDV reader too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Take the metadata pointers of SnapshotStatisticsNdv by const reference (clang-tidy performance-move-const-arg). - Reserve the sketch task slots before scheduling them, so a scheduled task is always tracked. - expire_snapshots keeps a statistics file that a retained snapshot uses as a deletion-vector container, and lists a file that is both an expired deletion-vector container and an expired statistics file once. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/Storages/ObjectStorage/DataLakes/Iceberg/Compaction.cpp
Initialize the Puffin blob compression method for clang-tidy, and revert the hand edit of the generated PuffinMetadata doc: the page regenerates from the format documentation in PuffinBlockInputFormat.cpp, which already has the change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…DATA Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n expire_snapshots Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e_snapshots Metadata may spell one object in several ways, e.g. s3:// and s3a://, and deletion resolves the path, so comparing the raw text could delete a Puffin file a retained snapshot still uses. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing Binary sizes
The official master build is compiled with Object file sizes
|
| Object file | Master | PR | Δ |
|---|---|---|---|
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/IcebergTableStatisticsNdv.cpp.o |
new | 694.16 KiB | +694.16 KiB |
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/Puffin/PuffinThetaSketch.cpp.o |
222.75 KiB | 348.57 KiB | +125.82 KiB (+56.48%) |
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/ExpireSnapshotsExecute.cpp.o |
631.59 KiB | 652.44 KiB | +20.84 KiB (+3.30%) |
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
62 translation units recompiled, 488 s compile time in total, 61 of them have a recent master baseline.
Translation units without a recent master baseline:
src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergTableStatisticsNdv.cpp: 6.5 s
Match statistics files with master's storageIdentity in expire_snapshots: collectExpiredFiles now matches files by storage object, so retained statistics paths go back into the retained set. Check a Puffin blob's stored length against the cap before reading it, and bound the zstd window. Add [[nodiscard]] where modernize-use-nodiscard asks. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tics writes Prepares the ground for #131249, which writes NDV statistics on Iceberg commits: - `PuffinColumnThetaSketch` is the Theta sketch of one column, with the hashing of that PR: values are cast to a type whose `getDataAt` bytes are the Iceberg single-value serialization (decimals and `UUID` are encoded explicitly) and hashed with the new `IColumn::computeMurmurHash3Into` straight into the hash table of an `update_theta_sketch`. The result goes through a `theta_union` and gets `p = 1.0`, so it stays byte-identical to Iceberg's sketches. The `Puffin` output format and Iceberg statistics writes can both build on it. - `PuffinBlob::toJSON` and `PuffinReader` (footer, blobs on demand, `zstd` and `lz4` blobs) from that PR. - Blobs of unknown types are listed by `PuffinMetadata` and skipped by `Puffin`, as the Puffin specification requires, instead of failing the read. Related: #131249 Co-Authored-By: Claude Opus 5.5 <[email protected]>
With the setting on for the whole session, the cloud build arms background compaction on every IcebergLocal table, and clickhouse-local aborts on exit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
AI review of a later commit does not approve the PR, see the AI Review comment.
Use master's Puffin layer (ClickHouse#121982) instead of PuffinFile.{h,cpp}.
- Sketch columns with PuffinColumnThetaSketch; drop the own theta sketch, IColumn::computeMurmurHash3Into and its CMake workaround, and put minimalTwosComplementOffset back inline in dumpDecimalValue. - Union snapshot and parent sketches with the new unionThetaSketches in PuffinThetaSketch (validation included, a single sketch kept as is), so the writer no longer uses DataSketches directly nor needs USE_DATASKETCHES. - Keep the sketch of a field added after the parent snapshot without an initial-default: the parent's rows are all NULL in it. - expire_snapshots passes the expired statistics files to collectExpiredFiles instead of collecting and filtering them separately. - Drop gtest_puffin_file, which tested master's Puffin reader and writer. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…anged type - Take a parent blob only if the statistics entry's blob-metadata lists it, as the readers do. - Drop the parent sketch of a promoted field (int to long, float to double): it hashes the narrower encoding, so a union would inflate the NDV. - TODO in compaction: the statistics of the retained snapshots, whose files clearOldFiles deletes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…fault Co-Authored-By: Claude Opus 5.5 <[email protected]>
…writes none Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/Core/Settings.cpp
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…REST or Unity catalog The check runs before a commit writes any file. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@copilot resolve the merge conflicts on this branch. |
# Conflicts: # src/Core/Settings.cpp # src/Storages/ObjectStorage/DataLakes/Iceberg/Mutations.cpp
AI review of a later commit does not approve the PR, see the AI Review comment.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Iceberg tables written by ClickHouse now record per-column NDV statistics (theta sketches in Puffin files, as Spark's
compute_table_statswrites them), souse_iceberg_table_statistics_ndvworks for them. Enabled by the new experimental settingiceberg_write_table_statistics_ndv(off by default).Details
INSERT,ALTER UPDATE/DELETE,DROP PARTITION,OPTIMIZE) writes or carries forward its snapshot's sketches;expire_snapshotsremoves the expired ones.PuffinColumnThetaSketch, which hashes values as Spark does, so sketches from either engine union; a snapshot's sketches union with its parent's through the newunionThetaSketches.set-statistics). A statistics failure never fails the commit.OPTIMIZErewrites its data, which it does only when the table has position deletes; a fullOPTIMIZEkeeps only the current snapshot's statistics. A command that sketches a table without rewriting it is a follow-up.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/131249]
Version info
26.12.1.112-master(included in26.12and later)