Skip to content

Iceberg deletion vectors support - #113561

Closed
ianton-ru wants to merge 94 commits into
ClickHouse:masterfrom
ianton-ru:iceberg-puffin-deletion-vectors-read-2
Closed

ianton-ru wants to merge 94 commits into
ClickHouse:masterfrom
ianton-ru:iceberg-puffin-deletion-vectors-read-2

Conversation

@ianton-ru

@ianton-ru ianton-ru commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • New Feature

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

Iceberg deletion vectors support

Goal

Add read support for Iceberg v3 Puffin deletion vectors (deletion-vector-v1) so ClickHouse applies DV bitmaps when reading Iceberg tables (local / object storage / cluster), without writing DVs.
Also expose SQL input formats Puffin / PuffinMetadata for inspecting Puffin files, and a process-global Puffin files cache for parsed DV bitmaps.


High-level architecture

Manifest (position deletes, content=2)
        │
        ▼
IcebergIterator ──loadDeletionVector──► Puffin footer bind + blob read
        │                                      │
        │                                      ▼
        │                              PuffinFilesCache (optional)
        ▼
IcebergDataObjectInfo.excluded_rows  (roaring bitmap of deleted positions)
        │
        ▼
StorageObjectStorageSource / DeletionVectorTransform
        │
        ├── need_only_count → cardinality via roaring rank (no Filter materialization)
        └── full read → exclude rows (DV before equality deletes)

Shared Puffin parsing / DV deserialize lives under:

Component Role
PuffinDeletionVectorReader Envelope peek, CRC, roaring deserialize, size ceilings
PuffinFilesCache Context-global cache of cloned exclusion bitmaps
IcebergDeletionVector Iceberg-specific load + validation vs data-file record_count
Iceberg path uses seekable object-storage reads. SQL formats also support a non-seekable fallback (pipes / input_format_allow_seeks = 0).

Feature behavior (what users get)

  1. Iceberg reads honor live Puffin DVs attached as position-delete manifest entries (content = 2 / deletion vectors).
  2. Non-Parquet data files with DVs are rejected (fail closed).
  3. Equality deletes still work; DVs are applied before equality filters so file-local row numbers stay correct.
  4. Trivial / snapshot COUNT shortcuts fail closed when any live deletes (equality, position files, or DVs) are present — do not trust poisoned snapshot summaries or naive data − deletes arithmetic.
  5. Cluster / parallel read fails closed if the cluster protocol cannot carry excluded_rows or delete metadata (no silent drop of deletes).
  6. SYSTEM DROP PUFFIN FILES CACHE (spaced form; underscore alias accepted) clears the cache; gated by access control.
  7. Settings: use_puffin_files_cache and related server/cache size settings (see Settings / docs).

Safety / fail-closed decisions (intentional)

Reviewers should treat these as product decisions, not accidental omissions:

  • Absolute ceilings (not FormatSettings knobs): footer payload (16 MiB), DV blob size (2 GiB, Iceberg-aligned), materialized positions, non-seekable buffer size.
  • Envelope peek before allocating full DV blob; CRC after bounded read.
  • Footer bind: unique blob at (content_offset, content_size) matching referenced_data_file + cardinality.
  • Positions must be < data_file.record_count.
  • Cache keys include storage identity, path, etag, slice, referenced data file, expected cardinality, and data-file row count.
  • Cache returns clones of bitmaps so callers cannot mutate shared cache state.
  • Weak / empty etags skip the cache (isEtagUsableAsCacheKey).
  • COUNT / need_only_count: prefer roaring cardinality / rank; avoid building a full Filter over all file rows when only a count is needed; skip file-level count cache when excluded_rows is present.
    Explicitly out of scope / deferred (workspace rule): Poco JSON Int64 wrap of 2^63 / 2^63+1 — do not treat as a defect to fix in this PR.

Tests (where to look)

Unit / gtest

  • Puffin: envelope, bounds, cardinality, footer bind, referenced_data_file, non-seekable buffer limit
  • Cache: key (incl. storage identity), clone, weight, metrics (clear-during-load, waiter, hit-after-clear)
  • Iceberg: count shortcuts, DV positions, position-delete kind presence, parquet row-deletes guard
  • Parquet: need_only_count with buckets, row-group global offsets
  • CacheBase / LRU: getOrSetWithOutcome*

Stateless

  • Puffin happy path, allow_seeks=0, stdin pipe, error fixtures under tests/queries/0_stateless/data_puffin/
  • SYSTEM DROP PUFFIN FILES CACHE parsing / privileges
    Integration
  • tests/integration/test_storage_iceberg_with_spark/test_deletion_vectors.py
  • MinIO fixtures under data_minio/ (dv_puffin_*), generator generate_iceberg_dv_fixture.py

