Skip to content

Fix Iceberg _row_id and _last_updated_sequence_number returning stored values for data files without first_row_id - #130117

Open
groeneai wants to merge 4 commits into
ClickHouse:masterfrom
groeneai:iceberg-stored-row-lineage-without-first-row-id
Open

groeneai wants to merge 4 commits into
ClickHouse:masterfrom
groeneai:iceberg-stored-row-lineage-without-first-row-id

Conversation

@groeneai

@groeneai groeneai commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #130021
Related: #130100
Related: #130010

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fixed _row_id and _last_updated_sequence_number of an Iceberg data file that has no first_row_id (data written before the table was upgraded to format version 3): they are now NULL also when the file stores values in these columns. Closes #130021.

Description

On v26.10.2.103-stable, the DuckDB table row_lineage_stored_columns of #130021 read at snapshot 1111111111111111111 (written before the upgrade to format version 3, so its data file has no first_row_id) returns 100, 103 in _row_id and 7, 9 in _last_updated_sequence_number, the values its Parquet file stores. The spec reads both columns as NULL for every row of such a file, whatever it stores.

Two places used the stored values:

  • StorageObjectStorageSource::generate passed the stored columns on, and a non-NULL stored value wins over the inherited one; only the inherited half checked first_row_id.
  • getFormatFilter kept the lineage conjuncts in the filter pushed into the format, so Parquet skipped row groups by the stored statistics before the values were reset (WHERE _row_id IS NULL returned 0 of 4 rows), and the query condition cache could replay that verdict for an older snapshot. Fix Iceberg _row_id and _last_updated_sequence_number filters losing rows of files that store lineage values #130100 (merged) fixed this one.

Now generate drops the stored lineage columns of a file without first_row_id, so both columns are NULL. The PR carried #130100's commit until it merged; after merging master, the diff is this change and its test.

Validation: the new test 05583_iceberg_v3_stored_row_lineage_without_first_row_id fails on master (re-checked on 2026-11-22) and passes 50/50; the Iceberg row lineage integration tests pass.

🤖 Generated with Claude Code


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

groeneai and others added 3 commits November 8, 2026 08:52
…row_id`

A data file without `first_row_id` (every data file of a snapshot written before the table was
upgraded to format version 3) has NULL `_row_id` and `_last_updated_sequence_number` for every
row, also where the file stores values in these reserved columns (spec, "Row Lineage for Upgraded
Tables"). The source passed the stored values on; it now drops them for such a file, so both
columns take the NULL path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`getFormatFilter` kept the conjuncts on `_row_id` and
`_last_updated_sequence_number` for Iceberg, so the Parquet reader pruned row
groups, pages and dictionaries by the statistics of the column stored in the
data file. Those statistics do not cover rows that store NULL and inherit
the value, so a filter above the stored maximum skipped row groups with
matching inherited values. After a Spark copy-on-write `UPDATE` the rewritten
file stores `_last_updated_sequence_number` [1, NULL, 1, 1], and
`WHERE _last_updated_sequence_number = 2` lost the updated row with the
default `input_format_parquet_filter_push_down = 1`.

The lineage columns are now treated like every other virtual column added
after the format; the filter is still applied after the source, and the
manifest-level pruning keeps skipping whole files where declared bounds
allow it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

groeneai commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review of the same tree (0 blocker, 0 major).

# Sev Finding Verdict Evidence / action
- - No findings - -

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-review-slot-11:20261108-094800

@clickhouse-gh

clickhouse-gh Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6e96952]

Summary: ✅


AI Review

Summary

This PR fixes Iceberg reads of data files without first_row_id: stored _row_id and _last_updated_sequence_number values are discarded so both columns return NULL, as required by the Iceberg specification. Files with an assigned first_row_id retain their stored values and inheritance behavior. The new stateless regression test covers both projections together and separately, mixed and fully populated stored columns, IS NULL filters, the first write after upgrading, historical snapshots, and query condition cache reuse. No actionable findings in the current diff at 6e96952aa5b88c8998f5bdd5abfd11a586d269c4.

Final Verdict

Status: ✅ Approve

@groeneai

groeneai commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The DuckDB row_lineage_stored_columns table at snapshot 1111111111111111111, and the new test 05583, fail on every run of the master binary.
b Root cause explained? Yes. generate passed the stored lineage columns of a file without first_row_id on, and a stored non-NULL value wins; the Iceberg format filter kept lineage conjuncts, so Parquet pruned by the stored statistics and the condition cache stored that verdict.
c Fix matches root cause? Yes. The stored columns are dropped at the source, keyed on the metadata first_row_id; the one exception that pushed lineage conjuncts into the format is removed.
d Test intent preserved / new tests added? Yes. New stateless test 05583 (values, IS NULL filters, cross-snapshot condition cache); no existing test changed.
e Both directions demonstrated? Yes. Master FAIL, fix OK; mutants dropping either reset, the first_row_id condition, or the filter change each fail the test.
f Fix is general across code paths? Yes. Value assembly, row-group/page/dictionary pruning and the condition cache are covered for every format; inherited values, manifest pruning, distributed reads and the count-from-cache path were checked; PREWHERE on these columns is rejected.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes. Each column stored alone or together, with and without NULLs, one or both projected, IS NULL and mixed filters, time travel by snapshot id and by metadata file. Both columns are Nullable(UInt64).
h Backward compatible? (maintainer-approved exception only) Yes. No setting; reads now follow the spec. Parquet no longer prunes row groups by lineage columns; manifest-level pruning stays.
i Invariants and contracts preserved? Yes. The reader header is unchanged (the stored columns are still read, then dropped), so all files of a query match the shared key condition; chunk column counts stay equal.

Session id: cron:clickhouse-impl-slot-5:20261108-085000

@groeneai

groeneai commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author

cc @scanhex12 @alesapin, could you review this and add the can be tested label so CI runs? An Iceberg data file without first_row_id returned the _row_id / _last_updated_sequence_number values it stores instead of NULL, because generate passed the stored columns on; they are now dropped for such a file, and the second commit is the removal of lineage conjuncts from the format filter from #130100, byte-identical, so the two PRs merge in either order.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Nov 8, 2026
@clickhouse-gh clickhouse-gh Bot added can be tested Allows running workflows for external contributors comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 8, 2026
@groeneai

groeneai commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 30c9a78

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Build profile diff infra, not from this PR (no ci/ file in the diff): all 8 readiness probes to the CI logs cluster hit Read timed out. (read timeout=3), so has_pr_data raised LogClusterNotReady: the endpoint never became ready #129675 (mine, open)
CH Inc sync - CH Inc sync (private, not actionable by me)
PR praktika rollup of the rows above #129675 (the owner above)

Session id: cron:our-pr-ci-monitor:20261108-143005

@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 19, 2026
…lineage-without-first-row-id

# Conflicts:
#	src/Storages/prepareReadingFromFormat.h
@clickhouse-gh

clickhouse-gh Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 6e96952aa with master 3f2770fd6 (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.

Compile time of recompiled translation units

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

Job report

This branch has not been deployed

No deployments
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-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Iceberg v3: _row_id/_last_updated_sequence_number stored in a data file without first_row_id are returned instead of NULL

1 participant