SteNicholas commented on code in PR #958:
URL: https://github.com/apache/incubator-paimon/pull/958#discussion_r1181447410


##########
paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveCatalog.java:
##########
@@ -177,6 +177,12 @@ public void dropDatabase(String name, boolean 
ignoreIfNotExists, boolean cascade
         }
     }
 
+    @Override
+    public void renameDatabase(String fromDatabase, String toDatabase, boolean 
ignoreIfNotExists)
+            throws DatabaseNotExistException, DatabaseAlreadyExistException {
+        throw new UnsupportedOperationException("Hive catalog does not support 
rename database.");

Review Comment:
   Why not support rename database of `HiveCatalog`? Just uses the 
`IMetaStoreClient#alterDatabase`?



##########
paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java:
##########
@@ -87,6 +87,19 @@ public interface Catalog extends AutoCloseable {
     void dropDatabase(String name, boolean ignoreIfNotExists, boolean cascade)
             throws DatabaseNotExistException, DatabaseNotEmptyException;
 
+    /**
+     * Rename a database.

Review Comment:
   Adds the blew note for renaming database:
   
   ```
        * <p>NOTE: If you use object storage, such as S3 or OSS, please use 
this syntax carefully,
        * because the renaming of object storage is not atomic, and only 
partial files may be moved in
        * case of failure.
   ``` 



##########
paimon-core/src/test/java/org/apache/paimon/catalog/FileSystemCatalogTest.java:
##########
@@ -44,4 +45,11 @@ public void testListDatabasesWhenNoDatabases() {
         List<String> databases = catalog.listDatabases();
         assertThat(databases).isEmpty();
     }
+
+    @Test
+    public void testRenameDatabase() throws Exception {
+        catalog.createDatabase("db1", false);
+        catalog.renameDatabase("db1", "db2", false);
+        
assertThat(catalog.listDatabases()).isEqualTo(Lists.newArrayList("db2"));

Review Comment:
   Could we add the test case to rename to the same name of other database?



##########
paimon-core/src/main/java/org/apache/paimon/catalog/FileSystemCatalog.java:
##########
@@ -99,6 +99,24 @@ public void dropDatabase(String name, boolean 
ignoreIfNotExists, boolean cascade
         uncheck(() -> fileIO.delete(databasePath(name), true));
     }
 
+    @Override
+    public void renameDatabase(String fromDatabase, String toDatabase, boolean 
ignoreIfNotExists)
+            throws DatabaseNotExistException, DatabaseAlreadyExistException {
+        if (!databaseExists(fromDatabase)) {
+            if (ignoreIfNotExists) {
+                return;
+            }
+
+            throw new DatabaseNotExistException(fromDatabase);
+        }
+
+        if (databaseExists(toDatabase)) {
+            throw new DatabaseAlreadyExistException(toDatabase);
+        }
+
+        uncheck(() -> fileIO.rename(databasePath(fromDatabase), 
databasePath(toDatabase)));

Review Comment:
   @s7monk, above problem could be solved in another pull request. This pull 
request could keep the same behavior of `renameTable`.



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