@@ -1303,18 +1303,16 @@ def snapshot_by_name(self, name: str) -> Optional[Snapshot]:
1303
1303
return self .snapshot_by_id (ref .snapshot_id )
1304
1304
return None
1305
1305
1306
- def latest_snapshot_before_timestamp (self , timestamp_ms : int ) -> Optional [Snapshot ]:
1307
- """Get the snapshot right before the given timestamp, or None if there is no matching snapshot."""
1308
- result , prev_timestamp = None , 0
1309
- if self .metadata .current_snapshot_id is not None :
1310
- for snapshot in self .current_ancestors ():
1311
- if snapshot and prev_timestamp < snapshot .timestamp_ms < timestamp_ms :
1312
- result , prev_timestamp = snapshot , snapshot .timestamp_ms
1313
- return result
1306
+ def snapshot_at_or_before_timestamp (self , timestamp_ms : int ) -> Optional [Snapshot ]:
1307
+ """Get the snapshot that was current at or right before the given timestamp, or None if there is no matching snapshot."""
1308
+ for log_entry in reversed (self .history ()):
1309
+ if log_entry .timestamp_ms <= timestamp_ms :
1310
+ return self .snapshot_by_id (log_entry .snapshot_id )
1311
+ return None
1314
1312
1315
- def current_ancestors (self ) -> List [ Optional [ Snapshot ] ]:
1313
+ def current_ancestors (self ) -> Iterable [ Snapshot ]:
1316
1314
"""Get a list of ancestors of and including the current snapshot."""
1317
- return list ( ancestors_of (self .current_snapshot (), self .metadata ) ) # type: ignore
1315
+ return ancestors_of (self .current_snapshot (), self .metadata ) # type: ignore
1318
1316
1319
1317
def history (self ) -> List [SnapshotLogEntry ]:
1320
1318
"""Get the snapshot history of this table."""
0 commit comments