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

 ##########
 File path: 
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/api/internal/TableEnvImpl.scala
 ##########
 @@ -481,18 +481,53 @@ abstract class TableEnvImpl(
           createTableOperation.getCatalogTable,
           createTableOperation.getTableIdentifier,
           createTableOperation.isIgnoreIfExists)
+      case createDatabaseOperation: CreateDatabaseOperation =>
+        catalogManager.createDatabase(
+          createDatabaseOperation.getCatalogName,
+          createDatabaseOperation.getDatabaseName,
+          createDatabaseOperation.getCatalogDatabase,
+          createDatabaseOperation.isIgnoreIfExists,
+          false)
       case dropTableOperation: DropTableOperation =>
         catalogManager.dropTable(
           dropTableOperation.getTableIdentifier,
           dropTableOperation.isIfExists)
-      case useCatalogOperation: UseCatalogOperation =>
-        catalogManager.setCurrentCatalog(useCatalogOperation.getCatalogName)
+      case dropDatabaseOperation: DropDatabaseOperation =>
+        catalogManager.dropDatabase(
+          dropDatabaseOperation.getCatalogName,
+          dropDatabaseOperation.getDatabaseName,
+          dropDatabaseOperation.isIfExists,
+          dropDatabaseOperation.isRestrict,
+          false)
+      case alterDatabaseOperation: AlterDatabaseOperation =>
+        catalogManager.alterDatabase(
+          alterDatabaseOperation.getCatalogName,
+          alterDatabaseOperation.getDatabaseName,
+          alterDatabaseOperation.getCatalogDatabase,
+          false)
+      case useOperation: UseOperation => applyUseOperation(useOperation)
       case _ => 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 def applyUseOperation(useOperation: UseOperation): Unit = {
+      useOperation match {
+        case useCatalogOperation: UseCatalogOperation =>
+          catalogManager.setCurrentCatalog(useCatalogOperation.getCatalogName)
+        case useDatabaseOperation: UseDatabaseOperation => {
+          val fullDatabaseName = useDatabaseOperation.getFullDatabaseName
 
 Review comment:
   We can resolve catalog name in UseDatabaseOperation rather than here.

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