Skip to content

Add virtual columns from v3 spec for CDC pipelines - #115603

Merged
scanhex12 merged 10 commits into
masterfrom
iceberg_cdc
Aug 28, 2026
Merged

scanhex12 merged 10 commits into
masterfrom
iceberg_cdc

Conversation

@scanhex12

@scanhex12 scanhex12 commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • New Feature

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

Iceberg v3 has two new fields in manifest file - first_row_id and last_seq_num. This PR allows to read them as virtual columns


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

@clickhouse-gh

clickhouse-gh Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b7ebe59]

Summary: ❌

job_name test_name status info comment
Integration tests (arm_binary, distributed plan, 2/4) FAIL
test_storage_nats/test_nats_jet_stream.py::test_nats_restore_failed_connection_without_losses_on_write FAIL cidb, issue
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/feature_docs.py FAIL

AI Review

Summary

This PR threads Iceberg v3 row-lineage metadata (first_row_id, _row_id, _last_updated_sequence_number) through the reader, manifest pruning, distributed object info, and system.iceberg_files. The direction is right, but the current implementation still breaks row-lineage semantics on some supported snapshots and file formats, so I do not think it is ready to merge.

PR Metadata
  • Changelog category: New Feature matches the diff.
  • Changelog entry: required and present, but it names manifest internals instead of the user-visible behavior. Suggested replacement: Iceberg format-version 3 tables can now expose the _row_id and _last_updated_sequence_number virtual columns, and system.iceberg_files now shows the resolved first_row_id for each data file.
