HonahX commented on code in PR #758:
URL: https://github.com/apache/iceberg-python/pull/758#discussion_r1665133966


##########
pyiceberg/table/__init__.py:
##########
@@ -1975,6 +1948,52 @@ def _commit(self) -> UpdatesAndRequirements:
         """Apply the pending changes and commit."""
         return self._updates, self._requirements
 
+    def _commit_if_ref_updates_exist(self) -> None:
+        self._transaction._apply(*self._commit(), commit_transaction_now=False)
+        self._updates, self._requirements = (), ()
+
+    def _stage_main_branch_snapshot_ref(self, snapshot_id: int) -> None:
+        update, requirement = self._set_ref_snapshot(
+            snapshot_id=snapshot_id, ref_name=MAIN_BRANCH, 
type=str(SnapshotRefType.BRANCH)
+        )
+        self._updates += update
+        self._requirements += requirement
+
+    def _set_ref_snapshot(
+        self,
+        snapshot_id: int,
+        ref_name: str,
+        type: str,
+        max_ref_age_ms: Optional[int] = None,
+        max_snapshot_age_ms: Optional[int] = None,
+        min_snapshots_to_keep: Optional[int] = None,
+    ) -> UpdatesAndRequirements:
+        """Update a ref to a snapshot.
+
+        Returns:
+            The updates and requirements for the set-snapshot-ref staged
+        """
+        updates = (
+            SetSnapshotRefUpdate(
+                snapshot_id=snapshot_id,
+                ref_name=ref_name,
+                type=type,
+                max_ref_age_ms=max_ref_age_ms,
+                max_snapshot_age_ms=max_snapshot_age_ms,
+                min_snapshots_to_keep=min_snapshots_to_keep,
+            ),
+        )
+        requirements = (
+            AssertRefSnapshotId(
+                
snapshot_id=self._transaction.table_metadata.refs[ref_name].snapshot_id
+                if ref_name in self._transaction.table_metadata.refs
+                else None,
+                ref=ref_name,
+            ),
+        )
+
+        return updates, requirements

Review Comment:
   Instead of return `updates` and `requirements`, how about directly updating 
the field here
   ```python
   self._updates += update
   self._requirements += requirement
   ```
   This way we do not need to repeat these two lines and all APIs will end with 
a `self._set_snapshot_ref(...)`



##########
pyiceberg/table/__init__.py:
##########
@@ -299,7 +300,12 @@ def __exit__(self, _: Any, value: Any, traceback: Any) -> 
None:
         """Close and commit the transaction."""
         self.commit_transaction()
 
-    def _apply(self, updates: Tuple[TableUpdate, ...], requirements: 
Tuple[TableRequirement, ...] = ()) -> Transaction:
+    def _apply(
+        self,
+        updates: Tuple[TableUpdate, ...],
+        requirements: Tuple[TableRequirement, ...] = (),
+        commit_transaction_now: bool = True,

Review Comment:
   How about `commit_transaction_if_autocommit`? I think this aligns more with 
the behavior of this parameter.



-- 
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