Search in sources :

Example 1 with SchemaAlreadyExistsException

use of io.prestosql.spi.connector.SchemaAlreadyExistsException in project hetu-core by openlookeng.

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));
}
Also used : SchemaAlreadyExistsException(io.prestosql.spi.connector.SchemaAlreadyExistsException) Database(org.apache.hadoop.hive.metastore.api.Database) SchemaNotFoundException(io.prestosql.spi.connector.SchemaNotFoundException) SchemaTableName(io.prestosql.spi.connector.SchemaTableName)

Example 2 with SchemaAlreadyExistsException

use of io.prestosql.spi.connector.SchemaAlreadyExistsException in project boostkit-bigdata by kunpengcompute.

the class GlueHiveMetastore method createDatabase.

@Override
public void createDatabase(HiveIdentity identity, Database inputDatabase) {
    Database database = inputDatabase;
    if (!database.getLocation().isPresent() && 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);
        glueClient.createDatabase(new CreateDatabaseRequest().withCatalogId(catalogId).withDatabaseInput(databaseInput));
    } catch (AlreadyExistsException e) {
        throw new SchemaAlreadyExistsException(database.getDatabaseName());
    } catch (AmazonServiceException e) {
        throw new PrestoException(HiveErrorCode.HIVE_METASTORE_ERROR, e);
    }
    if (database.getLocation().isPresent()) {
        HiveWriteUtils.createDirectory(hdfsContext, hdfsEnvironment, new Path(database.getLocation().get()));
    }
}
Also used : Path(org.apache.hadoop.fs.Path) CreateDatabaseRequest(com.amazonaws.services.glue.model.CreateDatabaseRequest) TableAlreadyExistsException(io.prestosql.spi.connector.TableAlreadyExistsException) SchemaAlreadyExistsException(io.prestosql.spi.connector.SchemaAlreadyExistsException) AlreadyExistsException(com.amazonaws.services.glue.model.AlreadyExistsException) SchemaAlreadyExistsException(io.prestosql.spi.connector.SchemaAlreadyExistsException) Database(io.prestosql.plugin.hive.metastore.Database) AmazonServiceException(com.amazonaws.AmazonServiceException) DatabaseInput(com.amazonaws.services.glue.model.DatabaseInput) PrestoException(io.prestosql.spi.PrestoException)

Example 3 with SchemaAlreadyExistsException

use of io.prestosql.spi.connector.SchemaAlreadyExistsException in project boostkit-bigdata by kunpengcompute.

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));
}
Also used : SchemaAlreadyExistsException(io.prestosql.spi.connector.SchemaAlreadyExistsException) Database(org.apache.hadoop.hive.metastore.api.Database) SchemaNotFoundException(io.prestosql.spi.connector.SchemaNotFoundException) SchemaTableName(io.prestosql.spi.connector.SchemaTableName)

Example 4 with SchemaAlreadyExistsException

use of io.prestosql.spi.connector.SchemaAlreadyExistsException in project hetu-core by openlookeng.

the class InMemoryThriftMetastore method createDatabase.

@Override
public synchronized void createDatabase(HiveIdentity identity, Database inputDatabase) {
    Database database = inputDatabase;
    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(io.prestosql.spi.connector.SchemaAlreadyExistsException) Database(org.apache.hadoop.hive.metastore.api.Database) File(java.io.File)

Example 5 with SchemaAlreadyExistsException

use of io.prestosql.spi.connector.SchemaAlreadyExistsException in project hetu-core by openlookeng.

the class GlueHiveMetastore method createDatabase.

@Override
public void createDatabase(HiveIdentity identity, Database inputDatabase) {
    Database database = inputDatabase;
    if (!database.getLocation().isPresent() && 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);
        glueClient.createDatabase(new CreateDatabaseRequest().withCatalogId(catalogId).withDatabaseInput(databaseInput));
    } catch (AlreadyExistsException e) {
        throw new SchemaAlreadyExistsException(database.getDatabaseName());
    } catch (AmazonServiceException e) {
        throw new PrestoException(HiveErrorCode.HIVE_METASTORE_ERROR, e);
    }
    if (database.getLocation().isPresent()) {
        HiveWriteUtils.createDirectory(hdfsContext, hdfsEnvironment, new Path(database.getLocation().get()));
    }
}
Also used : Path(org.apache.hadoop.fs.Path) CreateDatabaseRequest(com.amazonaws.services.glue.model.CreateDatabaseRequest) TableAlreadyExistsException(io.prestosql.spi.connector.TableAlreadyExistsException) SchemaAlreadyExistsException(io.prestosql.spi.connector.SchemaAlreadyExistsException) AlreadyExistsException(com.amazonaws.services.glue.model.AlreadyExistsException) SchemaAlreadyExistsException(io.prestosql.spi.connector.SchemaAlreadyExistsException) Database(io.prestosql.plugin.hive.metastore.Database) AmazonServiceException(com.amazonaws.AmazonServiceException) DatabaseInput(com.amazonaws.services.glue.model.DatabaseInput) PrestoException(io.prestosql.spi.PrestoException)

Aggregations

SchemaAlreadyExistsException (io.prestosql.spi.connector.SchemaAlreadyExistsException)6 Database (org.apache.hadoop.hive.metastore.api.Database)4 AmazonServiceException (com.amazonaws.AmazonServiceException)2 AlreadyExistsException (com.amazonaws.services.glue.model.AlreadyExistsException)2 CreateDatabaseRequest (com.amazonaws.services.glue.model.CreateDatabaseRequest)2 DatabaseInput (com.amazonaws.services.glue.model.DatabaseInput)2 Database (io.prestosql.plugin.hive.metastore.Database)2 PrestoException (io.prestosql.spi.PrestoException)2 SchemaNotFoundException (io.prestosql.spi.connector.SchemaNotFoundException)2 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)2 TableAlreadyExistsException (io.prestosql.spi.connector.TableAlreadyExistsException)2 File (java.io.File)2 Path (org.apache.hadoop.fs.Path)2