From 3691ea1306158558a888277dc31ad7b0bf83a244 Mon Sep 17 00:00:00 2001 From: QingweiYang Date: Thu, 28 May 2026 07:36:15 -0400 Subject: [PATCH] [rest] Remove REST renameBranch implementation Strip the client-side renameBranch call, its request path, and the RenameBranchRequest payload. RESTCatalog now throws UnsupportedOperationException for renameBranch to satisfy the Catalog interface. Mock server and tests updated accordingly. --- .../java/org/apache/paimon/rest/RESTApi.java | 22 --------- .../org/apache/paimon/rest/ResourcePaths.java | 13 ------ .../rest/requests/RenameBranchRequest.java | 46 ------------------- .../org/apache/paimon/rest/RESTCatalog.java | 10 +--- .../apache/paimon/rest/RESTCatalogServer.java | 27 +---------- .../apache/paimon/rest/RESTCatalogTest.java | 20 +------- 6 files changed, 3 insertions(+), 135 deletions(-) delete mode 100644 paimon-api/src/main/java/org/apache/paimon/rest/requests/RenameBranchRequest.java diff --git a/paimon-api/src/main/java/org/apache/paimon/rest/RESTApi.java b/paimon-api/src/main/java/org/apache/paimon/rest/RESTApi.java index 7433a30388f8..263c4e2c0640 100644 --- a/paimon-api/src/main/java/org/apache/paimon/rest/RESTApi.java +++ b/paimon-api/src/main/java/org/apache/paimon/rest/RESTApi.java @@ -49,7 +49,6 @@ import org.apache.paimon.rest.requests.ListPartitionsByNamesRequest; import org.apache.paimon.rest.requests.MarkDonePartitionsRequest; import org.apache.paimon.rest.requests.RegisterTableRequest; -import org.apache.paimon.rest.requests.RenameBranchRequest; import org.apache.paimon.rest.requests.RenameTableRequest; import org.apache.paimon.rest.requests.ReplaceTableRequest; import org.apache.paimon.rest.requests.ResetConsumerRequest; @@ -985,27 +984,6 @@ public void dropBranch(Identifier identifier, String branch) { restAuthFunction); } - /** - * Rename branch for table. - * - * @param identifier database name and table name. - * @param fromBranch source branch name - * @param toBranch target branch name - * @throws NoSuchResourceException Exception thrown on HTTP 404 means the branch not exists - * @throws AlreadyExistsException Exception thrown on HTTP 409 means the target branch already - * exists - * @throws ForbiddenException Exception thrown on HTTP 403 means don't have the permission for - * this table - */ - public void renameBranch(Identifier identifier, String fromBranch, String toBranch) { - RenameBranchRequest request = new RenameBranchRequest(toBranch); - client.post( - resourcePaths.renameBranch( - identifier.getDatabaseName(), identifier.getObjectName(), fromBranch), - request, - restAuthFunction); - } - /** * Forward branch for table. * diff --git a/paimon-api/src/main/java/org/apache/paimon/rest/ResourcePaths.java b/paimon-api/src/main/java/org/apache/paimon/rest/ResourcePaths.java index 66a1653232b8..28f79d040995 100644 --- a/paimon-api/src/main/java/org/apache/paimon/rest/ResourcePaths.java +++ b/paimon-api/src/main/java/org/apache/paimon/rest/ResourcePaths.java @@ -273,19 +273,6 @@ public String forwardBranch(String databaseName, String tableName, String branch "forward"); } - public String renameBranch(String databaseName, String tableName, String branch) { - return SLASH.join( - V1, - prefix, - DATABASES, - encodeString(databaseName), - TABLES, - encodeString(tableName), - BRANCHES, - encodeString(branch), - "rename"); - } - public String tags(String databaseName, String objectName) { return SLASH.join( V1, diff --git a/paimon-api/src/main/java/org/apache/paimon/rest/requests/RenameBranchRequest.java b/paimon-api/src/main/java/org/apache/paimon/rest/requests/RenameBranchRequest.java deleted file mode 100644 index 63cf0011fac0..000000000000 --- a/paimon-api/src/main/java/org/apache/paimon/rest/requests/RenameBranchRequest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.paimon.rest.requests; - -import org.apache.paimon.rest.RESTRequest; - -import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonCreator; -import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonGetter; -import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonProperty; - -/** Request for renaming branch. */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class RenameBranchRequest implements RESTRequest { - - private static final String FIELD_TO_BRANCH = "toBranch"; - - @JsonProperty(FIELD_TO_BRANCH) - private final String toBranch; - - @JsonCreator - public RenameBranchRequest(@JsonProperty(FIELD_TO_BRANCH) String toBranch) { - this.toBranch = toBranch; - } - - @JsonGetter(FIELD_TO_BRANCH) - public String toBranch() { - return toBranch; - } -} diff --git a/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java b/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java index 7e2f6cfd2743..9d76cfdf4fef 100644 --- a/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java +++ b/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java @@ -761,15 +761,7 @@ public void dropBranch(Identifier identifier, String branch) throws BranchNotExi @Override public void renameBranch(Identifier identifier, String fromBranch, String toBranch) throws BranchNotExistException, BranchAlreadyExistException { - try { - api.renameBranch(identifier, fromBranch, toBranch); - } catch (NoSuchResourceException e) { - throw new BranchNotExistException(identifier, fromBranch, e); - } catch (AlreadyExistsException e) { - throw new BranchAlreadyExistException(identifier, toBranch, e); - } catch (ForbiddenException e) { - throw new TableNoPermissionException(identifier, e); - } + throw new UnsupportedOperationException(); } @Override diff --git a/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogServer.java b/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogServer.java index 74e4f4e465a9..af5d94e3f632 100644 --- a/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogServer.java +++ b/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogServer.java @@ -61,7 +61,6 @@ import org.apache.paimon.rest.requests.CreateViewRequest; import org.apache.paimon.rest.requests.ListPartitionsByNamesRequest; import org.apache.paimon.rest.requests.MarkDonePartitionsRequest; -import org.apache.paimon.rest.requests.RenameBranchRequest; import org.apache.paimon.rest.requests.RenameTableRequest; import org.apache.paimon.rest.requests.ReplaceTableRequest; import org.apache.paimon.rest.requests.ResetConsumerRequest; @@ -1888,31 +1887,7 @@ private MockResponse branchApiHandle( case "POST": if (resources.length == 6) { branch = RESTUtil.decodeString(resources[4]); - if ("rename".equals(resources[5])) { - // Rename branch: /branches/{branch}/rename - RenameBranchRequest requestBody = - RESTApi.fromJson(data, RenameBranchRequest.class); - String toBranch = requestBody.toBranch(); - table.renameBranch(branch, toBranch); - // Update store for renamed branch - Identifier fromBranchIdentifier = - new Identifier( - identifier.getDatabaseName(), - identifier.getTableName(), - branch); - Identifier toBranchIdentifier = - new Identifier( - identifier.getDatabaseName(), - identifier.getTableName(), - toBranch); - tableLatestSnapshotStore.put( - toBranchIdentifier.getFullName(), - tableLatestSnapshotStore.get( - fromBranchIdentifier.getFullName())); - tableMetadataStore.put( - toBranchIdentifier.getFullName(), - tableMetadataStore.get(fromBranchIdentifier.getFullName())); - } else if ("forward".equals(resources[5])) { + if ("forward".equals(resources[5])) { // Fast forward branch branchManager.fastForward(branch); branchIdentifier = diff --git a/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java b/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java index 8cefa2ec7b42..6ff873aed17d 100644 --- a/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java +++ b/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java @@ -2161,25 +2161,7 @@ void testBranches() throws Exception { () -> restCatalog.createBranch(identifier, "my_branch", null)); assertThat(restCatalog.listBranches(identifier)).containsOnly("my_branch"); - // Test rename branch - restCatalog.renameBranch(identifier, "my_branch", "renamed_branch"); - assertThat(restCatalog.listBranches(identifier)).containsOnly("renamed_branch"); - assertThat(restCatalog.getTable(new Identifier(databaseName, "table", "renamed_branch"))) - .isNotNull(); - - // Test rename to existing branch should fail - restCatalog.createBranch(identifier, "another_branch", null); - assertThrows( - Catalog.BranchAlreadyExistException.class, - () -> restCatalog.renameBranch(identifier, "renamed_branch", "another_branch")); - - // Test rename non-existent branch should fail - assertThrows( - Catalog.BranchNotExistException.class, - () -> restCatalog.renameBranch(identifier, "non_existent_branch", "new_branch")); - - restCatalog.dropBranch(identifier, "renamed_branch"); - restCatalog.dropBranch(identifier, "another_branch"); + restCatalog.dropBranch(identifier, "my_branch"); assertThrows( Catalog.BranchNotExistException.class,