Search in sources :

Example 1 with Segment

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

the class GlueHiveMetastore method getPartitions.

private List<Partition> getPartitions(String databaseName, String tableName, String expression) {
    if (partitionSegments == 1) {
        return getPartitions(databaseName, tableName, expression, null);
    }
    // Do parallel partition fetch.
    CompletionService<List<Partition>> completionService = new ExecutorCompletionService<>(executor);
    for (int i = 0; i < partitionSegments; i++) {
        Segment segment = new Segment().withSegmentNumber(i).withTotalSegments(partitionSegments);
        completionService.submit(() -> getPartitions(databaseName, tableName, expression, segment));
    }
    List<Partition> partitions = new ArrayList<>();
    try {
        for (int i = 0; i < partitionSegments; i++) {
            Future<List<Partition>> futurePartitions = completionService.take();
            partitions.addAll(futurePartitions.get());
        }
    } catch (ExecutionException | InterruptedException e) {
        if (e instanceof InterruptedException) {
            Thread.currentThread().interrupt();
        }
        throw new PrestoException(HIVE_METASTORE_ERROR, "Failed to fetch partitions from Glue Data Catalog", e);
    }
    partitions.sort(PARTITION_COMPARATOR);
    return partitions;
}
Also used : Partition(com.facebook.presto.hive.metastore.Partition) ArrayList(java.util.ArrayList) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) PrestoException(com.facebook.presto.spi.PrestoException) Segment(com.amazonaws.services.glue.model.Segment) ArrayList(java.util.ArrayList) PartitionValueList(com.amazonaws.services.glue.model.PartitionValueList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

PartitionValueList (com.amazonaws.services.glue.model.PartitionValueList)1 Segment (com.amazonaws.services.glue.model.Segment)1 Partition (com.facebook.presto.hive.metastore.Partition)1 PrestoException (com.facebook.presto.spi.PrestoException)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorCompletionService (java.util.concurrent.ExecutorCompletionService)1