Repository navigation
Support row lineage assignment on commit - #4102
cayetanobv wants to merge 2 commits into
Conversation
39e7fd9 to
551c5f4
Compare
|
The Python 3.10 failure is not from this change. |
551c5f4 to
fc5db85
Compare
|
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! |
|
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. |
fc5db85 to
05b4198
Compare
|
Still active. This is waiting on #3624, which has addressed all review feedback and is waiting on a committer. Once it merges I'll rebase this onto The only red check is |
Fokko
left a comment
There was a problem hiding this comment.
Thanks @cayetanobv for picking this up, and for the clear write-up! This matches Java's SnapshotProducer, where added-rows is the number of row IDs the manifest list writer assigned, and I like that the integration test now checks _row_id and _last_updated_sequence_number through Spark. Nothing blocking from my side, just a couple of small suggestions below. I'll give it a final look once #3624 is merged and this is rebased 👍
| first_row_id = self._transaction.table_metadata.next_row_id | ||
| if first_row_id is not None: | ||
| # row IDs assigned to manifests without a first_row_id, including existing rows of upgraded tables | ||
| added_rows = cast(ManifestListWriterV3, writer).next_row_id - first_row_id |
There was a problem hiding this comment.
cast is a bit of a code smell here. In Java, nextRowId() lives on the base ManifestListWriter and returns null for V1/V2 (ManifestListWriter.java#L95-L97), so the producer can just do writer.nextRowId() - base.nextRowId() (SnapshotProducer.java#L359). Could we add a next_row_id -> int | None property to ManifestListWriter that returns None? That would let us drop the cast and the ManifestListWriterV3 import:
if first_row_id is not None and (next_row_id := writer.next_row_id) is not None:
added_rows = next_row_id - first_row_idThere was a problem hiding this comment.
Done. ManifestListWriter.next_row_id now returns None and ManifestListWriterV3 overrides it, so the producer no longer needs the cast or the ManifestListWriterV3 import. Two # type: ignore[attr-defined] comments in tests/utils/test_manifest.py became unused, so I removed them too.
| added_rows: int | None = None | ||
|
|
||
| if self._transaction.table_metadata.format_version >= 3: | ||
| first_row_id = self._transaction.table_metadata.next_row_id |
There was a problem hiding this comment.
The spec says: "If a commit is retried, the first-row-id must be reassigned based on the table's current next-row-id". I think _rebuild_snapshot_updates already handles this because it calls _commit() again on refreshed metadata, but nothing tests it. How about adding 3 to the format_version parametrize of test_conflict_append_append in tests/integration/test_writes/test_optimistic_concurrency.py, and asserting that the second snapshot's first_row_id starts where the first one ended? WDYT?
There was a problem hiding this comment.
Good call, added. test_conflict_append_append now runs for V3 too, and asserts that the three snapshots have (first_row_id, added_rows) of (0, n), (n, n) and (2n, n), so the retried append starts after the rows of the concurrent one. As you said, _attempt_landed() refreshes the table before _rebuild_snapshot_updates() calls _commit() again, so the retry reads the current next-row-id.
| sort_order=UNSORTED_SORT_ORDER, | ||
| location=str(tmp_path), | ||
| properties={"format-version": "3"}, | ||
| ).model_copy(update={"next_row_id": 0}) |
There was a problem hiding this comment.
I see that .model_copy(update={"next_row_id": 0}) works around new_table_metadata leaving next_row_id as None. In Java, the builder initializes it to INITIAL_ROW_ID (TableMetadata.java#L975), and the spec marks next-row-id as required for v3. Could we open a small follow-up that defaults TableMetadataV3.next_row_id to INITIAL_ROW_ID? Then this workaround can go away.
There was a problem hiding this comment.
#3551 already covers this: new_table_metadata sets next_row_id=INITIAL_ROW_ID for V3, as Java's builder does, and it adds test_new_table_metadata_v3_initializes_next_row_id. I'll drop the model_copy here once it merges, instead of opening a separate follow-up.
| @pytest.fixture | ||
| def empty_table_v3(tmp_path: Path, arrow_table_simple: pa.Table) -> Table: | ||
| """An empty V3 table; writing V3 metadata files is not supported, so commits stay staged in a transaction.""" | ||
| from pyiceberg.catalog.noop import NoopCatalog |
There was a problem hiding this comment.
Nit: could we move these imports to the top of the file? The same goes for import pyarrow.parquet as pq further down.
There was a problem hiding this comment.
Done, they're at the top of the file now, pyarrow.parquet included.
05b4198 to
bced150
Compare
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
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
bced150 to
e4e17a6
Compare
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._commitsetsfirst-row-idon the new snapshot but never setsadded-rows, and the spec requires both together. The REST fixture rejects the snapshot:Without a server check, the table metadata goes wrong instead.
add_snapshotcomputesnext-row-idfromadded-rows, sonext-row-idbecomesNoneafter the first commit and the next commit fails.This PR sets
added-rowstowriter.next_row_id - first_row_id, which is the number of row IDsManifestListWriterV3assigned. Java'sSnapshotProducercomputes it the same way. The count includes existing rows in manifests that had nofirst_row_id, sonext-row-idalways moves past every assigned ID.It also removes
_calculate_added_rows. Nothing called it, and it counted onlyadded_rows_countfrom the snapshot's own manifests, which would undercount the rows that the writer assigns.Out of scope: a V3 table created by
new_table_metadatahasnext-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 keep the row IDs of EXISTING entries: since #3972, reads inherit
first_row_id, and the V3 manifest writer persists it. A rewritten manifest still counts its existing rows inadded-rows, as Java'sManifestListWriterdoes, sonext-row-idmoves past IDs that are reserved but not reused.Are these changes tested?
Yes. Three new tests in
tests/table/test_snapshots.pycommit to an empty V3 table inside a transaction, because writing a V3metadata.jsonis not supported yet:(first_row_id, added_rows)is(0, 3), then(3, 3), andnext-row-idis 6add_files:(0, 3),next-row-idis 3(3, 2), andnext-row-idis 5All 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_idand_last_updated_sequence_numberwith 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 sameInvalid added-rowserror.test_conflict_append_appendnow also runs on V3 and checks that a retried commit takes itsfirst-row-idfrom the refreshednext-row-id.I also ran this script against
apache/iceberg-rest-fixture(sha256:db8de90b…) with the RustFS warehouse fromdev/docker-compose-integration.yml:Before, on #3624 (
c152089d):After:
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-rowsfor tables upgraded from V2, which follows Java but needs #3622 to exercise.