Skip to content

Support row lineage assignment on commit - #4102

Open
cayetanobv wants to merge 2 commits into
apache:mainfrom
cayetanobv:feat/row-lineage-on-commit
Open

cayetanobv wants to merge 2 commits into
apache:mainfrom
cayetanobv:feat/row-lineage-on-commit

Conversation

@cayetanobv

@cayetanobv cayetanobv commented Oct 13, 2026 •

Copy link
Copy Markdown

Closes #3621 (part of #1551). Stacked on #3624, which adds ManifestListWriterV3. Only the last commit belongs to this PR; I will rebase once #3624 merges.

Rationale for this change

Every commit to a V3 table fails on a REST catalog. _SnapshotProducer._commit sets first-row-id on the new snapshot but never sets added-rows, and the spec requires both together. The REST fixture rejects the snapshot:

java.lang.IllegalArgumentException: Invalid added-rows (required when first-row-id is set): null

Without a server check, the table metadata goes wrong instead. add_snapshot computes next-row-id from added-rows, so next-row-id becomes None after the first commit and the next commit fails.

This PR sets added-rows to writer.next_row_id - first_row_id, which is the number of row IDs ManifestListWriterV3 assigned. Java's SnapshotProducer computes it the same way. The count includes existing rows in manifests that had no first_row_id, so next-row-id always moves past every assigned ID.

It also removes _calculate_added_rows. Nothing called it, and it counted only added_rows_count from the snapshot's own manifests, which would undercount the rows that the writer assigns.

Out of scope: a V3 table created by new_table_metadata has next-row-id = None, so a commit to it still fails. A REST server sets it to 0 on create, which hides this. That belongs with writing V3 metadata (#3551).

Rewritten manifests do not keep row IDs on EXISTING entries yet, so a merge append or partial delete moves them. #3972 fixes this by inheriting first_row_id on read. added-rows already matches Java in both cases.

Are these changes tested?

Yes. Three new tests in tests/table/test_snapshots.py commit to an empty V3 table inside a transaction, because writing a V3 metadata.json is not supported yet:

  • two appends: (first_row_id, added_rows) is (0, 3), then (3, 3), and next-row-id is 6
  • add_files: (0, 3), next-row-id is 3
  • a delete that rewrites a data file: the 2 surviving rows get new IDs, (3, 2), and next-row-id is 5

All three fail without the change. The unit suite passes locally.

This PR also un-skips the integration test test_v3_write_and_read_row_lineage. It now appends twice and reads _row_id and _last_updated_sequence_number with Spark (Iceberg 1.11.0), which must see row IDs 0 to 5 with sequence numbers 1 and 2. It passes with the change and fails without it on the same Invalid added-rows error.

I also ran this script against apache/iceberg-rest-fixture (sha256:db8de90b…) with the RustFS warehouse from dev/docker-compose-integration.yml:

t = cat.create_table(ident, schema=data.schema, properties={"format-version": "3"})
t.add_files([f"file://{src}"])           # 3 rows
cat.load_table(ident).append(data)        # 3 rows
cat.load_table(ident).delete("id == 1")   # rewrites both files

Before, on #3624 (c152089d):

lineage.t_2890d52f format-version=3 next-row-id=0
CommitStateUnknownException: RESTError 500: ... Invalid added-rows (required when first-row-id is set): null

After:

lineage.t_0e297eff format-version=3 next-row-id=0
add_files: first-row-id=0 added-rows=3 next-row-id=3 rows=3
append   : first-row-id=3 added-rows=3 next-row-id=6 rows=6
delete   : first-row-id=6 added-rows=4 next-row-id=10 rows=4

Are there any user-facing changes?

No API changes. Commits to V3 tables through a REST catalog now succeed.

Written with Claude Code (Claude Opus 5.5) and reviewed by me. One path has no test: added-rows for tables upgraded from V2, which follows Java but needs #3622 to exercise.

@cayetanobv
cayetanobv force-pushed the feat/row-lineage-on-commit branch from 39e7fd9 to 551c5f4 Compare October 13, 2026 07:02
@cayetanobv
cayetanobv marked this pull request as ready for review October 13, 2026 07:05
@cayetanobv

Copy link
Copy Markdown
Author

The Python 3.10 failure is not from this change. google.api_core now warns that Python 3.10 is unsupported, and the warning fails collection of test_bigquery_metastore.py. #4100 fixes it. The 3.11 and 3.14 jobs were cancelled when 3.10 failed. Integration, including the un-skipped test_v3_write_and_read_row_lineage, passes. I'll re-run CI once #4100 merges.

@cayetanobv

Copy link
Copy Markdown
Author

This builds on #3624; the first commits come from that PR, and I'll rebase once it merges. @Fokko @kevinjqliu could one of you take a look when you have a moment? Without a review, the stale bot will close both PRs in about a month, as happened to #3551, and the V3 write work would drop out of the queue. Thanks!

Add ManifestWriterV3 and ManifestListWriterV3, rebased onto main, which
now binds every record to the V3 layout. The manifest list writer
assigns first-row-id to data manifests that lack one, clears it on
delete manifests as Java does, and works on a fresh record so the
caller's manifest files are never mutated. The snapshot producer passes
the table's next-row-id to the V3 manifest list writer.

Closes apache#3620

Generated-by: Claude Code
@github-actions

Copy link
Copy Markdown

This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that's incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions.

@github-actions github-actions Bot added the stale label Nov 26, 2026
V3 snapshots set first-row-id but not added-rows, so REST catalogs
reject every V3 commit and next-row-id is lost after the first one.
Set added-rows to the row IDs that the V3 manifest list writer
assigns, as Java does, and remove the unused _calculate_added_rows.

Closes apache#3621
@cayetanobv
cayetanobv force-pushed the feat/row-lineage-on-commit branch from fc5db85 to 05b4198 Compare November 26, 2026 10:28

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support row lineage assignment on commit

2 participants