Skip to content

Add support for reading Iceberg v3 deletion vectors - #110781

Merged
asya-ch merged 43 commits into
ClickHouse:masterfrom
linjiayu1025-collab:iceberg_reading_v3_delete_vectors
Sep 17, 2026
Merged

asya-ch merged 43 commits into
ClickHouse:masterfrom
linjiayu1025-collab:iceberg_reading_v3_delete_vectors

Conversation

@linjiayu1025-collab

@linjiayu1025-collab linjiayu1025-collab commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Resolves: #107502

Changelog category (leave one):

  • Experimental Feature

Changelog entry:
Add read support for Iceberg v3 deletion vectors stored in Puffin files.

Summary:

This PR adds read support for Iceberg v3 deletion vectors stored in Puffin files.
Supported:

  • Read Iceberg v3 deletion vector metadata from manifest entries:
    • referenced_data_file
    • content_offset
    • content_size_in_bytes
  • Read Puffin deletion vector blobs from object storage.
  • Validate DV blob length, magic bytes, and CRC.
  • Decode Roaring64 deletion vectors.
  • Apply deletion vectors during reads.
  • Support mixed reads with:
    • v2 parquet position delete files
    • v3 Puffin deletion vectors
  • Support table functions and table engines through the common Iceberg read path, including local/S3/Azure object storage.
    Not supported:
  • Writing Iceberg v3 deletion vectors.
  • Updating existing deletion vectors.
  • Compaction/rewrite of deletion vectors.
  • Container-level lazy decoding of Roaring bitmaps.
  • Hard memory limit on decoded Roaring bitmap memory.
  • Full Iceberg v3 feature support beyond deletion vector reads.
    Notes:
  • The implementation decodes the DV blob into a Roaring bitmap and applies it with a streaming iterator during data reads.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

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

Version info

  • Merged into: 26.10.1.35 (included in 26.10 and later)

@linjiayu1025-collab

Copy link
Copy Markdown
Contributor Author

@alexey-milovidov Can you help me check this feature when you have time

@asya-ch asya-ch self-assigned this Jul 29, 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.

Hey, thank you for your contribution! Please address my feedback, and I'll take another pass at reviewing afterwards.

Comment thread src/Core/SettingsChangesHistory.cpp Resolved
@asya-ch asya-ch added the can be tested Allows running workflows for external contributors label Jul 30, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f5463ff]

Summary: ❌

job_name test_name status info comment
Storage memory check FAIL
08_parts_analysis.sql FAIL cidb IGNORED

AI Review

Summary

This PR adds Iceberg v3 deletion-vector reads by parsing the new manifest fields, carrying the deletion-vector location through cluster read-task serialization, and applying Puffin-backed deletes in the Iceberg read path. The main flow is coherent and the new integration coverage is useful, but the current head still has one new correctness gap, one missing protocol-spec update, and a few previously discussed contract issues that are still present in the code.

Missing context / blind spots
  • ⚠️ Most build and integration jobs were still pending when I reviewed this. Fast test, Style check, Docs check, and the build-profile report had finished, but a full green CI run would still be the last runtime/build check.
Findings

