use of io.trino.plugin.hive.SchemaAlreadyExistsException in project trino by trinodb.
the class GlueHiveMetastore method createDatabase.
@Override
public void createDatabase(Database database) {
if (database.getLocation().isEmpty() && defaultDir.isPresent()) {
String databaseLocation = new Path(defaultDir.get(), database.getDatabaseName()).toString();
database = Database.builder(database).setLocation(Optional.of(databaseLocation)).build();
}
try {
DatabaseInput databaseInput = GlueInputConverter.convertDatabase(database);
stats.getCreateDatabase().call(() -> glueClient.createDatabase(new CreateDatabaseRequest().withCatalogId(catalogId).withDatabaseInput(databaseInput)));
} catch (AlreadyExistsException e) {
throw new SchemaAlreadyExistsException(database.getDatabaseName());
} catch (AmazonServiceException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, e);
}
if (database.getLocation().isPresent()) {
HiveWriteUtils.createDirectory(hdfsContext, hdfsEnvironment, new Path(database.getLocation().get()));
}
}
use of io.trino.plugin.hive.SchemaAlreadyExistsException in project trino by trinodb.
the class InMemoryThriftMetastore method alterDatabase.
@Override
public synchronized void alterDatabase(HiveIdentity identity, String databaseName, Database newDatabase) {
String newDatabaseName = newDatabase.getName();
if (databaseName.equals(newDatabaseName)) {
if (databases.replace(databaseName, newDatabase) == null) {
throw new SchemaNotFoundException(databaseName);
}
return;
}
Database database = databases.get(databaseName);
if (database == null) {
throw new SchemaNotFoundException(databaseName);
}
if (databases.putIfAbsent(newDatabaseName, database) != null) {
throw new SchemaAlreadyExistsException(newDatabaseName);
}
databases.remove(databaseName);
rewriteKeys(relations, name -> new SchemaTableName(newDatabaseName, name.getTableName()));
rewriteKeys(views, name -> new SchemaTableName(newDatabaseName, name.getTableName()));
rewriteKeys(partitions, name -> name.withSchemaName(newDatabaseName));
rewriteKeys(tablePrivileges, name -> name.withDatabase(newDatabaseName));
}
use of io.trino.plugin.hive.SchemaAlreadyExistsException in project trino by trinodb.
the class InMemoryThriftMetastore method createDatabase.
@Override
public synchronized void createDatabase(HiveIdentity identity, Database database) {
requireNonNull(database, "database is null");
File directory;
if (database.getLocationUri() != null) {
directory = new File(URI.create(database.getLocationUri()));
} else {
// use Hive default naming convention
directory = new File(baseDirectory, database.getName() + ".db");
database = database.deepCopy();
database.setLocationUri(directory.toURI().toString());
}
checkArgument(!directory.exists(), "Database directory already exists");
checkArgument(isParentDir(directory, baseDirectory), "Database directory must be inside of the metastore base directory");
checkArgument(directory.mkdirs(), "Could not create database directory");
if (databases.putIfAbsent(database.getName(), database) != null) {
throw new SchemaAlreadyExistsException(database.getName());
}
}
use of io.trino.plugin.hive.SchemaAlreadyExistsException in project trino by trinodb.
the class TrinoGlueCatalog method createNamespace.
@Override
public void createNamespace(ConnectorSession session, String namespace, Map<String, Object> properties, TrinoPrincipal owner) {
checkArgument(owner.getType() == PrincipalType.USER, "Owner type must be USER");
checkArgument(owner.getName().equals(session.getUser()), "Explicit schema owner is not supported");
try {
stats.getCreateDatabase().call(() -> glueClient.createDatabase(new CreateDatabaseRequest().withDatabaseInput(createDatabaseInput(namespace, properties))));
} catch (AlreadyExistsException e) {
throw new SchemaAlreadyExistsException(namespace);
} catch (AmazonServiceException e) {
throw new TrinoException(ICEBERG_CATALOG_ERROR, e);
}
}
Aggregations