@@ -1291,18 +1291,16 @@ def snapshot_by_name(self, name: str) -> Optional[Snapshot]:
1291
1291
return self .snapshot_by_id (ref .snapshot_id )
1292
1292
return None
1293
1293
1294
- def latest_snapshot_before_timestamp (self , timestamp_ms : int ) -> Optional [Snapshot ]:
1295
- """Get the snapshot right before the given timestamp, or None if there is no matching snapshot."""
1296
- result , prev_timestamp = None , 0
1297
- if self .metadata .current_snapshot_id is not None :
1298
- for snapshot in self .current_ancestors ():
1299
- if snapshot and prev_timestamp < snapshot .timestamp_ms < timestamp_ms :
1300
- result , prev_timestamp = snapshot , snapshot .timestamp_ms
1301
- return result
1294
+ def snapshot_at_or_before_timestamp (self , timestamp_ms : int ) -> Optional [Snapshot ]:
1295
+ """Get the snapshot that was current at or right before the given timestamp, or None if there is no matching snapshot."""
1296
+ for log_entry in reversed (self .history ()):
1297
+ if log_entry .timestamp_ms <= timestamp_ms :
1298
+ return self .snapshot_by_id (log_entry .snapshot_id )
1299
+ return None
1302
1300
1303
- def current_ancestors (self ) -> List [ Optional [ Snapshot ] ]:
1301
+ def current_ancestors (self ) -> Iterable [ Snapshot ]:
1304
1302
"""Get a list of ancestors of and including the current snapshot."""
1305
- return list ( ancestors_of (self .current_snapshot (), self .metadata ) ) # type: ignore
1303
+ return ancestors_of (self .current_snapshot (), self .metadata ) # type: ignore
1306
1304
1307
1305
def history (self ) -> List [SnapshotLogEntry ]:
1308
1306
"""Get the snapshot history of this table."""
0 commit comments