Search in sources :

Example 1 with AWSGlueException

use of com.amazonaws.services.glue.model.AWSGlueException in project alluxio by Alluxio.

the class GlueDatabase method batchGetPartitions.

private List<Partition> batchGetPartitions(AWSGlueAsync glueClient, String tableName) throws IOException {
    // TODO(shouwei): make getPartition multi-thread to accelerate the large table fetching
    List<Partition> partitions = new ArrayList<>();
    String nextToken = null;
    try {
        do {
            GetPartitionsRequest getPartitionsRequest = new GetPartitionsRequest().withCatalogId(mGlueConfiguration.get(Property.CATALOG_ID)).withDatabaseName(mGlueDbName).withTableName(tableName).withMaxResults(mGlueConfiguration.getInt(Property.MAX_GLUE_FETCH_PARTITIONS)).withNextToken(nextToken);
            GetPartitionsResult getPartitionsResult = glueClient.getPartitions(getPartitionsRequest);
            partitions.addAll(getPartitionsResult.getPartitions());
            nextToken = getPartitionsResult.getNextToken();
            LOG.debug("Glue table {}.{} adding {} batch partitions with total {} partitions.", mGlueDbName, tableName, getPartitionsResult.getPartitions().size(), partitions.size());
        } while (nextToken != null);
        if (partitions != null) {
            LOG.info("Glue table {}.{} has {} partitions.", mGlueDbName, tableName, partitions.size());
            if (LOG.isDebugEnabled()) {
                partitions.stream().forEach(partition -> LOG.debug("Glue table {}.{} with partition: {}.", partition.getDatabaseName(), tableName, partition));
            }
        }
        return partitions;
    } catch (AWSGlueException e) {
        throw new IOException("Cannot get partition information for table: " + tableName + " in Database: " + mGlueDbName + "; Catalog ID: " + mGlueConfiguration.get(Property.CATALOG_ID) + ". error: " + e.getMessage(), e);
    }
}
Also used : UdbPartition(alluxio.table.common.UdbPartition) Partition(com.amazonaws.services.glue.model.Partition) GetPartitionsResult(com.amazonaws.services.glue.model.GetPartitionsResult) AWSGlueException(com.amazonaws.services.glue.model.AWSGlueException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) GetPartitionsRequest(com.amazonaws.services.glue.model.GetPartitionsRequest)

Aggregations

UdbPartition (alluxio.table.common.UdbPartition)1 AWSGlueException (com.amazonaws.services.glue.model.AWSGlueException)1 GetPartitionsRequest (com.amazonaws.services.glue.model.GetPartitionsRequest)1 GetPartitionsResult (com.amazonaws.services.glue.model.GetPartitionsResult)1 Partition (com.amazonaws.services.glue.model.Partition)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1