smaheshwar-pltr commented on code in PR #2031:
URL: https://github.com/apache/iceberg-python/pull/2031#discussion_r2101323675


##########
pyiceberg/table/snapshots.py:
##########
@@ -440,11 +440,40 @@ def ancestors_of(current_snapshot: Optional[Snapshot], 
table_metadata: TableMeta
 def ancestors_between(
     from_snapshot: Optional[Snapshot], to_snapshot: Snapshot, table_metadata: 
TableMetadata
 ) -> Iterable[Snapshot]:
-    """Get the ancestors of and including the given snapshot between the to 
and from snapshots."""
+    """Get the ancestors of and including the given snapshot between the to 
and from snapshots, both inclusively."""
     if from_snapshot is not None:
         for snapshot in ancestors_of(to_snapshot, table_metadata):
             yield snapshot
             if snapshot == from_snapshot:
                 break
     else:
         yield from ancestors_of(to_snapshot, table_metadata)
+
+
+def ancestors_between_ids(
+    from_snapshot_id_exclusive: Optional[int],
+    to_snapshot_id_inclusive: int,
+    table_metadata: TableMetadata,
+) -> Iterable[Snapshot]:
+    """Return the ancestors of and including the given "to" snapshot, up to 
but not including the "from" snapshot.
+
+    If from_snapshot_id_exclusive is None or no ancestors of the "to" snapshot 
match it, all ancestors of the "to"
+    snapshot are returned.
+    """
+    if from_snapshot_id_exclusive is not None:
+        for snapshot in 
ancestors_of(table_metadata.snapshot_by_id(to_snapshot_id_inclusive), 
table_metadata):
+            if snapshot.snapshot_id == from_snapshot_id_exclusive:
+                break
+
+            yield snapshot
+    else:
+        yield from 
ancestors_of(table_metadata.snapshot_by_id(to_snapshot_id_inclusive), 
table_metadata)
+
+
+def is_ancestor_of(snapshot_id: int, ancestor_snapshot_id: int, 
table_metadata: TableMetadata) -> bool:

Review Comment:
   Copied virtually exactly from 
https://github.com/apache/iceberg/blob/1911c94ea605a3d3f10a1994b046f00a5e9fdceb/core/src/main/java/org/apache/iceberg/util/SnapshotUtil.java#L43-L52



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to