use of org.apache.flink.table.catalog.CatalogDatabase in project flink by apache.
the class HiveCatalog method alterDatabase.
@Override
public void alterDatabase(String databaseName, CatalogDatabase newDatabase, boolean ignoreIfNotExists) throws DatabaseNotExistException, CatalogException {
checkArgument(!isNullOrWhitespaceOnly(databaseName), "databaseName cannot be null or empty");
checkNotNull(newDatabase, "newDatabase cannot be null");
// client.alterDatabase doesn't throw any exception if there is no existing database
Database hiveDB;
try {
hiveDB = getHiveDatabase(databaseName);
} catch (DatabaseNotExistException e) {
if (!ignoreIfNotExists) {
throw new DatabaseNotExistException(getName(), databaseName);
}
return;
}
try {
client.alterDatabase(databaseName, alterDatabase(hiveDB, newDatabase));
} catch (TException e) {
throw new CatalogException(String.format("Failed to alter database %s", databaseName), e);
}
}
use of org.apache.flink.table.catalog.CatalogDatabase in project flink by apache.
the class HiveParserDDLSemanticAnalyzer method convertAlterDatabaseLocation.
private Operation convertAlterDatabaseLocation(HiveParserASTNode ast) {
String dbName = HiveParserBaseSemanticAnalyzer.getUnescapedName((HiveParserASTNode) ast.getChild(0));
String newLocation = HiveParserBaseSemanticAnalyzer.unescapeSQLString(ast.getChild(1).getText());
CatalogDatabase originDB = getDatabase(dbName);
Map<String, String> props = new HashMap<>(originDB.getProperties());
props.put(ALTER_DATABASE_OP, SqlAlterHiveDatabase.AlterHiveDatabaseOp.CHANGE_LOCATION.name());
props.put(DATABASE_LOCATION_URI, newLocation);
CatalogDatabase newDB = new CatalogDatabaseImpl(props, originDB.getComment());
return new AlterDatabaseOperation(catalogManager.getCurrentCatalog(), dbName, newDB);
}
use of org.apache.flink.table.catalog.CatalogDatabase in project flink by apache.
the class HiveParserDDLSemanticAnalyzer method convertCreateDatabase.
private Operation convertCreateDatabase(HiveParserASTNode ast) {
String dbName = HiveParserBaseSemanticAnalyzer.unescapeIdentifier(ast.getChild(0).getText());
boolean ifNotExists = false;
String dbComment = null;
String dbLocation = null;
Map<String, String> dbProps = null;
for (int i = 1; i < ast.getChildCount(); i++) {
HiveParserASTNode childNode = (HiveParserASTNode) ast.getChild(i);
switch(childNode.getToken().getType()) {
case HiveASTParser.TOK_IFNOTEXISTS:
ifNotExists = true;
break;
case HiveASTParser.TOK_DATABASECOMMENT:
dbComment = HiveParserBaseSemanticAnalyzer.unescapeSQLString(childNode.getChild(0).getText());
break;
case HiveASTParser.TOK_DATABASEPROPERTIES:
dbProps = getProps((HiveParserASTNode) childNode.getChild(0));
break;
case HiveASTParser.TOK_DATABASELOCATION:
dbLocation = HiveParserBaseSemanticAnalyzer.unescapeSQLString(childNode.getChild(0).getText());
break;
default:
throw new ValidationException("Unknown AST node for CREATE DATABASE: " + childNode);
}
}
Map<String, String> props = new HashMap<>();
if (dbProps != null) {
props.putAll(dbProps);
}
if (dbLocation != null) {
props.put(DATABASE_LOCATION_URI, dbLocation);
}
CatalogDatabase catalogDatabase = new CatalogDatabaseImpl(props, dbComment);
return new CreateDatabaseOperation(catalogManager.getCurrentCatalog(), dbName, catalogDatabase, ifNotExists);
}
use of org.apache.flink.table.catalog.CatalogDatabase 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.CatalogDatabase in project flink-mirror by flink-ci.
the class HiveCatalog method getDatabase.
// ------ databases ------
@Override
public CatalogDatabase getDatabase(String databaseName) throws DatabaseNotExistException, CatalogException {
Database hiveDatabase = getHiveDatabase(databaseName);
Map<String, String> properties = new HashMap<>(hiveDatabase.getParameters());
properties.put(SqlCreateHiveDatabase.DATABASE_LOCATION_URI, hiveDatabase.getLocationUri());
return new CatalogDatabaseImpl(properties, hiveDatabase.getDescription());
}
Aggregations