jayceslesar commented on code in PR #3426:
URL: https://github.com/apache/iceberg-python/pull/3426#discussion_r3498328861


##########
pyiceberg/table/update/snapshot.py:
##########
@@ -937,6 +937,37 @@ def remove_branch(self, branch_name: str) -> 
ManageSnapshots:
         """
         return self._remove_ref_snapshot(ref_name=branch_name)
 
+    def rename_branch(self, name: str, new_name: str) -> ManageSnapshots:
+        """
+        Rename a branch.
+
+        Args:
+            name (str): name of branch to rename
+            new_name (str): the desired new name of the branch
+        Returns:
+            This for method chaining
+        """
+        self._commit_if_ref_updates_exist()
+
+        if name == MAIN_BRANCH:
+            raise ValueError("Cannot rename main branch")
+
+        refs = self._transaction.table_metadata.refs
+        if name not in refs:
+            raise ValueError(f"Branch does not exist: {name}")
+
+        ref = refs[name]
+        if ref.snapshot_ref_type != SnapshotRefType.BRANCH:
+            raise ValueError(f"Ref {name} is not a branch")
+
+        if new_name in refs:
+            raise ValueError(f"Ref {new_name} already exists")
+
+        self.create_branch(ref.snapshot_id, new_name, ref.max_ref_age_ms, 
ref.max_snapshot_age_ms, ref.min_snapshots_to_keep)

Review Comment:
   What does upstream do here for validation?



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

Reply via email to