use of org.apache.flink.table.catalog.CatalogDatabase in project flink-mirror by flink-ci.
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 splunk.
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 by splunk.
the class HiveParserDDLSemanticAnalyzer method getDatabase.
private CatalogDatabase getDatabase(String databaseName) {
Catalog catalog = catalogManager.getCatalog(catalogManager.getCurrentCatalog()).get();
CatalogDatabase database;
try {
database = catalog.getDatabase(databaseName);
} catch (DatabaseNotExistException e) {
throw new ValidationException(String.format("Database %s not exists", databaseName), e);
}
return database;
}
use of org.apache.flink.table.catalog.CatalogDatabase in project flink by splunk.
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 splunk.
the class HiveCatalog method createDatabase.
@Override
public void createDatabase(String databaseName, CatalogDatabase database, boolean ignoreIfExists) throws DatabaseAlreadyExistException, CatalogException {
checkArgument(!isNullOrWhitespaceOnly(databaseName), "databaseName cannot be null or empty");
checkNotNull(database, "database cannot be null");
Map<String, String> properties = database.getProperties();
String dbLocationUri = properties.remove(SqlCreateHiveDatabase.DATABASE_LOCATION_URI);
Database hiveDatabase = new Database(databaseName, database.getComment(), dbLocationUri, properties);
try {
client.createDatabase(hiveDatabase);
} catch (AlreadyExistsException e) {
if (!ignoreIfExists) {
throw new DatabaseAlreadyExistException(getName(), hiveDatabase.getName());
}
} catch (TException e) {
throw new CatalogException(String.format("Failed to create database %s", hiveDatabase.getName()), e);
}
}
Aggregations