Skip to content

Commit 3e45b39

Browse files
committed
general cleanup
1 parent 8a9a610 commit 3e45b39

4 files changed

Lines changed: 13 additions & 8 deletions

File tree

‎pyiceberg/manifest.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -920,16 +920,18 @@ def fetch_manifest_entry(
920920
read_enums={0: ManifestEntryStatus, 101: FileFormat, 134: DataFileContent},
921921
) as reader:
922922
result = []
923-
next_row_id = self.first_row_id
923+
next_row_id = self.first_row_id if self.content == ManifestContent.DATA else None
924924

925925
for entry in reader:
926926
if discard_deleted and entry.status == ManifestEntryStatus.DELETED:
927927
continue
928928
_inherit_from_manifest(entry, self)
929929

930-
# Data files without a first_row_id inherit one from the manifest, assigned in file order
930+
# Inherit first row IDs, which are only valid when a data manifest has a first_row_id
931931
data_file = entry.data_file
932-
if next_row_id is not None and entry.status != ManifestEntryStatus.DELETED and data_file.first_row_id is None:
932+
if next_row_id is None:
933+
data_file.first_row_id = None
934+
elif entry.status != ManifestEntryStatus.DELETED and data_file.first_row_id is None:
933935
data_file.first_row_id = next_row_id
934936
next_row_id += data_file.record_count
935937

‎tests/integration/test_reads.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,6 @@ def test_initial_default(catalog: Catalog, spark: SparkSession) -> None:
12571257
@pytest.mark.integration
12581258
@pytest.mark.parametrize("catalog", [lf("session_catalog")])
12591259
def test_read_first_row_ids_written_by_spark(catalog: Catalog, spark: SparkSession) -> None:
1260-
"""Data files read by PyIceberg get the same first row IDs that Spark reports through `_row_id`."""
12611260
identifier = "default.test_read_first_row_ids_written_by_spark"
12621261
spark.sql(f"DROP TABLE IF EXISTS {identifier}")
12631262
spark.sql(f"CREATE TABLE {identifier} (id int) USING ICEBERG TBLPROPERTIES ('format-version'='3')")

‎tests/table/test_init.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1972,7 +1972,6 @@ def test_add_snapshot_update_fails_without_added_rows(table_v3: Table) -> None:
19721972

19731973

19741974
def test_add_snapshot_update_keeps_next_row_id_unset_below_v3(table_v2: Table) -> None:
1975-
"""`next-row-id` only exists in V3, so a V2 commit must not gain one."""
19761975
new_snapshot = Snapshot(
19771976
snapshot_id=25,
19781977
parent_snapshot_id=3055729675574597004,

‎tests/utils/test_manifest.py‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def test_fetch_manifest_entry_with_filter(generated_manifest_entry_file: str) ->
229229

230230

231231
def test_fetch_manifest_entry_inherits_first_row_id(tmp_path: Path) -> None:
232-
"""Data files without a first_row_id inherit one from the manifest in file order, skipping deleted entries."""
232+
"""Data files inherit first row IDs from data manifests in file order, and have them cleared otherwise."""
233233
io = PyArrowFileIO()
234234
manifest_path = str(tmp_path / "manifest.avro")
235235

@@ -268,21 +268,25 @@ def entry(status: ManifestEntryStatus, record_count: int, first_row_id: int | No
268268
]
269269
)
270270

271-
def first_row_ids(manifest_first_row_id: int | None, discard_deleted: bool) -> list[int | None]:
271+
def first_row_ids(
272+
manifest_first_row_id: int | None, discard_deleted: bool, content: ManifestContent = ManifestContent.DATA
273+
) -> list[int | None]:
272274
manifest = ManifestFile.from_args(
273275
manifest_path=manifest_path,
274276
manifest_length=0,
275277
partition_spec_id=0,
278+
content=content,
276279
added_snapshot_id=25,
277280
sequence_number=1,
278281
min_sequence_number=1,
279282
first_row_id=manifest_first_row_id,
280283
)
281284
return [e.data_file.first_row_id for e in manifest.fetch_manifest_entry(io, discard_deleted=discard_deleted)]
282285

283-
assert first_row_ids(None, discard_deleted=False) == [None, 500, None, None]
284286
assert first_row_ids(1000, discard_deleted=False) == [1000, 500, None, 1010]
285287
assert first_row_ids(1000, discard_deleted=True) == [1000, 500, 1010]
288+
assert first_row_ids(None, discard_deleted=False) == [None, None, None, None]
289+
assert first_row_ids(1000, discard_deleted=False, content=ManifestContent.DELETES) == [None, None, None, None]
286290

287291

288292
def test_read_manifest_entry_v3_fields(tmp_path: Path) -> None:
@@ -314,6 +318,7 @@ def write_and_read(file_name: str, data_file: DataFile) -> DataFile:
314318
added_snapshot_id=25,
315319
sequence_number=1,
316320
min_sequence_number=1,
321+
first_row_id=0,
317322
)
318323
return manifest.fetch_manifest_entry(io)[0].data_file
319324

0 commit comments

Comments
 (0)