Skip to content

Commit 7637601

Browse files
committed
Pass first-row-id to the V3 manifest list writer
1 parent 7230a42 commit 7637601

2 files changed

Lines changed: 43 additions & 5 deletions

File tree

pyiceberg/table/update/snapshot.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,21 +328,22 @@ def _commit(self) -> UpdatesAndRequirements:
328328
manifest_list_file_path = location_provider.new_metadata_location(file_name)
329329
self._written_manifest_lists.append(manifest_list_file_path)
330330

331+
first_row_id: int | None = None
332+
333+
if self._transaction.table_metadata.format_version >= 3:
334+
first_row_id = self._transaction.table_metadata.next_row_id
335+
331336
with write_manifest_list(
332337
format_version=self._transaction.table_metadata.format_version,
333338
output_file=self._io.new_output(manifest_list_file_path),
334339
snapshot_id=self._snapshot_id,
335340
parent_snapshot_id=self._parent_snapshot_id,
336341
sequence_number=next_sequence_number,
337342
avro_compression=self._compression,
343+
first_row_id=first_row_id,
338344
) as writer:
339345
writer.add_manifests(new_manifests)
340346

341-
first_row_id: int | None = None
342-
343-
if self._transaction.table_metadata.format_version >= 3:
344-
first_row_id = self._transaction.table_metadata.next_row_id
345-
346347
snapshot = Snapshot(
347348
snapshot_id=self._snapshot_id,
348349
parent_snapshot_id=self._parent_snapshot_id,

tests/table/test_snapshots.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,3 +737,40 @@ def test_overwrite_rejects_explicit_delete_without_parent_snapshot(
737737
with empty.transaction() as tx:
738738
with tx.update_snapshot().overwrite() as overwrite:
739739
overwrite.delete_data_file(stale_file)
740+
741+
742+
def test_manifest_list_receives_first_row_id_for_v3(table_v3: Table) -> None:
743+
"""The V3 manifest list writer requires first-row-id, so the producer has to supply it."""
744+
from unittest import mock
745+
746+
from pyiceberg.table.update.snapshot import _FastAppendFiles
747+
748+
txn = table_v3.transaction()
749+
append = _FastAppendFiles(operation=Operation.APPEND, transaction=txn, io=table_v3.io)
750+
751+
with (
752+
mock.patch("pyiceberg.table.update.snapshot.write_manifest_list") as writer,
753+
mock.patch.object(_FastAppendFiles, "_manifests", return_value=[]),
754+
):
755+
append._commit()
756+
757+
assert writer.call_args.kwargs["format_version"] == 3
758+
assert writer.call_args.kwargs["first_row_id"] == table_v3.metadata.next_row_id
759+
760+
761+
def test_manifest_list_has_no_first_row_id_for_v2(table_v2: Table) -> None:
762+
from unittest import mock
763+
764+
from pyiceberg.table.update.snapshot import _FastAppendFiles
765+
766+
txn = table_v2.transaction()
767+
append = _FastAppendFiles(operation=Operation.APPEND, transaction=txn, io=table_v2.io)
768+
769+
with (
770+
mock.patch("pyiceberg.table.update.snapshot.write_manifest_list") as writer,
771+
mock.patch.object(_FastAppendFiles, "_manifests", return_value=[]),
772+
):
773+
append._commit()
774+
775+
assert writer.call_args.kwargs["format_version"] == 2
776+
assert writer.call_args.kwargs["first_row_id"] is None

0 commit comments

Comments
 (0)