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);
}
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);
}
Aggregations