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

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

Introduction

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

Prototype

BatchGetPartitionRequest

Source Link

Usage

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

License:Apache License

private List<Partition> batchGetPartition(String databaseName, String tableName, List<String> partitionNames) {
    try {/*  w w w  . java 2s.c  o m*/
        List<PartitionValueList> partitionValueLists = partitionNames.stream()
                .map(partitionName -> new PartitionValueList().withValues(toPartitionValues(partitionName)))
                .collect(toList());

        List<List<PartitionValueList>> batchedPartitionValueLists = Lists.partition(partitionValueLists,
                BATCH_GET_PARTITION_MAX_PAGE_SIZE);
        List<Future<BatchGetPartitionResult>> batchGetPartitionFutures = new ArrayList<>();
        List<Partition> result = new ArrayList<>();

        for (List<PartitionValueList> partitions : batchedPartitionValueLists) {
            batchGetPartitionFutures.add(glueClient.batchGetPartitionAsync(new BatchGetPartitionRequest()
                    .withDatabaseName(databaseName).withTableName(tableName).withPartitionsToGet(partitions)));
        }

        for (Future<BatchGetPartitionResult> future : batchGetPartitionFutures) {
            future.get().getPartitions()
                    .forEach(partition -> result.add(GlueToPrestoConverter.convertPartition(partition)));
        }

        return result;
    } catch (AmazonServiceException | InterruptedException | ExecutionException e) {
        if (e instanceof InterruptedException) {
            Thread.currentThread().interrupt();
        }
        throw new PrestoException(HIVE_METASTORE_ERROR, e);
    }
}