Skip to content

Commit b344ea5

Browse files
Nits
- Raise on missing snapshot in `is_parent_ancestor_of`. - Add empty-range integration test. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent dd17340 commit b344ea5

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

pyiceberg/table/snapshots.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,14 @@ def ancestors_between_ids(
457457

458458

459459
def is_parent_ancestor_of(snapshot_id: int, ancestor_parent_snapshot_id: int, table_metadata: TableMetadata) -> bool:
460-
"""Return whether any ancestor of ``snapshot_id`` has ``ancestor_parent_snapshot_id`` as its parent."""
460+
"""Return whether any ancestor of ``snapshot_id`` has ``ancestor_parent_snapshot_id`` as its parent.
461+
462+
Raises:
463+
ValueError: if ``snapshot_id`` is not present in the table metadata.
464+
"""
461465
snapshot = table_metadata.snapshot_by_id(snapshot_id)
462466
if snapshot is None:
463-
return False
467+
raise ValueError(f"Cannot find snapshot: {snapshot_id}")
464468
for ancestor in ancestors_of(snapshot, table_metadata):
465469
if ancestor.parent_snapshot_id == ancestor_parent_snapshot_id:
466470
return True

tests/integration/test_reads.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,20 @@ def test_incremental_append_scan_ignores_non_append_snapshots(catalog: Catalog)
13091309
assert sorted(scan.to_arrow()["number"].to_pylist()) == [2, 3, 4]
13101310

13111311

1312+
@pytest.mark.integration
1313+
@pytest.mark.parametrize("catalog", [lf("session_catalog_hive"), lf("session_catalog")])
1314+
def test_incremental_append_scan_empty_range(catalog: Catalog) -> None:
1315+
test_table = catalog.load_table("default.test_incremental_read")
1316+
1317+
# snapshots[3] is the only snapshot in the range and is a delete; the scan must return empty.
1318+
scan = test_table.incremental_append_scan(
1319+
from_snapshot_id_exclusive=test_table.snapshots()[2].snapshot_id,
1320+
to_snapshot_id_inclusive=test_table.snapshots()[3].snapshot_id,
1321+
)
1322+
assert list(scan.plan_files()) == []
1323+
assert len(scan.to_arrow()) == 0
1324+
1325+
13121326
@pytest.mark.integration
13131327
@pytest.mark.parametrize("catalog", [lf("session_catalog_hive"), lf("session_catalog")])
13141328
def test_incremental_append_scan_schema_evolution_within_range(catalog: Catalog) -> None:

tests/table/test_snapshots.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,9 @@ def test_is_parent_ancestor_of(table_v2: Table) -> None:
490490
assert not is_parent_ancestor_of(ancestor_snapshot_id, snapshot_id, table_v2.metadata)
491491
# An ID not referenced anywhere in the chain is not a parent ancestor.
492492
assert not is_parent_ancestor_of(snapshot_id, 42, table_v2.metadata)
493+
# Raises when the start snapshot ID is missing from metadata.
494+
with pytest.raises(ValueError, match="Cannot find snapshot: 42"):
495+
is_parent_ancestor_of(42, snapshot_id, table_v2.metadata)
493496

494497

495498
def test_ancestors_between_ids(table_v2: Table) -> None:

0 commit comments

Comments
 (0)