Example usage for com.amazonaws.services.glue.model BatchCreatePartitionRequest BatchCreatePartitionRequest

List of usage examples for com.amazonaws.services.glue.model BatchCreatePartitionRequest BatchCreatePartitionRequest

Introduction

In this page you can find the example usage for com.amazonaws.services.glue.model BatchCreatePartitionRequest BatchCreatePartitionRequest.

Prototype

BatchCreatePartitionRequest

Source Link

Usage

From source file:com.facebook.presto.hive.metastore.glue.GlueHiveMetastore.java

License:Apache License

@Override
public void addPartitions(String databaseName, String tableName, List<PartitionWithStatistics> partitions) {
    try {//  w w w. j  a  v a  2  s .c o  m
        List<List<PartitionWithStatistics>> batchedPartitions = Lists.partition(partitions,
                BATCH_CREATE_PARTITION_MAX_PAGE_SIZE);
        List<Future<BatchCreatePartitionResult>> futures = new ArrayList<>();

        for (List<PartitionWithStatistics> partitionBatch : batchedPartitions) {
            List<PartitionInput> partitionInputs = partitionBatch.stream()
                    .map(GlueInputConverter::convertPartition).collect(toList());
            futures.add(glueClient
                    .batchCreatePartitionAsync(new BatchCreatePartitionRequest().withDatabaseName(databaseName)
                            .withTableName(tableName).withPartitionInputList(partitionInputs)));
        }

        for (Future<BatchCreatePartitionResult> future : futures) {
            BatchCreatePartitionResult result = future.get();
            propagatePartitionErrorToPrestoException(databaseName, tableName, result.getErrors());
        }
    } catch (AmazonServiceException | InterruptedException | ExecutionException e) {
        if (e instanceof InterruptedException) {
            Thread.currentThread().interrupt();
        }
        throw new PrestoException(HIVE_METASTORE_ERROR, e);
    }
}