Search in sources :

Example 31 with CatalogDatabase

use of org.apache.flink.table.catalog.CatalogDatabase in project flink-mirror by flink-ci.

the class SqlToOperationConverter method convertAlterDatabase.

/**
 * Convert ALTER DATABASE statement.
 */
private Operation convertAlterDatabase(SqlAlterDatabase sqlAlterDatabase) {
    String[] fullDatabaseName = sqlAlterDatabase.fullDatabaseName();
    if (fullDatabaseName.length > 2) {
        throw new ValidationException("alter database identifier format error");
    }
    String catalogName = (fullDatabaseName.length == 1) ? catalogManager.getCurrentCatalog() : fullDatabaseName[0];
    String databaseName = (fullDatabaseName.length == 1) ? fullDatabaseName[0] : fullDatabaseName[1];
    final Map<String, String> properties;
    CatalogDatabase originCatalogDatabase;
    Optional<Catalog> catalog = catalogManager.getCatalog(catalogName);
    if (catalog.isPresent()) {
        try {
            originCatalogDatabase = catalog.get().getDatabase(databaseName);
            properties = new HashMap<>(originCatalogDatabase.getProperties());
        } catch (DatabaseNotExistException e) {
            throw new ValidationException(String.format("Database %s not exists", databaseName), e);
        }
    } else {
        throw new ValidationException(String.format("Catalog %s not exists", catalogName));
    }
    // set with properties
    sqlAlterDatabase.getPropertyList().getList().forEach(p -> properties.put(((SqlTableOption) p).getKeyString(), ((SqlTableOption) p).getValueString()));
    CatalogDatabase catalogDatabase = new CatalogDatabaseImpl(properties, originCatalogDatabase.getComment());
    return new AlterDatabaseOperation(catalogName, databaseName, catalogDatabase);
}
Also used : CatalogDatabase(org.apache.flink.table.catalog.CatalogDatabase) SqlTableOption(org.apache.flink.sql.parser.ddl.SqlTableOption) AlterDatabaseOperation(org.apache.flink.table.operations.ddl.AlterDatabaseOperation) ValidationException(org.apache.flink.table.api.ValidationException) DatabaseNotExistException(org.apache.flink.table.catalog.exceptions.DatabaseNotExistException) SqlShowCurrentCatalog(org.apache.flink.sql.parser.dql.SqlShowCurrentCatalog) Catalog(org.apache.flink.table.catalog.Catalog) SqlUseCatalog(org.apache.flink.sql.parser.ddl.SqlUseCatalog) SqlDropCatalog(org.apache.flink.sql.parser.ddl.SqlDropCatalog) SqlCreateCatalog(org.apache.flink.sql.parser.ddl.SqlCreateCatalog) CatalogDatabaseImpl(org.apache.flink.table.catalog.CatalogDatabaseImpl)

Aggregations

CatalogDatabase (org.apache.flink.table.catalog.CatalogDatabase)31 CatalogDatabaseImpl (org.apache.flink.table.catalog.CatalogDatabaseImpl)22 HashMap (java.util.HashMap)18 ValidationException (org.apache.flink.table.api.ValidationException)18 LinkedHashMap (java.util.LinkedHashMap)15 AlterDatabaseOperation (org.apache.flink.table.operations.ddl.AlterDatabaseOperation)15 DatabaseNotExistException (org.apache.flink.table.catalog.exceptions.DatabaseNotExistException)12 SqlAlterHiveDatabase (org.apache.flink.sql.parser.hive.ddl.SqlAlterHiveDatabase)9 SqlCreateHiveDatabase (org.apache.flink.sql.parser.hive.ddl.SqlCreateHiveDatabase)9 Catalog (org.apache.flink.table.catalog.Catalog)9 Database (org.apache.hadoop.hive.metastore.api.Database)9 SqlCreateCatalog (org.apache.flink.sql.parser.ddl.SqlCreateCatalog)6 SqlDropCatalog (org.apache.flink.sql.parser.ddl.SqlDropCatalog)6 SqlTableOption (org.apache.flink.sql.parser.ddl.SqlTableOption)6 SqlUseCatalog (org.apache.flink.sql.parser.ddl.SqlUseCatalog)6 SqlShowCurrentCatalog (org.apache.flink.sql.parser.dql.SqlShowCurrentCatalog)6 CreateDatabaseOperation (org.apache.flink.table.operations.ddl.CreateDatabaseOperation)6 CatalogException (org.apache.flink.table.catalog.exceptions.CatalogException)4 TException (org.apache.thrift.TException)4 ArrayList (java.util.ArrayList)3