Search in sources :

Example 1 with UpdatePartitionRequest

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

the class GlueHiveMetastore method updatePartitionStatistics.

@Override
public void updatePartitionStatistics(MetastoreContext metastoreContext, String databaseName, String tableName, String partitionName, Function<PartitionStatistics, PartitionStatistics> update) {
    PartitionStatistics currentStatistics = getPartitionStatistics(metastoreContext, databaseName, tableName, ImmutableSet.of(partitionName)).get(partitionName);
    if (currentStatistics == null) {
        throw new PrestoException(HIVE_PARTITION_DROPPED_DURING_QUERY, "Statistics result does not contain entry for partition: " + partitionName);
    }
    PartitionStatistics updatedStatistics = update.apply(currentStatistics);
    if (!updatedStatistics.getColumnStatistics().isEmpty()) {
        throw new PrestoException(NOT_SUPPORTED, "Glue metastore does not support column level statistics");
    }
    List<String> partitionValues = toPartitionValues(partitionName);
    Partition partition = getPartition(metastoreContext, databaseName, tableName, partitionValues).orElseThrow(() -> new PartitionNotFoundException(new SchemaTableName(databaseName, tableName), partitionValues));
    try {
        PartitionInput partitionInput = GlueInputConverter.convertPartition(partition);
        partitionInput.setParameters(updateStatisticsParameters(partition.getParameters(), updatedStatistics.getBasicStatistics()));
        stats.getUpdatePartition().record(() -> glueClient.updatePartition(new UpdatePartitionRequest().withCatalogId(catalogId).withDatabaseName(databaseName).withTableName(tableName).withPartitionValueList(partition.getValues()).withPartitionInput(partitionInput)));
    } catch (EntityNotFoundException e) {
        throw new PartitionNotFoundException(new SchemaTableName(databaseName, tableName), partitionValues);
    } catch (AmazonServiceException e) {
        throw new PrestoException(HIVE_METASTORE_ERROR, e);
    }
}
Also used : Partition(com.facebook.presto.hive.metastore.Partition) PartitionNotFoundException(com.facebook.presto.hive.PartitionNotFoundException) PartitionStatistics(com.facebook.presto.hive.metastore.PartitionStatistics) AmazonServiceException(com.amazonaws.AmazonServiceException) PrestoException(com.facebook.presto.spi.PrestoException) UpdatePartitionRequest(com.amazonaws.services.glue.model.UpdatePartitionRequest) EntityNotFoundException(com.amazonaws.services.glue.model.EntityNotFoundException) SchemaTableName(com.facebook.presto.spi.SchemaTableName) PartitionInput(com.amazonaws.services.glue.model.PartitionInput)

Example 2 with UpdatePartitionRequest

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

the class GlueHiveMetastore method alterPartition.

@Override
public void alterPartition(MetastoreContext metastoreContext, String databaseName, String tableName, PartitionWithStatistics partition) {
    try {
        PartitionInput newPartition = GlueInputConverter.convertPartition(partition);
        stats.getUpdatePartition().record(() -> glueClient.updatePartition(new UpdatePartitionRequest().withCatalogId(catalogId).withDatabaseName(databaseName).withTableName(tableName).withPartitionInput(newPartition).withPartitionValueList(partition.getPartition().getValues())));
    } catch (EntityNotFoundException e) {
        throw new PartitionNotFoundException(new SchemaTableName(databaseName, tableName), partition.getPartition().getValues());
    } catch (AmazonServiceException e) {
        throw new PrestoException(HIVE_METASTORE_ERROR, e);
    }
}
Also used : PartitionNotFoundException(com.facebook.presto.hive.PartitionNotFoundException) AmazonServiceException(com.amazonaws.AmazonServiceException) PrestoException(com.facebook.presto.spi.PrestoException) UpdatePartitionRequest(com.amazonaws.services.glue.model.UpdatePartitionRequest) EntityNotFoundException(com.amazonaws.services.glue.model.EntityNotFoundException) SchemaTableName(com.facebook.presto.spi.SchemaTableName) PartitionInput(com.amazonaws.services.glue.model.PartitionInput)

Aggregations

AmazonServiceException (com.amazonaws.AmazonServiceException)2 EntityNotFoundException (com.amazonaws.services.glue.model.EntityNotFoundException)2 PartitionInput (com.amazonaws.services.glue.model.PartitionInput)2 UpdatePartitionRequest (com.amazonaws.services.glue.model.UpdatePartitionRequest)2 PartitionNotFoundException (com.facebook.presto.hive.PartitionNotFoundException)2 PrestoException (com.facebook.presto.spi.PrestoException)2 SchemaTableName (com.facebook.presto.spi.SchemaTableName)2 Partition (com.facebook.presto.hive.metastore.Partition)1 PartitionStatistics (com.facebook.presto.hive.metastore.PartitionStatistics)1