⚠️ Majors

  • [src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergDataObjectInfo.cpp:141-153] The new DeletionVectorObject drops the manifest record_count, so readIcebergDeletionVector can no longer prove that the decoded bitmap cardinality matches the deletion-vector manifest entry. A malformed but internally consistent blob can therefore undelete rows silently instead of being rejected.
    Suggested fix: carry record_count through DeletionVectorObject and the cluster-function serialization, then validate the decoded bitmap cardinality against it in readIcebergDeletionVector.
  • [src/Core/ProtocolDefines.h:53] This bumps DBMS_CLUSTER_PROCESSING_PROTOCOL_VERSION, which changes the VERSIONED_CLUSTER_FUNCTION_PROTOCOL bytes announced in ServerHello, but the matching public spec at docs/reference/interfaces/specs/NativeProtocol.mdx is untouched and still documents current value 8.
    Suggested fix: update the English NativeProtocol spec in the same change to describe version 11 and the new Iceberg deletion-vector payload gated on it.
  • [dismissed by author -- https://github.com/Add support for reading Iceberg v3 deletion vectors #110781#discussion_r3832273715] [src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergDeletionVectorReader.cpp:39-54] The reader still trusts only manifest content_offset / content_size_in_bytes. If a corrupt manifest points at another valid deletion-vector-v1 blob in the same Puffin file, ClickHouse will apply deletes for the wrong data file instead of rejecting the metadata.
    Suggested fix: parse the Puffin footer here (or in the caller) and verify that the blob at this range is deletion-vector-v1 and that its referenced-data-file matches the current manifest entry before decoding.
  • [dismissed by author -- https://github.com/Add support for reading Iceberg v3 deletion vectors #110781#discussion_r3984507553] [src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergDataObjectInfo.cpp:109-153] The new docs and PR body say v3 deletion-vector reads are supported, but the read path still rejects any data file whose file_format is not PARQUET. Valid v3 tables with AVRO or ORC data files and Puffin deletion vectors will still fail here, so the feature contract is broader than the implementation.
    Suggested fix: either extend the row-number/delete path beyond Parquet, or narrow the docs/changelog/summary to say deletion-vector reads are supported only for Parquet-backed Iceberg data files.
Tests
  • ⚠️ Add a focused negative test for malformed deletion-vector metadata: a manifest entry whose targeted Puffin blob has the wrong cardinality or belongs to a different data file should be rejected rather than silently applied.
  • ⚠️ If the intended contract stays “v3 deletion-vector reads are supported” rather than “supported for Parquet-backed data files,” add a regression test with an ORC or AVRO data file plus a Puffin deletion vector.
Performance & Safety
  • ⚠️ [src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergMetadata.cpp:1397-1400] Pure deletion-vector reads still inherit format_settings.parquet.preserve_order = true from use_roaring_bitmap_iceberg_positional_deletes = 0, even though getPositionDeleteTransformer now always routes deletion vectors to the bitmap path. That keeps the slower ordered Parquet reader on the feature's default configuration for no correctness benefit.
Final Verdict

Status: ⚠️ Request changes
Minimum required actions:

  1. Preserve the deletion-vector record_count and validate decoded cardinality against it.
  2. Update docs/reference/interfaces/specs/NativeProtocol.mdx for cluster-function protocol version 11.
  3. Either validate the targeted Puffin blob against footer metadata or explicitly narrow the supported contract/docs to what the implementation actually guarantees today.

LLVM Coverage Report

Measured on commit f5463ff.

Metric Baseline Current Δ
Lines 88.50% 88.50% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 80.70% 80.70% +0.00%

Changed lines: Changed C/C++ lines covered: 284/316 (89.87%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Jul 30, 2026
@linjiayu1025-collab

Copy link
Copy Markdown
Contributor Author

@asya-ch
I addressed the requested changes.
use_roaring_bitmap_iceberg_positional_deletes = 1 keeps the existing bitmap behavior: v2 position deletes and Puffin deletion vectors are read during initialization and materialized into the bitmap.
With use_roaring_bitmap_iceberg_positional_deletes = 0, the Puffin deletion vector is also read and decoded once during IcebergStreamingPositionDeleteTransform initialization. Its Roaring64Map iterator is then added as a source to the existing streaming merge with v2 position delete sources.
This restores the setting-dependent choice between bitmap and streaming transforms, and preserve_order is enabled only for the streaming path. Container-level lazy decoding remains unsupported and is out of scope for this experimental read support.
I also added coverage for both transform modes, mixed v2/v3 deletes, and deletion vectors applying only to their referenced data file.

@clickhouse-gh

clickhouse-gh Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing f5463ffc8 with master bdd39260f (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

24 object files changed (+101.81 KiB total), 1 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/IcebergDeletionVectorReader.cpp.o new 61.71 KiB +61.71 KiB

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

313 translation units recompiled, 2883 s compile time in total, 312 of them have a recent master baseline.

Median compile-time ratio to the baselines is ×0.88 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost -469.7 s (-14%) in total before that adjustment.

Translation units without a recent master baseline:

  • src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergDeletionVectorReader.cpp: 6.2 s

Job report

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

Thank you for updating the code! I think the overall logic here is good, it just needs some cleanup (see other comments). It will be great to have deletion vector support.

@linjiayu1025-collab

Copy link
Copy Markdown
Contributor Author

@asya-ch Thanks for reviewing, all the comment have been fixed. Please review it for me again.

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

Found a few more perf fixes. Almost there!

@linjiayu1025-collab

Copy link
Copy Markdown
Contributor Author

@asya-ch the perf fixes has been modified , Do we need to revise the questions the robot asked? Thanks, please help me review it

@asya-ch

asya-ch commented Aug 17, 2026 •

Copy link
Copy Markdown
Collaborator

@asya-ch the perf fixes has been modified , Do we need to revise the questions the robot asked? Thanks, please help me review it

Yes, we'll need to revise the optimization logic and add a test, but please hold off before spending more time on it.

There's a competing PR (#113561) that also implements deletion vector support. I've started to review it, but it is quite long. I want to take some time to better understand the design there before merging either PR. The advantage of that PR is that it has caching, optimizations around count(), and extensive tests.

I'll try to get through it this week and decide how to proceed. We might merge just one PR or combine ideas from the two. Thanks for your patience.

@asya-ch

asya-ch commented Aug 19, 2026 •

Copy link
Copy Markdown
Collaborator

@linjiayu1025-collab, I would like to proceed with this PR. Could you please add the optimization logic and a test for it?

I think the other PR can be broken up into smaller PRs that are merged after this one.

Comment thread src/Core/Settings.cpp Resolved

@scanhex12 scanhex12 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks good, some cosmetics


void IcebergDataObjectInfo::addPositionDeleteObject(Iceberg::ProcessedManifestFileEntryPtr position_delete_object, const String & resolved_storage_path)
{
const bool is_deletion_vector = Poco::toUpper(position_delete_object->parsed_entry->file_format) == "PUFFIN";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

seems strange as addPositionDeleteObject doesn't match with deletion vectors, so this place should be refactored somehow

if (info.deletion_vector.has_value())
throw Exception(ErrorCodes::ICEBERG_SPECIFICATION_VIOLATION, "Multiple deletion vectors apply to the same Iceberg data file");

info.position_deletes_objects.clear();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why do we need it? let's check that it's not empty and throw an exception

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.

You are allowed to have a mix of position delete files and deletion vectors (say, if a table was upgraded from V2 to V3).

The spec says that if there is a deletion vector on a certain data file, reads must disregard the position files.

I'll add a comment to make it more clear.

}

void IcebergStreamingPositionDeleteTransform::fetchNewChunkFromSource(size_t delete_source_index)
IcebergStreamingPositionDeleteTransform::DeletionVectorState::DeletionVectorState(std::unique_ptr<roaring::Roaring64Map> bitmap_)

@scanhex12 scanhex12 Sep 16, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we have streaming position delete transform and bitmap?

Streaming here means that we don't read the whole delete file at once. We read it chunk by chunk (as iceberg spec gives us a guarantee that this file is sorted). When we have deletion vector we apply the whole part at once, so it seems more like non-streaming way as we don't need to rely on the rule of sorting

I think you need to move this bitmap into non-streaming transform

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.

Good point, we can disregard the setting for deletion vectors.

@subkanthi subkanthi mentioned this pull request Sep 16, 2026
11 of 17 tasks
Comment thread src/Core/ProtocolDefines.h Resolved
@asya-ch
asya-ch added this pull request to the merge queue Sep 17, 2026
Merged via the queue into ClickHouse:master with commit e601945 Sep 17, 2026
176 of 178 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 17, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

@linjiayu1025-collab @asya-ch — title/description suggestions:

Description (currently incomplete):

  • Why: The "Not supported" list covers deletion-vector writes but not the two restrictions the diff actually imposes on existing behaviour: mutations are now refused for ALL format-version 3 tables (not just those with deletion vectors), and compaction is refused for tables with deletion vectors. The description also does not mention that test_row_lineage.py::test_row_id_clickhouse_survives_delete -- green on master, 1518 runs in 21 days -- is deleted rather than converted.

  • Suggested addition:

    Behaviour changes on existing paths:

    • ALTER TABLE ... DELETE / UPDATE now throw NOT_IMPLEMENTED for every Iceberg format-version 3 table, including tables written by ClickHouse (iceberg_format_version = 3) that contain no deletion vectors. These statements succeed today.
    • OPTIMIZE now throws NOT_IMPLEMENTED for tables whose snapshot contains deletion vectors.
    • test_row_lineage.py::test_row_id_clickhouse_survives_delete is removed because of the first item; say why, or convert it to assert the new error.

Ignore if intentional.

groeneai added a commit to groeneai/ClickHouse that referenced this pull request Sep 19, 2026
`test_optimize_rejected_on_format_v3` created a positional delete so that
compaction would have work to do, then asserted that OPTIMIZE is refused on a
format-version 3 table. Since 2288bde (ClickHouse#110781, "Add support for reading
Iceberg v3 deletion vectors") `Iceberg::mutate` refuses DELETE and UPDATE
outright on format-version 3, so that setup step throws NOT_IMPLEMENTED and the
test now aborts before reaching its own assertion. It was red on all six
integration flavours that ran it at 5abe53e.

The delete file was never needed for the refusal: the format-version check sits
at the top of `getPlan`, ahead of the manifest scan that computes
`need_optimize`, so a v3 table is rejected whether or not it carries delete
files. Dropping the DELETE therefore keeps the arm's subject intact and leaves
it able to fail: with the guard deleted from `Compaction.cpp` the OPTIMIZE
succeeds and the assertion reddens (verified against a mutant build).

Co-Authored-By: Claude Opus 5 <[email protected]>
@alexey-milovidov alexey-milovidov mentioned this pull request Sep 20, 2026
47 of 72 tasks
@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-experimental Experimental Feature 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.

Support reading Iceberg v3 deletion vectors

6 participants