lirui-apache 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_r350161836
 
 

 ##########
 File path: 
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/TableEnvironmentImpl.java
 ##########
 @@ -469,18 +475,53 @@ public void sqlUpdate(String stmt) {
                                createTableOperation.getCatalogTable(),
                                createTableOperation.getTableIdentifier(),
                                createTableOperation.isIgnoreIfExists());
+               } else if (operation instanceof CreateDatabaseOperation) {
+                       CreateDatabaseOperation createDatabaseOperation = 
(CreateDatabaseOperation) operation;
+                       catalogManager.createDatabase(
+                                       
createDatabaseOperation.getCatalogName(),
+                                       
createDatabaseOperation.getDatabaseName(),
+                                       
createDatabaseOperation.getCatalogDatabase(),
+                                       
createDatabaseOperation.isIgnoreIfExists(),
+                                       false);
                } else if (operation instanceof DropTableOperation) {
                        DropTableOperation dropTableOperation = 
(DropTableOperation) operation;
                        catalogManager.dropTable(
                                dropTableOperation.getTableIdentifier(),
                                dropTableOperation.isIfExists());
-               } else if (operation instanceof UseCatalogOperation) {
-                       UseCatalogOperation useCatalogOperation = 
(UseCatalogOperation) operation;
-                       
catalogManager.setCurrentCatalog(useCatalogOperation.getCatalogName());
+               } else if (operation instanceof DropDatabaseOperation) {
+                       DropDatabaseOperation dropDatabaseOperation = 
(DropDatabaseOperation) operation;
+                       catalogManager.dropDatabase(
+                                       dropDatabaseOperation.getCatalogName(),
+                                       dropDatabaseOperation.getDatabaseName(),
+                                       dropDatabaseOperation.isIfExists(),
+                                       dropDatabaseOperation.isRestrict(),
+                                       false);
+               } else if (operation instanceof AlterDatabaseOperation) {
+                       AlterDatabaseOperation alterDatabaseOperation = 
(AlterDatabaseOperation) operation;
+                       catalogManager.alterDatabase(
+                                       alterDatabaseOperation.getCatalogName(),
+                                       
alterDatabaseOperation.getDatabaseName(),
+                                       
alterDatabaseOperation.getCatalogDatabase(),
+                                       false);
+               } else if (operation instanceof UseOperation) {
+                       applyUseOperation((UseOperation) operation);
                } else {
                        throw new TableException(
                                "Unsupported SQL query! sqlUpdate() only 
accepts a single SQL statements of " +
-                                       "type INSERT, CREATE TABLE, DROP TABLE, 
USE CATALOG");
+                                       "type INSERT, CREATE TABLE, DROP TABLE, 
USE CATALOG, USE [catalog.]database, " +
+                                       "CREATE DATABASE, DROP DATABASE, ALTER 
DATABASE");
+               }
+       }
+
+       /**Apply use operation to current table environment. */
+       private void applyUseOperation(UseOperation operation) {
+               if (operation instanceof UseCatalogOperation) {
+                       UseCatalogOperation useCatalogOperation = 
(UseCatalogOperation) operation;
+                       
catalogManager.setCurrentCatalog(useCatalogOperation.getCatalogName());
+               } else if (operation instanceof UseDatabaseOperation) {
+                       UseDatabaseOperation useDatabaseOperation = 
(UseDatabaseOperation) operation;
+                       
catalogManager.setCurrentCatalog(useDatabaseOperation.getCatalogName());
+                       
catalogManager.setCurrentDatabase(useDatabaseOperation.getDatabaseName());
                }
 
 Review comment:
   throw an exception if it'e neither `UseCatalogOperation ` nor 
`UseDatabaseOperation `?

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to