Skip to content

Commit 32f7199

Browse files
committed
iterate over ancestors_of()
1 parent b78a456 commit 32f7199

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pyiceberg/table/metadata.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,12 @@ def snapshot_by_id(self, snapshot_id: int) -> Optional[Snapshot]:
233233
def latest_snapshot_before_timestamp(self, timestamp_ms: int) -> Optional[Snapshot]:
234234
"""Get the snapshot right before the given timestamp."""
235235
result, prev_timestamp = None, 0
236-
for snapshot in self.snapshots:
237-
if prev_timestamp < snapshot.timestamp_ms < timestamp_ms:
238-
result, prev_timestamp = snapshot, snapshot.timestamp_ms
239-
return result if result else None
236+
if self.current_snapshot_id is not None:
237+
for snapshot_id, snapshot_timestamp in self.ancestors_of(self.current_snapshot_id):
238+
snapshot = self.snapshot_by_id(snapshot_id)
239+
if prev_timestamp < snapshot_timestamp < timestamp_ms:
240+
result, prev_timestamp = snapshot, snapshot_timestamp
241+
return result
240242

241243
def ancestors_of(self, snapshot_id: int) -> List[tuple[int, int]]:
242244
"""Get the snapshot_id of the ancestors of the given snapshot."""

0 commit comments

Comments
 (0)