4040
4141def _validation_history (
4242 table : Table ,
43- from_snapshot : Snapshot ,
43+ from_snapshot : Snapshot | None ,
4444 to_snapshot : Snapshot ,
4545 matching_operations : set [Operation ],
4646 manifest_content_filter : ManifestContent ,
4747) -> tuple [list [ManifestFile ], set [int ]]:
4848 """Return newly added manifests and snapshot IDs between the starting snapshot and parent snapshot.
4949
5050 Walks from to_snapshot backwards towards from_snapshot, collecting manifests from
51- snapshots whose operations match. from_snapshot is excluded from results.
51+ snapshots whose operations match. from_snapshot is excluded from results. A None
52+ from_snapshot walks the entire history of to_snapshot down to the root.
5253
5354 Args:
5455 table: Table to get the history from
55- from_snapshot: Snapshot where the walk stops (exclusive)
56+ from_snapshot: Snapshot where the walk stops (exclusive), or None to walk the whole history
5657 to_snapshot: Snapshot where the walk starts
5758 matching_operations: Operations to match on
5859 manifest_content_filter: Manifest content type to filter
@@ -63,15 +64,15 @@ def _validation_history(
6364 Returns:
6465 List of manifest files and set of snapshots ID's matching conditions
6566 """
66- if from_snapshot .snapshot_id == to_snapshot .snapshot_id :
67+ if from_snapshot is not None and from_snapshot .snapshot_id == to_snapshot .snapshot_id :
6768 return [], set ()
6869
6970 manifests_files : list [ManifestFile ] = []
7071 snapshots : set [int ] = set ()
7172
7273 last_snapshot = None
7374 for snapshot in ancestors_between (from_snapshot , to_snapshot , table .metadata ):
74- if snapshot .snapshot_id == from_snapshot .snapshot_id :
75+ if from_snapshot is not None and snapshot .snapshot_id == from_snapshot .snapshot_id :
7576 last_snapshot = snapshot
7677 break
7778 last_snapshot = snapshot
@@ -90,7 +91,7 @@ def _validation_history(
9091 ]
9192 )
9293
93- if last_snapshot is None or last_snapshot .snapshot_id != from_snapshot .snapshot_id :
94+ if from_snapshot is not None and ( last_snapshot is None or last_snapshot .snapshot_id != from_snapshot .snapshot_id ) :
9495 raise ValidationException ("No matching snapshot found." )
9596
9697 return manifests_files , snapshots
@@ -216,9 +217,6 @@ def _added_data_files(
216217 Returns:
217218 Iterator of manifest entries for added data files matching the conditions
218219 """
219- if parent_snapshot is None :
220- return
221-
222220 manifests , snapshot_ids = _validation_history (
223221 table ,
224222 parent_snapshot ,
@@ -252,7 +250,7 @@ def _added_delete_files(
252250 Returns:
253251 DeleteFileIndex
254252 """
255- if parent_snapshot is None or table .format_version < 2 :
253+ if table .format_version < 2 :
256254 return DeleteFileIndex ()
257255
258256 manifests , snapshot_ids = _validation_history (
@@ -352,7 +350,7 @@ def _validate_no_new_deletes_for_data_files(
352350 parent_snapshot: Ending snapshot on the branch being validated
353351 """
354352 # If there is no current state, or no files has been added
355- if parent_snapshot is None or table .format_version < 2 :
353+ if table .format_version < 2 :
356354 return
357355
358356 deletes = _added_delete_files (table , starting_snapshot , data_filter , None , parent_snapshot )
0 commit comments