Docs touched

  • Iceberg table engine / table function
  • Puffin / PuffinMetadata formats
  • SYSTEM DROP PUFFIN FILES CACHE

ianton-ru and others added 30 commits August 5, 2026 13:20
Wire manifest parsing for puffin delete entries, load deletion-vector-v1
blobs into excluded_rows, and apply them during Iceberg table reads.

Co-authored-by: Cursor <[email protected]>
Add headers required to compile ReadBufferFromFileBase and
RoaringBitmapWithSmallSet usage.

Co-authored-by: Cursor <[email protected]>
Track PuffinFilesRead count and PuffinFileReadMicroseconds when reading
puffin footers and deletion-vector blobs.

Co-authored-by: Cursor <[email protected]>
Cover multi-step inserts, deletes, schema evolution, updates, and Spark
rewrite_data_files compaction in integration and stateless fixtures.

Co-authored-by: Cursor <[email protected]>
Introduce an in-memory SLRU cache on global Context for parsed puffin file content, with server/session settings and SYSTEM DROP PUFFIN FILES CACHE support.

Co-authored-by: Cursor <[email protected]>
Align the parser alias and access type name with other cache drop commands such as SYSTEM DROP PARQUET_METADATA_CACHE.

Co-authored-by: Cursor <[email protected]>
Use the global cache when use_puffin_files_cache is enabled and puffin file etag is available, and add a stateless test for cache hit/miss behavior.
Cover cache hit/miss behavior in stateless and S3 integration tests, document SYSTEM DROP PUFFIN_FILES_CACHE, and extend parser and privileges coverage.

Co-authored-by: Cursor <[email protected]>
Deletion vector row positions are meaningful only for a specific data file, so cache entries must not be shared across different referenced_data_file values that reuse the same puffin blob slice.

Co-authored-by: Cursor <[email protected]>
Iceberg reads manifest offset and length directly, so check offset + length against the puffin file size before allocation to reject corrupt metadata early.

Co-authored-by: Cursor <[email protected]>
Callers must not share the mutable cached ExcludedRows instance, so getOrSetDeletionVector now returns an independent copy on every hit and miss.

Co-authored-by: Cursor <[email protected]>
Cardinality-based weight underestimated sparse roaring bitmaps, so cache byte limits could be exceeded; use getAllocatedBytes instead.

Co-authored-by: Cursor <[email protected]>
Repeated reads of data files with zero deleted rows should skip puffin I/O, so treat cached nullptr as an explicit empty deletion vector and account for it with a tiny cache entry weight.

Co-authored-by: Cursor <[email protected]>
Enforce the shared puffin materialization ceiling and early roaring cardinality checks on Iceberg reads by wiring manifest record_count into readDeletionVectorFromPuffin.

Co-authored-by: Cursor <[email protected]>
Fail closed with NOT_IMPLEMENTED before loading puffin DVs when the data file is not Parquet, matching position-delete behavior and avoiding LOGICAL_ERROR in DeletionVectorTransform.

Co-authored-by: Cursor <[email protected]>
ConstChunkGenerator bypasses DeletionVectorTransform, and the cache key is data-file identity only while Iceberg deletion vectors change independently.

Co-authored-by: Cursor <[email protected]>
…reader.

Reject mismatched magic or combined_length before a full up-to-2GiB blob allocate/read on the Iceberg path, matching the SQL Puffin format guard.

Co-authored-by: Cursor <[email protected]>
Downgrading to protocol <5 previously omitted deletion/selection vectors and could return deleted rows on mixed-version workers.

Co-authored-by: Cursor <[email protected]>
Restore expected_cardinality, materialization/blob ceilings, and little-endian roaring parsing that landed via skipped fix-puffin-deletion-vector-v1 merges, so Iceberg callers and further cherry-picks match the shared API.

Co-authored-by: Cursor <[email protected]>
Manifest record_count above the materialization ceiling can fail closed without peeking or allocating up to the 2 GiB blob cap.

Co-authored-by: Cursor <[email protected]>
ObjectIteratorSplitByBuckets previously sliced IcebergDataObjectInfo to ObjectInfo, dropping equality and position deletes under BUCKET granularity.

Co-authored-by: Cursor <[email protected]>
…unt cache.

Bucketed cluster tasks previously counted whole files and could poison the schema row-count cache with partial totals under a file-only key.

Co-authored-by: Cursor <[email protected]>
…umbers.

Equality FilterTransform shrinks chunks without updating ChunkInfoRowNumbers::applied_filter; running DeletionVectorTransform first keeps DV positions mapped to absolute file rows.

Co-authored-by: Cursor <[email protected]>
…ion deletes.

Protocol versions below WITH_ICEBERG_METADATA omit iceberg_info, so workers would skip delete transforms and return deleted rows; reject those tasks instead.

