in aws-glue-datacatalog-client-common/src/main/java/com/amazonaws/glue/catalog/metastore/DefaultAWSGlueMetastore.java [261:306]
private List<Partition> getPartitionsParallel(
final String databaseName,
final String tableName,
final String expression,
final long max) throws TException {
// Prepare the segments
List<Segment> segments = Lists.newArrayList();
for (int i = 0; i < numPartitionSegments; i++) {
segments.add(new Segment()
.withSegmentNumber(i)
.withTotalSegments(numPartitionSegments));
}
// Submit Glue API calls in parallel using the thread pool.
// We could convert this into a parallelStream after upgrading to JDK 8 compiler base.
List<Future<List<Partition>>> futures = Lists.newArrayList();
for (final Segment segment : segments) {
futures.add(this.executorService.submit(new Callable<List<Partition>>() {
@Override
public List<Partition> call() throws Exception {
return getCatalogPartitions(databaseName, tableName, expression, max, segment);
}
}));
}
// Get the results
List<Partition> partitions = Lists.newArrayList();
try {
for (Future<List<Partition>> future : futures) {
List<Partition> segmentPartitions = future.get();
if (partitions.size() + segmentPartitions.size() >= max && max > 0) {
// Extract the required number of partitions from the segment and we're done.
long remaining = max - partitions.size();
partitions.addAll(segmentPartitions.subList(0, (int) remaining));
break;
} else {
partitions.addAll(segmentPartitions);
}
}
} catch (ExecutionException e) {
Throwables.propagateIfInstanceOf(e.getCause(), AmazonServiceException.class);
Throwables.propagate(e.getCause());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return partitions;
}