syun64 commented on code in PR #599: URL: https://github.com/apache/iceberg-python/pull/599#discussion_r1562918080
########## pyiceberg/table/__init__.py: ########## @@ -3253,6 +3253,15 @@ def __init__(self, tbl: Table) -> None: except ModuleNotFoundError as e: raise ModuleNotFoundError("For metadata operations PyArrow needs to be installed") from e + def _snapshot(self, snapshot_id: Optional[int] = None) -> Optional[Snapshot]: + if snapshot_id: + if snapshot := self.tbl.metadata.snapshot_by_id(snapshot_id): + return snapshot + else: + raise ValueError(f"Cannot find snapshot with ID {snapshot_id}") Review Comment: Hi @kevinjqliu thanks for the review. I thought about this, and I stand by this behavior / type annotation. This is my rationale: 1. If the user passes in `snapshot_id` - that's an indication that the user wants to look up a specific snapshot_id (instead of using the current one). Then we should look up snapshot_by_id and see if we can find the corresponding Snapshot and if we can't find the Snapshot, we should raise. 2. The output arg type is still `Optional[Snapshot]` even if we raise in the above behavior, because tbl.metadata.current_snapshot() returns `Optional[Snapshot]`. https://github.com/apache/iceberg-python/blob/5039b5d70644bc06c98349090912c6e9066d3ea1/pyiceberg/table/metadata.py#L295 -- 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