Search in sources :

Example 1 with SchemaAlreadyExistsException

use of com.facebook.presto.hive.SchemaAlreadyExistsException in project presto by prestodb.

the class InMemoryHiveMetastore method createDatabase.

@Override
public synchronized void createDatabase(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());
    }
}
Also used : SchemaAlreadyExistsException(com.facebook.presto.hive.SchemaAlreadyExistsException) File(java.io.File)

Example 2 with SchemaAlreadyExistsException

use of com.facebook.presto.hive.SchemaAlreadyExistsException in project presto by prestodb.

the class InMemoryHiveMetastore method alterDatabase.

@Override
public synchronized void alterDatabase(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));
}
Also used : SchemaAlreadyExistsException(com.facebook.presto.hive.SchemaAlreadyExistsException) Database(org.apache.hadoop.hive.metastore.api.Database) SchemaNotFoundException(com.facebook.presto.spi.SchemaNotFoundException) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Aggregations

SchemaAlreadyExistsException (com.facebook.presto.hive.SchemaAlreadyExistsException)2 SchemaNotFoundException (com.facebook.presto.spi.SchemaNotFoundException)1 SchemaTableName (com.facebook.presto.spi.SchemaTableName)1 File (java.io.File)1 Database (org.apache.hadoop.hive.metastore.api.Database)1