Findings
  • ❌ Blockers
  • [src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFileIterator.cpp:484-489] first_row_id inheritance still skips EXISTING data entries. The first snapshot after a format-version 2 -> 3 upgrade carries pre-upgrade files forward as live EXISTING entries with parsed_first_row_id = NULL, so this loop leaves entry->first_row_id unset for those files. That makes both _row_id and _last_updated_sequence_number come back NULL, prevents row-lineage pruning, and leaves system.iceberg_files.first_row_id blank for the carried-forward data. Suggested fix: assign inherited row ids to every live DATA entry with a null parsed_first_row_id, not only ADDED ones.
  • [src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFileIterator.cpp:195-209] The pruning fallback still treats “row-lineage field missing from manifest stats” as proof that the field is absent whenever any ordinary column stats are present. A copy-on-write file with materialized _row_id / _last_updated_sequence_number but no reserved-field stats will therefore be pruned on the bogus inherited range, which can drop live rows. Suggested fix: only use the exact inherited range when the manifest positively proves the reserved fields are absent; otherwise skip row-lineage pruning for that file unless explicit lineage bounds are available.
  • [src/Storages/VirtualColumnUtils.cpp:580-603] [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/115603#discussion_r3829217101] _row_id is still effectively Parquet-only: if the reader cannot provide physical row positions and no materialized lineage column was read, this path returns NULL for every row. That is still a real correctness gap because the PR and the new Avro pruning test both treat _row_id as a usable Iceberg v3 virtual column, but on non-Parquet files the actual values remain NULL. Suggested fix: either reject _row_id explicitly for non-Parquet Iceberg files or add a non-Parquet implementation and value-level coverage.
Tests
  • ⚠️ Add an integration test that upgrades a table from format-version = 2 to 3 and verifies carried-forward EXISTING data files still expose _row_id, _last_updated_sequence_number, and system.iceberg_files.first_row_id.
  • ⚠️ Strengthen tests/integration/test_storage_iceberg_with_spark/test_row_lineage_pruning.py:210-266 to assert the actual row-lineage values for the Avro/ORC cases, not only pruned-file counters on SELECT id ... WHERE _row_id .... The current checks still pass even if _row_id itself is always NULL.
Final Verdict

❌ Changes requested.

LLVM Coverage Report

Measured on commit b7ebe59.

Metric Baseline Current Δ
Lines 88.40% 88.50% +0.10%
Functions 92.00% 92.00% +0.00%
Branches 80.80% 80.80% +0.00%

Changed lines: Changed C/C++ lines covered: 383/389 (98.46%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Aug 20, 2026
Comment thread src/Storages/VirtualColumnUtils.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing b7ebe592d with master d2237d7d0 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of fd57f120f; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 712.38 MiB 707.03 MiB -5.36 MiB (-0.75%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Object file sizes

39 object files changed (+82.38 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFileIterator.cpp.o 297.74 KiB 317.10 KiB +19.36 KiB (+6.50%)
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/StorageObjectStorageSource.cpp.o 995.94 KiB 1013.23 KiB +17.29 KiB (+1.74%)
src/CMakeFiles/dbms.dir/Processors/Transforms/TTLDeleteFilterTransform.cpp.o 133.34 KiB 116.63 KiB -16.71 KiB (-12.53%)

835 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

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

Job report

for (size_t row_index = 0; row_index < total_rows; ++row_index)
{
const auto parsed_entry = manifest_file_deserializer->getParsedManifestFileEntry(row_index);
if (parsed_entry->content_type != FileContentType::DATA || parsed_entry->status != ManifestEntryStatus::ADDED

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Iceberg v3 first_row_id inheritance is not limited to ADDED data files. The important case is the first commit after upgrading a table from v2 to v3: the carried-forward files are written as EXISTING entries with first_row_id = null, and the reader is supposed to assign them from the manifest's first_row_id plus the preceding record_counts.

Because this loop skips every EXISTING entry, those live files keep entry->first_row_id == null, so both _row_id and _last_updated_sequence_number come back NULL for all pre-upgrade rows and row-lineage pruning never fires on them. The inheritance pass needs to cover any live DATA entry with a null parsed_first_row_id, regardless of status.

{
std::vector<UInt64> row_positions;
#if USE_PARQUET
if (auto chunk_info = chunk.getChunkInfos().get<ChunkInfoRowNumbers>(); chunk_info && virtual_values.first_row_id)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This makes _row_id silently Parquet-only. For a v3 Iceberg table written as ORC/Avro, first_row_id is still available from the manifest, but no non-Parquet reader attaches ChunkInfoRowNumbers, so row_positions stays empty here. Since materialized_row_ids are only requested for Parquet, the code falls into the default-null branch below and returns _row_id = NULL for every row.

If row-lineage virtual columns are meant to work only for Parquet, the read path should reject them explicitly for other Iceberg file formats; otherwise this needs a non-Parquet implementation and coverage instead of a silent null result.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

For a v3 Iceberg table written as ORC/Avro

Useless case

return;
}

if (entry.first_row_id.has_value())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This fallback is only safe for append-only files. A copy-on-write v3 file can still carry materialized _row_id / _last_updated_sequence_number values that diverge from the contiguous [first_row_id, first_row_id + record_count) block, and the manifest does not guarantee min/max stats for those reserved fields.

If the writer emits ordinary column stats but omits row-lineage stats, has_materialized_row_lineage stays false and this branch prunes on the bogus file-level range, which drops live rows. A concrete case is the rewritten file from test_materialized_row_ids_are_not_pruned_away: the file keeps row ids 0..3, the manifest advertises first_row_id = 4, and WHERE _row_id = 1 would incorrectly prune the file if only non-lineage stats are present.

The safe fallback here is "do not prune by row lineage" unless the manifest proves the reserved row-lineage columns are absent or provides usable bounds for them.

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.

I think this comment makes sense

// always zero in case of format version 1
const Int64 inherited_sequence_number;
const Int64 inherited_snapshot_id;
const std::optional<UInt64> inherited_first_row_id;

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.

inherited_first_row_id -> maybe I missed it, where is this used ?

@scanhex12 scanhex12 Aug 28, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, it's maybe strange to have both inherited_first_row_id and inherited_first_row_ids. I'll replace with one lazy-materialised vector

std::map<Int32, Int64> column_sizes;
std::map<Int32, Int64> value_counts;
std::vector<Int32> equality_ids;
std::optional<UInt64> first_row_id;

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.

For this one, we need to add Column right

{"equality_ids", std::make_shared<DataTypeArray>(std::make_shared<DataTypeInt32>()), "Equality field IDs for equality delete files (empty for non-equality-delete files)."},
?
you dont want to add that is it ?
Then this variable is not needed then ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch

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

Rest all LGTM

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

LGTM

@scanhex12
scanhex12 enabled auto-merge August 28, 2026 20:16
@scanhex12
scanhex12 added this pull request to the merge queue Aug 28, 2026
Merged via the queue into master with commit 8eb6c42 Aug 28, 2026
172 of 175 checks passed
@scanhex12
scanhex12 deleted the iceberg_cdc branch August 28, 2026 21:02
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 28, 2026
zvonand added a commit to Altinity/ClickHouse that referenced this pull request Sep 29, 2026
Antalya 26.6 - Backport of ClickHouse#115603 - read row_lineage(iceberg v3) fields as virtual columns
alexey-milovidov pushed a commit to valerypetrov/ClickHouse that referenced this pull request Oct 10, 2026
…ge statistics

`addRowLineageHyperrectangles` took "some column of the manifest entry has
`column_sizes`" as proof that a lineage column with no statistics is absent
from the data file, and pruned `_row_id` / `_last_updated_sequence_number`
on the inherited block `[first_row_id, first_row_id + record_count - 1]` /
`[sequence_number, sequence_number]`. The Iceberg spec makes every metric map
optional and a missing id means unknown, so a copy-on-write rewritten file
whose materialized values lie below that block was skipped and its rows lost
(ClickHouse#124271). The branch came with ClickHouse#115603.

Without declared bounds a lineage column now gets the existing fallback
`[0, top of the inherited block]`: a materialized row id is below the table's
`next-row-id` and a copied sequence number belongs to an earlier commit.

The new integration test strips only the lineage statistics from a Spark
copy-on-write manifest. Seven count assertions that encoded the old lower
bound are updated to the fallback numbers, and the wrapped-block probe moves
to `_row_id >= 20`, which still distinguishes the overflow guard.

Closes ClickHouse#124271

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

pr-feature Pull request with new product 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.

3 participants