Search in sources :

Example 1 with TableInput

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

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

the class GlueHiveMetastore method replaceTable.

@Override
public void replaceTable(MetastoreContext metastoreContext, String databaseName, String tableName, Table newTable, PrincipalPrivileges principalPrivileges) {
    try {
        TableInput newTableInput = GlueInputConverter.convertTable(newTable);
        stats.getUpdateTable().record(() -> glueClient.updateTable(new UpdateTableRequest().withCatalogId(catalogId).withDatabaseName(databaseName).withTableInput(newTableInput)));
    } catch (EntityNotFoundException e) {
        throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
    } 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) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) UpdateTableRequest(com.amazonaws.services.glue.model.UpdateTableRequest) AmazonServiceException(com.amazonaws.AmazonServiceException) PrestoException(com.facebook.presto.spi.PrestoException) EntityNotFoundException(com.amazonaws.services.glue.model.EntityNotFoundException) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 3 with TableInput

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

the class GlueHiveMetastore method updateTableStatistics.

@Override
public void updateTableStatistics(MetastoreContext metastoreContext, String databaseName, String tableName, Function<PartitionStatistics, PartitionStatistics> update) {
    PartitionStatistics currentStatistics = getTableStatistics(metastoreContext, databaseName, tableName);
    PartitionStatistics updatedStatistics = update.apply(currentStatistics);
    if (!updatedStatistics.getColumnStatistics().isEmpty()) {
        throw new PrestoException(NOT_SUPPORTED, "Glue metastore does not support column level statistics");
    }
    Table table = getTableOrElseThrow(metastoreContext, databaseName, tableName);
    try {
        TableInput tableInput = GlueInputConverter.convertTable(table);
        tableInput.setParameters(updateStatisticsParameters(table.getParameters(), updatedStatistics.getBasicStatistics()));
        UpdateTableRequest request = new UpdateTableRequest().withCatalogId(catalogId).withDatabaseName(databaseName).withTableInput(tableInput);
        stats.getUpdateTable().record(() -> glueClient.updateTable(request));
    } catch (EntityNotFoundException e) {
        throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
    } 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) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) Table(com.facebook.presto.hive.metastore.Table) PartitionStatistics(com.facebook.presto.hive.metastore.PartitionStatistics) UpdateTableRequest(com.amazonaws.services.glue.model.UpdateTableRequest) AmazonServiceException(com.amazonaws.AmazonServiceException) PrestoException(com.facebook.presto.spi.PrestoException) EntityNotFoundException(com.amazonaws.services.glue.model.EntityNotFoundException) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 4 with TableInput

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

the class GlueInputConverter method convertTable.

public static TableInput convertTable(Table table) {
    TableInput input = new TableInput();
    input.setName(table.getTableName());
    input.setOwner(table.getOwner());
    checkArgument(EnumSet.of(MANAGED_TABLE, EXTERNAL_TABLE, VIRTUAL_VIEW).contains(table.getTableType()), "Invalid table type: %s", table.getTableType());
    input.setTableType(table.getTableType().toString());
    input.setStorageDescriptor(convertStorage(table.getStorage(), table.getDataColumns()));
    input.setPartitionKeys(table.getPartitionColumns().stream().map(GlueInputConverter::convertColumn).collect(toList()));
    input.setParameters(table.getParameters());
    table.getViewOriginalText().ifPresent(input::setViewOriginalText);
    table.getViewExpandedText().ifPresent(input::setViewExpandedText);
    return input;
}
Also used : TableInput(com.amazonaws.services.glue.model.TableInput)

Example 5 with TableInput

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

the class GlueInputConverter method toTableInput.

public static TableInput toTableInput(com.amazonaws.services.glue.model.Table table) {
    TableInput input = new TableInput();
    input.setName(table.getName());
    input.setOwner(table.getOwner());
    input.setTableType(table.getTableType());
    input.setStorageDescriptor(table.getStorageDescriptor());
    input.setPartitionKeys(table.getPartitionKeys());
    input.setParameters(table.getParameters());
    input.setViewOriginalText(table.getViewOriginalText());
    input.setViewExpandedText(table.getViewExpandedText());
    return input;
}
Also used : TableInput(com.amazonaws.services.glue.model.TableInput)

Aggregations

TableInput (com.amazonaws.services.glue.model.TableInput)6 AmazonServiceException (com.amazonaws.AmazonServiceException)3 EntityNotFoundException (com.amazonaws.services.glue.model.EntityNotFoundException)3 GlueInputConverter.toTableInput (com.facebook.presto.hive.metastore.glue.converter.GlueInputConverter.toTableInput)3 PrestoException (com.facebook.presto.spi.PrestoException)3 SchemaTableName (com.facebook.presto.spi.SchemaTableName)3 UpdateTableRequest (com.amazonaws.services.glue.model.UpdateTableRequest)2 TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)2 AlreadyExistsException (com.amazonaws.services.glue.model.AlreadyExistsException)1 CreateTableRequest (com.amazonaws.services.glue.model.CreateTableRequest)1 SchemaAlreadyExistsException (com.facebook.presto.hive.SchemaAlreadyExistsException)1 TableAlreadyExistsException (com.facebook.presto.hive.TableAlreadyExistsException)1 PartitionStatistics (com.facebook.presto.hive.metastore.PartitionStatistics)1 Table (com.facebook.presto.hive.metastore.Table)1 SchemaNotFoundException (com.facebook.presto.spi.SchemaNotFoundException)1 Test (org.testng.annotations.Test)1