KurtYoung commented on a change in pull request #10296: [FLINK-14691][table]Add 
use/create/drop/alter database operation and support it in flink/blink planner
URL: https://github.com/apache/flink/pull/10296#discussion_r353028953
 
 

 ##########
 File path: 
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/TableEnvironmentImpl.java
 ##########
 @@ -469,21 +479,84 @@ public void sqlUpdate(String stmt) {
                                createTableOperation.getCatalogTable(),
                                createTableOperation.getTableIdentifier(),
                                createTableOperation.isIgnoreIfExists());
+               } else if (operation instanceof CreateDatabaseOperation) {
+                       CreateDatabaseOperation createDatabaseOperation = 
(CreateDatabaseOperation) operation;
+                       Catalog catalog = 
getCatalogOrThrowException(createDatabaseOperation.getCatalogName());
+                       String exMsg = getDDLOpExecuteErrorMsg("CREATE 
DATABASE", createDatabaseOperation.getCatalogName());
+                       try {
+                               catalog.createDatabase(
+                                               
createDatabaseOperation.getDatabaseName(),
+                                               
createDatabaseOperation.getCatalogDatabase(),
+                                               
createDatabaseOperation.isIgnoreIfExists());
+                       } catch (DatabaseAlreadyExistException e) {
+                               throw new ValidationException(exMsg, e);
+                       } catch (Exception e) {
+                               throw new TableException(exMsg, e);
+                       }
                } else if (operation instanceof DropTableOperation) {
                        DropTableOperation dropTableOperation = 
(DropTableOperation) operation;
                        catalogManager.dropTable(
                                dropTableOperation.getTableIdentifier(),
                                dropTableOperation.isIfExists());
-               } else if (operation instanceof UseCatalogOperation) {
+               } else if (operation instanceof DropDatabaseOperation) {
+                       DropDatabaseOperation dropDatabaseOperation = 
(DropDatabaseOperation) operation;
+                       Catalog catalog = 
getCatalogOrThrowException(dropDatabaseOperation.getCatalogName());
+                       String exMsg = getDDLOpExecuteErrorMsg("DROP DATABASE", 
dropDatabaseOperation.getCatalogName());
+                       try {
+                               catalog.dropDatabase(
+                                               
dropDatabaseOperation.getDatabaseName(),
+                                               
dropDatabaseOperation.isIfExists(),
+                                               
dropDatabaseOperation.isCascade());
+                       } catch (DatabaseNotExistException | 
DatabaseNotEmptyException e) {
+                               throw new ValidationException(exMsg, e);
+                       } catch (Exception e) {
+                               throw new TableException(exMsg, e);
+                       }
+               } else if (operation instanceof AlterDatabaseOperation) {
+                       AlterDatabaseOperation alterDatabaseOperation = 
(AlterDatabaseOperation) operation;
+                       Catalog catalog = 
getCatalogOrThrowException(alterDatabaseOperation.getCatalogName());
+                       String exMsg = getDDLOpExecuteErrorMsg("ALTER 
DATABASE", alterDatabaseOperation.getCatalogName());
 
 Review comment:
   ditto

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