zjuwangg 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_r349991863
########## File path: flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/TableEnvironmentImpl.java ########## @@ -469,18 +475,57 @@ 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"); Review comment: Yes, but now we can't infer the type of unknown. We can do a refactor later. ---------------------------------------------------------------- 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