Search in sources :

Example 1 with AlreadyExistsException

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

the class GlueHiveMetastore method createTable.

@Override
public void createTable(MetastoreContext metastoreContext, Table table, PrincipalPrivileges principalPrivileges) {
    try {
        TableInput input = GlueInputConverter.convertTable(table);
        stats.getCreateTable().record(() -> glueClient.createTable(new CreateTableRequest().withCatalogId(catalogId).withDatabaseName(table.getDatabaseName()).withTableInput(input)));
    } catch (AlreadyExistsException e) {
        throw new TableAlreadyExistsException(new SchemaTableName(table.getDatabaseName(), table.getTableName()));
    } catch (EntityNotFoundException e) {
        throw new SchemaNotFoundException(table.getDatabaseName());
    } catch (AmazonServiceException e) {
        throw new PrestoException(HIVE_METASTORE_ERROR, e);
    }
}
Also used : TableInput(com.amazonaws.services.glue.model.TableInput) GlueInputConverter.toTableInput(com.facebook.presto.hive.metastore.glue.converter.GlueInputConverter.toTableInput) TableAlreadyExistsException(com.facebook.presto.hive.TableAlreadyExistsException) SchemaAlreadyExistsException(com.facebook.presto.hive.SchemaAlreadyExistsException) TableAlreadyExistsException(com.facebook.presto.hive.TableAlreadyExistsException) AlreadyExistsException(com.amazonaws.services.glue.model.AlreadyExistsException) AmazonServiceException(com.amazonaws.AmazonServiceException) PrestoException(com.facebook.presto.spi.PrestoException) EntityNotFoundException(com.amazonaws.services.glue.model.EntityNotFoundException) SchemaNotFoundException(com.facebook.presto.spi.SchemaNotFoundException) CreateTableRequest(com.amazonaws.services.glue.model.CreateTableRequest) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 2 with AlreadyExistsException

use of com.amazonaws.services.glue.model.AlreadyExistsException 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)2 AlreadyExistsException (com.amazonaws.services.glue.model.AlreadyExistsException)2 SchemaAlreadyExistsException (com.facebook.presto.hive.SchemaAlreadyExistsException)2 TableAlreadyExistsException (com.facebook.presto.hive.TableAlreadyExistsException)2 PrestoException (com.facebook.presto.spi.PrestoException)2 CreateDatabaseRequest (com.amazonaws.services.glue.model.CreateDatabaseRequest)1 CreateTableRequest (com.amazonaws.services.glue.model.CreateTableRequest)1 DatabaseInput (com.amazonaws.services.glue.model.DatabaseInput)1 EntityNotFoundException (com.amazonaws.services.glue.model.EntityNotFoundException)1 TableInput (com.amazonaws.services.glue.model.TableInput)1 GlueInputConverter.toTableInput (com.facebook.presto.hive.metastore.glue.converter.GlueInputConverter.toTableInput)1 SchemaNotFoundException (com.facebook.presto.spi.SchemaNotFoundException)1 SchemaTableName (com.facebook.presto.spi.SchemaTableName)1 Path (org.apache.hadoop.fs.Path)1