Search in sources :

Example 1 with CreateDatabaseRequest

use of com.amazonaws.services.glue.model.CreateDatabaseRequest in project presto by prestodb.

the class GlueHiveMetastore method createDatabase.

@Override
public void createDatabase(MetastoreContext metastoreContext, Database database) {
    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);
        stats.getCreateDatabase().record(() -> glueClient.createDatabase(new CreateDatabaseRequest().withCatalogId(catalogId).withDatabaseInput(databaseInput)));
    } catch (AlreadyExistsException e) {
        throw new SchemaAlreadyExistsException(database.getDatabaseName());
    } catch (AmazonServiceException e) {
        throw new PrestoException(HIVE_METASTORE_ERROR, e);
    }
    if (database.getLocation().isPresent()) {
        createDirectory(hdfsContext, hdfsEnvironment, new Path(database.getLocation().get()));
    }
}
Also used : Path(org.apache.hadoop.fs.Path) CreateDatabaseRequest(com.amazonaws.services.glue.model.CreateDatabaseRequest) SchemaAlreadyExistsException(com.facebook.presto.hive.SchemaAlreadyExistsException) TableAlreadyExistsException(com.facebook.presto.hive.TableAlreadyExistsException) AlreadyExistsException(com.amazonaws.services.glue.model.AlreadyExistsException) SchemaAlreadyExistsException(com.facebook.presto.hive.SchemaAlreadyExistsException) AmazonServiceException(com.amazonaws.AmazonServiceException) DatabaseInput(com.amazonaws.services.glue.model.DatabaseInput) PrestoException(com.facebook.presto.spi.PrestoException)

Aggregations

AmazonServiceException (com.amazonaws.AmazonServiceException)1 AlreadyExistsException (com.amazonaws.services.glue.model.AlreadyExistsException)1 CreateDatabaseRequest (com.amazonaws.services.glue.model.CreateDatabaseRequest)1 DatabaseInput (com.amazonaws.services.glue.model.DatabaseInput)1 SchemaAlreadyExistsException (com.facebook.presto.hive.SchemaAlreadyExistsException)1 TableAlreadyExistsException (com.facebook.presto.hive.TableAlreadyExistsException)1 PrestoException (com.facebook.presto.spi.PrestoException)1 Path (org.apache.hadoop.fs.Path)1