mchades commented on code in PR #14040:
URL: https://github.com/apache/gravitino/pull/14040#discussion_r4335362236


##########
core/src/main/java/org/apache/gravitino/catalog/ManagedTableOperations.java:
##########
@@ -181,8 +181,26 @@ public Table alterTable(NameIdentifier ident, 
TableChange... changes)
     } catch (NoSuchEntityException e) {
       throw new NoSuchTableException(e, "Table %s does not exist", ident);
     } catch (EntityAlreadyExistsException e) {
-      throw new IllegalArgumentException(
-          "Failed to rename table " + ident + " due to table already exists: 
", e);
+      NameIdentifier newIdent =
+          Arrays.stream(changes)
+              .filter(c -> c instanceof TableChange.RenameTable)
+              .map(c -> (TableChange.RenameTable) c)
+              .map(
+                  rename ->
+                      NameIdentifier.of(
+                          rename
+                              .getNewSchemaName()
+                              .map(
+                                  schema ->
+                                      NamespaceUtil.ofTable(
+                                          ident.namespace().level(0),
+                                          ident.namespace().level(1),
+                                          schema))
+                              .orElse(ident.namespace()),
+                          rename.getNewName()))
+              .reduce((first, second) -> second)

Review Comment:
   A name-only rename should preserve the previously specified schema, matching 
the authorization hook and Hive. Updated `applyChanges` accordingly. The catch 
now reuses the updater's identifier; `EntityAlreadyExistsException` has no 
structured identifier accessor.



##########
catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogOperations.java:
##########
@@ -727,10 +726,15 @@ public Fileset alterFileset(NameIdentifier ident, 
FilesetChange... changes)
       throw ExceptionMessages.wrap("Failed to update fileset " + ident, ioe);
     } catch (NoSuchEntityException nsee) {
       throw new NoSuchFilesetException(nsee, FILESET_DOES_NOT_EXIST_MSG, 
ident);
-    } catch (AlreadyExistsException aee) {
-      // This is happened when renaming a fileset to an existing fileset name.
-      throw ExceptionMessages.wrap(
-          "Fileset with the same name " + ident.name() + " already exists", 
aee);
+    } catch (EntityAlreadyExistsException e) {
+      String newName =
+          Arrays.stream(changes)
+              .filter(c -> c instanceof FilesetChange.RenameFileset)
+              .map(c -> ((FilesetChange.RenameFileset) c).getNewName())
+              .reduce((first, second) -> second)

Review Comment:
   Extracted `RenameUtils` for Fileset, Model, Catalog, Metalake, Policy, and 
Tag. Added a multi-rename Tag conflict test that verifies the final target name 
and unchanged source/target. ManagedTable reuses the updater's full identifier.



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

Reply via email to