xuefuz commented on a change in pull request #8329: [FLINK-12239][hive] Support 
table related operations in GenericHiveMetastoreCatalog
URL: https://github.com/apache/flink/pull/8329#discussion_r280239908
 
 

 ##########
 File path: 
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/GenericHiveMetastoreCatalog.java
 ##########
 @@ -229,31 +231,91 @@ public void alterDatabase(String name, CatalogDatabase 
newDatabase, boolean igno
        @Override
        public void dropTable(ObjectPath tablePath, boolean ignoreIfNotExists)
                        throws TableNotExistException, CatalogException {
-               throw new UnsupportedOperationException();
+               try {
+                       client.dropTable(tablePath.getDatabaseName(), 
tablePath.getObjectName(), true, ignoreIfNotExists);
+               } catch (NoSuchObjectException e) {
+                       if (!ignoreIfNotExists) {
+                               throw new TableNotExistException(catalogName, 
tablePath);
+                       }
+               } catch (TException e) {
+                       throw new CatalogException(
+                               String.format("Failed to drop table %s", 
tablePath.getFullName()), e);
+               }
        }
 
        @Override
        public void renameTable(ObjectPath tablePath, String newTableName, 
boolean ignoreIfNotExists)
-                       throws TableNotExistException, 
TableAlreadyExistException, DatabaseNotExistException, CatalogException {
-               throw new UnsupportedOperationException();
+                       throws TableNotExistException, 
TableAlreadyExistException, CatalogException {
+               try {
+                       // alter_table() doesn't throw a clear exception when 
target table doesn't exist. Thus, check the table existence explicitly
+                       if (tableExists(tablePath)) {
+                               ObjectPath newPath = new 
ObjectPath(tablePath.getDatabaseName(), newTableName);
+                               // alter_table() doesn't throw a clear 
exception when new table already exists. Thus, check the table existence 
explicitly
+                               if (tableExists(newPath)) {
+                                       throw new 
TableAlreadyExistException(catalogName, newPath);
+                               } else {
+                                       Table table = getHiveTable(tablePath);
+                                       table.setTableName(newTableName);
+                                       
client.alter_table(tablePath.getDatabaseName(), tablePath.getObjectName(), 
table);
+                               }
+                       } else if (!ignoreIfNotExists) {
+                               throw new TableNotExistException(catalogName, 
tablePath);
+                       }
+               } catch (TException e) {
+                       throw new CatalogException(
+                               String.format("Failed to alter table %s", 
tablePath.getFullName()), e);
 
 Review comment:
   => Failed to rename table?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to