File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -457,10 +457,14 @@ def ancestors_between_ids(
457457
458458
459459def 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
Original file line number Diff line number Diff 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" )])
13141328def test_incremental_append_scan_schema_evolution_within_range (catalog : Catalog ) -> None :
Original file line number Diff line number Diff 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
495498def test_ancestors_between_ids (table_v2 : Table ) -> None :
You can’t perform that action at this time.
0 commit comments