smaheshwar-pltr commented on code in PR #3364:
URL: https://github.com/apache/iceberg-python/pull/3364#discussion_r3260053030
##########
pyiceberg/table/snapshots.py:
##########
@@ -431,6 +431,42 @@ def ancestors_between(from_snapshot: Snapshot | None,
to_snapshot: Snapshot, tab
yield from ancestors_of(to_snapshot, table_metadata)
+def ancestors_between_ids(
Review Comment:
Mirrors Java's
[`SnapshotUtil.ancestorsBetween`](https://github.com/apache/iceberg/blob/2f6606a247e2b16be46ca6c02fc4cfc2e17691e6/core/src/main/java/org/apache/iceberg/util/SnapshotUtil.java#L216).
Differs from the existing `ancestors_between` (snapshot-based,
inclusive-inclusive) above by taking IDs and being exclusive-inclusive, to
match the incremental-scan validation pattern. Raises if
`to_snapshot_id_inclusive` is missing from metadata, mirroring Java.
##########
pyiceberg/table/snapshots.py:
##########
@@ -431,6 +431,42 @@ def ancestors_between(from_snapshot: Snapshot | None,
to_snapshot: Snapshot, tab
yield from ancestors_of(to_snapshot, table_metadata)
+def ancestors_between_ids(
+ from_snapshot_id_exclusive: int | None,
+ to_snapshot_id_inclusive: int,
+ table_metadata: TableMetadata,
+) -> Iterable[Snapshot]:
+ """Get the ancestors of and including the given "to" snapshot, up to but
not including the "from" snapshot.
+
+ If ``from_snapshot_id_exclusive`` is None, all ancestors of the "to"
snapshot are returned.
+
+ Raises:
+ ValueError: if ``to_snapshot_id_inclusive`` is not present in the
table metadata.
+ """
+ to_snapshot = table_metadata.snapshot_by_id(to_snapshot_id_inclusive)
+ if to_snapshot is None:
+ raise ValueError(f"Cannot find snapshot: {to_snapshot_id_inclusive}")
+
+ if from_snapshot_id_exclusive is not None:
+ for snapshot in ancestors_of(to_snapshot, table_metadata):
+ if snapshot.snapshot_id == from_snapshot_id_exclusive:
+ break
+ yield snapshot
+ else:
+ yield from ancestors_of(to_snapshot, table_metadata)
+
+
+def is_parent_ancestor_of(snapshot_id: int, ancestor_parent_snapshot_id: int,
table_metadata: TableMetadata) -> bool:
Review Comment:
Mirrors Java's
[`SnapshotUtil.isParentAncestorOf`](https://github.com/apache/iceberg/blob/2f6606a247e2b16be46ca6c02fc4cfc2e17691e6/core/src/main/java/org/apache/iceberg/util/SnapshotUtil.java#L77-L86).
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]