Search in sources :

Example 1 with DatabaseInput

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

the class TestGlueInputConverter method testConvertDatabase.

@Test
public void testConvertDatabase() {
    DatabaseInput dbInput = GlueInputConverter.convertDatabase(testDb);
    assertEquals(dbInput.getName(), testDb.getDatabaseName());
    assertEquals(dbInput.getDescription(), testDb.getComment().get());
    assertEquals(dbInput.getLocationUri(), testDb.getLocation().get());
    assertEquals(dbInput.getParameters(), testDb.getParameters());
}
Also used : DatabaseInput(com.amazonaws.services.glue.model.DatabaseInput) Test(org.testng.annotations.Test)

Example 2 with DatabaseInput

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

the class GlueInputConverter method convertDatabase.

public static DatabaseInput convertDatabase(Database database) {
    DatabaseInput input = new DatabaseInput();
    input.setName(database.getDatabaseName());
    input.setParameters(database.getParameters());
    database.getComment().ifPresent(input::setDescription);
    database.getLocation().ifPresent(input::setLocationUri);
    return input;
}
Also used : DatabaseInput(com.amazonaws.services.glue.model.DatabaseInput)

Example 3 with DatabaseInput

use of com.amazonaws.services.glue.model.DatabaseInput 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)

Example 4 with DatabaseInput

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

the class GlueHiveMetastore method renameDatabase.

@Override
public void renameDatabase(MetastoreContext metastoreContext, String databaseName, String newDatabaseName) {
    try {
        Database database = getDatabase(metastoreContext, databaseName).orElseThrow(() -> new SchemaNotFoundException(databaseName));
        DatabaseInput renamedDatabase = GlueInputConverter.convertDatabase(database).withName(newDatabaseName);
        stats.getUpdateDatabase().record(() -> glueClient.updateDatabase(new UpdateDatabaseRequest().withCatalogId(catalogId).withName(databaseName).withDatabaseInput(renamedDatabase)));
    } catch (AmazonServiceException e) {
        throw new PrestoException(HIVE_METASTORE_ERROR, e);
    }
}
Also used : UpdateDatabaseRequest(com.amazonaws.services.glue.model.UpdateDatabaseRequest) Database(com.facebook.presto.hive.metastore.Database) AmazonServiceException(com.amazonaws.AmazonServiceException) DatabaseInput(com.amazonaws.services.glue.model.DatabaseInput) PrestoException(com.facebook.presto.spi.PrestoException) SchemaNotFoundException(com.facebook.presto.spi.SchemaNotFoundException)

Aggregations

DatabaseInput (com.amazonaws.services.glue.model.DatabaseInput)4 AmazonServiceException (com.amazonaws.AmazonServiceException)2 PrestoException (com.facebook.presto.spi.PrestoException)2 AlreadyExistsException (com.amazonaws.services.glue.model.AlreadyExistsException)1 CreateDatabaseRequest (com.amazonaws.services.glue.model.CreateDatabaseRequest)1 UpdateDatabaseRequest (com.amazonaws.services.glue.model.UpdateDatabaseRequest)1 SchemaAlreadyExistsException (com.facebook.presto.hive.SchemaAlreadyExistsException)1 TableAlreadyExistsException (com.facebook.presto.hive.TableAlreadyExistsException)1 Database (com.facebook.presto.hive.metastore.Database)1 SchemaNotFoundException (com.facebook.presto.spi.SchemaNotFoundException)1 Path (org.apache.hadoop.fs.Path)1 Test (org.testng.annotations.Test)1