Co-authored-by: Cursor <[email protected]>
…locate.

Mirror the shared Iceberg reader: when deleted_rows is projected, fail closed on footer cardinality above the materialization ceiling before reading the blob.

Co-authored-by: Cursor <[email protected]>
Protocol versions below WITH_FILE_BUCKETS_INFO omit bucket subsetting, so workers would re-read whole files per bucket task and return duplicated rows.

Co-authored-by: Cursor <[email protected]>
Trivial count and need_only_count cannot apply equality filters correctly; also skip the file count cache for equality and position deletes whose identity is not in the cache key.

Co-authored-by: Cursor <[email protected]>
Share one canUseCountFromFilesCache helper between read and cache-write paths, and keep only the positive equality-before-DV mapping test.

Co-authored-by: Cursor <[email protected]>
ianton-ru and others added 13 commits August 14, 2026 12:51
Protocol versions below Iceberg metadata support omit iceberg_info entirely, so workers must not silently drop schema IDs and file format even when delete lists are empty.

Co-authored-by: Cursor <[email protected]>
Puffin v1 requires these footer fields to be unknown placeholders; accept only the specified values in parse and Iceberg bind.

Co-authored-by: Cursor <[email protected]>
Row policies and PREWHERE reduce emitted rows while the cache key is file identity only; treat them like filter DAGs in FormatFilterInfo::hasFilter.

Co-authored-by: Cursor <[email protected]>
Match the Iceberg reader fail-closed order so SQL FORMAT Puffin does not
I/O or allocate up to 2 GiB when footer cardinality exceeds the materialization ceiling.

Co-authored-by: Cursor <[email protected]>
Use false as previous_value so SET compatibility can disable the new
default-on Puffin files cache on older Antalya versions.

Co-authored-by: Cursor <[email protected]>
Iceberg v3 writers must not add position-delete files; fail closed until
deletion-vector writes are implemented.

Co-authored-by: Cursor <[email protected]>
Equality deletes still demote the fast path; count-from-files cache stays
fail-closed separately so DV count can use Parquet metadata plus bitmap
cardinality.

Co-authored-by: Cursor <[email protected]>
Coalesced multi-DV Puffin files shared one footer parse per file instead
of reparsing the full footer on every deletion-vector slice miss.

Co-authored-by: Cursor <[email protected]>
Empty deletion vectors no longer weigh one byte; long unique keys are
bounded by the configured byte limit even when max entries is unlimited.

Co-authored-by: Cursor <[email protected]>
Replace the sibling CacheBase footer LRU and its metrics with a
count-bounded mutex map so coalesced multi-DV files still parse once.

Co-authored-by: Cursor <[email protected]>
Clear and disable footer memoization when the cache size is 0, and
bound retained footers by the same approximate byte budget as DVs.

Co-authored-by: Cursor <[email protected]>
CI pre-sets send_logs_level to warning, so the previous :-error default
did not suppress IcebergMetadata v1/v2 schema fallback Warnings on stderr.

Co-authored-by: Cursor <[email protected]>
@asya-ch

asya-ch commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Hello, thank you for your contribution! To make review easier, would it be possible to split this diff into multiple smaller PRs?

For example, I think some of the changes in CacheBase.h, Reader.cpp, FormatFilterInfo, PuffinBlockInputFormat.cpp, and src/AggregateFunctions/AggregateFunctionGroupBitmapData.h could be filed as a preparatory PR.

@asya-ch

asya-ch commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Actually, there's another PR open that implements deletion vectors: #110781, and I'd like to merge that one first.

If it's okay with both you and @linjiayu1025-collab, I would like to adapt some of these tests for that PR, with co-authored-by credit so that the work is still attributed to you.

There are other great changes in here, especially the fixes for FormatFilterInfo, the clone() fix in IcebergDataObjectInfo, the count() optimizations, and the caching. Could you please open these as separate small PRs?

The fixes and hardening can go up right away. Count() optimizations and caching will need to wait for #110781 to merge.

@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Sep 4, 2026
@subkanthi subkanthi mentioned this pull request Sep 16, 2026
11 of 17 tasks
@alexey-milovidov alexey-milovidov mentioned this pull request Sep 20, 2026
47 of 72 tasks
@clickhouse-gh

clickhouse-gh Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Dear @asya-ch, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@asya-ch

asya-ch commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

Closing this PR. Please feel free to open the changes mentioned above (the fixes for FormatFilterInfo, the clone() fix in IcebergDataObjectInfo, the count() optimizations, and the caching) in a separate PR.

@ianton-ru

Copy link
Copy Markdown
Contributor Author

@asya-ch
#122835 - fix for FormatFilterInfo
#122861 - fir for clone() and optimization for count()
#122899 - cache

@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...

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants