Search in sources :

Example 11 with CatalogDatabaseImpl

use of org.apache.flink.table.catalog.CatalogDatabaseImpl in project flink by apache.

the class HiveParserDDLSemanticAnalyzer method convertAlterDatabaseProperties.

private Operation convertAlterDatabaseProperties(HiveParserASTNode ast) {
    String dbName = HiveParserBaseSemanticAnalyzer.unescapeIdentifier(ast.getChild(0).getText());
    Map<String, String> dbProps = null;
    for (int i = 1; i < ast.getChildCount(); i++) {
        HiveParserASTNode childNode = (HiveParserASTNode) ast.getChild(i);
        if (childNode.getToken().getType() == HiveASTParser.TOK_DATABASEPROPERTIES) {
            dbProps = getProps((HiveParserASTNode) childNode.getChild(0));
        } else {
            throw new ValidationException("Unknown AST node for ALTER DATABASE PROPERTIES: " + childNode);
        }
    }
    CatalogDatabase originDB = getDatabase(dbName);
    Map<String, String> props = new HashMap<>(originDB.getProperties());
    props.put(ALTER_DATABASE_OP, SqlAlterHiveDatabase.AlterHiveDatabaseOp.CHANGE_PROPS.name());
    props.putAll(dbProps);
    CatalogDatabase newDB = new CatalogDatabaseImpl(props, originDB.getComment());
    return new AlterDatabaseOperation(catalogManager.getCurrentCatalog(), dbName, newDB);
}
Also used : CatalogDatabase(org.apache.flink.table.catalog.CatalogDatabase) AlterDatabaseOperation(org.apache.flink.table.operations.ddl.AlterDatabaseOperation) HiveParserASTNode(org.apache.flink.table.planner.delegation.hive.copy.HiveParserASTNode) ValidationException(org.apache.flink.table.api.ValidationException) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) NotNullConstraint(org.apache.flink.table.planner.delegation.hive.copy.HiveParserBaseSemanticAnalyzer.NotNullConstraint) UniqueConstraint(org.apache.flink.table.api.constraints.UniqueConstraint) CatalogDatabaseImpl(org.apache.flink.table.catalog.CatalogDatabaseImpl)

Example 12 with CatalogDatabaseImpl

use of org.apache.flink.table.catalog.CatalogDatabaseImpl in project flink by apache.

the class SqlToOperationConverterTest method testAlterDatabase.

