Skip to content

Commit b78a456

Browse files
committed
add ancestors_of API
1 parent f158ae9 commit b78a456

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pyiceberg/table/metadata.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,18 @@ def latest_snapshot_before_timestamp(self, timestamp_ms: int) -> Optional[Snapsh
238238
result, prev_timestamp = snapshot, snapshot.timestamp_ms
239239
return result if result else None
240240

241+
def ancestors_of(self, snapshot_id: int) -> List[tuple[int, int]]:
242+
"""Get the snapshot_id of the ancestors of the given snapshot."""
243+
current_id: Optional[int] = snapshot_id
244+
result = []
245+
while current_id is not None:
246+
snapshot = self.snapshot_by_id(current_id)
247+
if not snapshot:
248+
break
249+
result.append((current_id, snapshot.timestamp_ms))
250+
current_id = snapshot.parent_snapshot_id
251+
return result
252+
241253
def schema_by_id(self, schema_id: int) -> Optional[Schema]:
242254
"""Get the schema by schema_id."""
243255
return next((schema for schema in self.schemas if schema.schema_id == schema_id), None)

0 commit comments

Comments
 (0)