@Test
public void testAlterDatabase() throws Exception {
    catalogManager.registerCatalog("cat1", new GenericInMemoryCatalog("default", "default"));
    catalogManager.getCatalog("cat1").get().createDatabase("db1", new CatalogDatabaseImpl(new HashMap<>(), "db1_comment"), true);
    final String sql = "alter database cat1.db1 set ('k1'='v1', 'K2'='V2')";
    Operation operation = parse(sql, SqlDialect.DEFAULT);
    assertThat(operation).isInstanceOf(AlterDatabaseOperation.class);
    Map<String, String> properties = new HashMap<>();
    properties.put("k1", "v1");
    properties.put("K2", "V2");
    AlterDatabaseOperation alterDatabaseOperation = (AlterDatabaseOperation) operation;
    assertThat(alterDatabaseOperation.getDatabaseName()).isEqualTo("db1");
    assertThat(alterDatabaseOperation.getCatalogName()).isEqualTo("cat1");
    assertThat(alterDatabaseOperation.getCatalogDatabase().getComment()).isEqualTo("db1_comment");
    assertThat(alterDatabaseOperation.getCatalogDatabase().getProperties()).isEqualTo(properties);
}
Also used : AlterDatabaseOperation(org.apache.flink.table.operations.ddl.AlterDatabaseOperation) HashMap(java.util.HashMap) OperationMatchers.isCreateTableOperation(org.apache.flink.table.planner.utils.OperationMatchers.isCreateTableOperation) DropDatabaseOperation(org.apache.flink.table.operations.ddl.DropDatabaseOperation) SinkModifyOperation(org.apache.flink.table.operations.SinkModifyOperation) AlterTableOptionsOperation(org.apache.flink.table.operations.ddl.AlterTableOptionsOperation) AlterTableDropConstraintOperation(org.apache.flink.table.operations.ddl.AlterTableDropConstraintOperation) UseCatalogOperation(org.apache.flink.table.operations.UseCatalogOperation) UseDatabaseOperation(org.apache.flink.table.operations.UseDatabaseOperation) CreateViewOperation(org.apache.flink.table.operations.ddl.CreateViewOperation) ShowJarsOperation(org.apache.flink.table.operations.command.ShowJarsOperation) AlterDatabaseOperation(org.apache.flink.table.operations.ddl.AlterDatabaseOperation) QueryOperation(org.apache.flink.table.operations.QueryOperation) EndStatementSetOperation(org.apache.flink.table.operations.EndStatementSetOperation) UseModulesOperation(org.apache.flink.table.operations.UseModulesOperation) ShowFunctionsOperation(org.apache.flink.table.operations.ShowFunctionsOperation) CreateDatabaseOperation(org.apache.flink.table.operations.ddl.CreateDatabaseOperation) SetOperation(org.apache.flink.table.operations.command.SetOperation) LoadModuleOperation(org.apache.flink.table.operations.LoadModuleOperation) Operation(org.apache.flink.table.operations.Operation) ShowModulesOperation(org.apache.flink.table.operations.ShowModulesOperation) SourceQueryOperation(org.apache.flink.table.operations.SourceQueryOperation) UnloadModuleOperation(org.apache.flink.table.operations.UnloadModuleOperation) CreateTableOperation(org.apache.flink.table.operations.ddl.CreateTableOperation) RemoveJarOperation(org.apache.flink.table.operations.command.RemoveJarOperation) BeginStatementSetOperation(org.apache.flink.table.operations.BeginStatementSetOperation) AddJarOperation(org.apache.flink.table.operations.command.AddJarOperation) AlterTableAddConstraintOperation(org.apache.flink.table.operations.ddl.AlterTableAddConstraintOperation) ExplainOperation(org.apache.flink.table.operations.ExplainOperation) ResetOperation(org.apache.flink.table.operations.command.ResetOperation) StatementSetOperation(org.apache.flink.table.operations.StatementSetOperation) AlterTableRenameOperation(org.apache.flink.table.operations.ddl.AlterTableRenameOperation) GenericInMemoryCatalog(org.apache.flink.table.catalog.GenericInMemoryCatalog) CatalogDatabaseImpl(org.apache.flink.table.catalog.CatalogDatabaseImpl) Test(org.junit.Test)

Aggregations

CatalogDatabaseImpl (org.apache.flink.table.catalog.CatalogDatabaseImpl)12 HashMap (java.util.HashMap)11 CatalogDatabase (org.apache.flink.table.catalog.CatalogDatabase)7 AlterDatabaseOperation (org.apache.flink.table.operations.ddl.AlterDatabaseOperation)6 LinkedHashMap (java.util.LinkedHashMap)5 ValidationException (org.apache.flink.table.api.ValidationException)5 CatalogTable (org.apache.flink.table.catalog.CatalogTable)5 Catalog (org.apache.flink.table.catalog.Catalog)4 Test (org.junit.Test)4 TableSchema (org.apache.flink.table.api.TableSchema)3 GenericInMemoryCatalog (org.apache.flink.table.catalog.GenericInMemoryCatalog)3 ObjectPath (org.apache.flink.table.catalog.ObjectPath)3 ResolvedCatalogTable (org.apache.flink.table.catalog.ResolvedCatalogTable)3 Configuration (org.apache.flink.configuration.Configuration)2 SqlCreateCatalog (org.apache.flink.sql.parser.ddl.SqlCreateCatalog)2 SqlDropCatalog (org.apache.flink.sql.parser.ddl.SqlDropCatalog)2 SqlTableOption (org.apache.flink.sql.parser.ddl.SqlTableOption)2 SqlUseCatalog (org.apache.flink.sql.parser.ddl.SqlUseCatalog)2 SqlShowCurrentCatalog (org.apache.flink.sql.parser.dql.SqlShowCurrentCatalog)2 Schema (org.apache.flink.table.api.Schema)2