Search in sources :

Example 1 with GetPartitionsResponsePage

use of com.palantir.foundry.athena.api.GetPartitionsResponsePage in project foundry-athena-query-federation-connector by palantir.

the class PartitionFetcher method getAndWritePartitions.

private void getAndWritePartitions(BlockWriter blockWriter, GetTableLayoutRequest request, QueryStatusChecker queryStatusChecker) {
    CatalogLocator locator = FoundryAthenaObjectMapper.objectMapper().convertValue(request.getSchema().getCustomMetadata(), CatalogLocator.class);
    Optional<String> pageToken = Optional.empty();
    while (queryStatusChecker.isQueryRunning()) {
        GetPartitionsResponsePage page = metadataService.getPartitions(authProvider.getAuthHeader(), GetPartitionsRequest.builder().locator(locator).limit(PAGE_SIZE).pageToken(pageToken).build());
        page.getPartitions().forEach(partition -> blockWriter.writeRows((block, rowNum) -> {
            boolean matched = partition.get().entrySet().stream().map(fieldName -> fieldName.getValue().accept(new PartitionValueWriter(block, fieldName.getKey(), rowNum))).reduce(true, Boolean::logicalAnd);
            // if all fields passed then we wrote 1 row
            return matched ? 1 : 0;
        }));
        if (page.getNextPageToken().isPresent()) {
            pageToken = page.getNextPageToken();
        } else {
            return;
        }
    }
}
Also used : CatalogLocator(com.palantir.foundry.athena.api.CatalogLocator) GetPartitionsResponsePage(com.palantir.foundry.athena.api.GetPartitionsResponsePage) BlockWriter(com.amazonaws.athena.connector.lambda.data.BlockWriter) CatalogLocator(com.palantir.foundry.athena.api.CatalogLocator) FoundryAthenaMetadataServiceBlocking(com.palantir.foundry.athena.api.FoundryAthenaMetadataServiceBlocking) GetTableLayoutRequest(com.amazonaws.athena.connector.lambda.metadata.GetTableLayoutRequest) Optional(java.util.Optional) QueryStatusChecker(com.amazonaws.athena.connector.lambda.QueryStatusChecker) VisibleForTesting(com.google.common.annotations.VisibleForTesting) GetPartitionsRequest(com.palantir.foundry.athena.api.GetPartitionsRequest) GetPartitionsResponsePage(com.palantir.foundry.athena.api.GetPartitionsResponsePage)

Aggregations

QueryStatusChecker (com.amazonaws.athena.connector.lambda.QueryStatusChecker)1 BlockWriter (com.amazonaws.athena.connector.lambda.data.BlockWriter)1 GetTableLayoutRequest (com.amazonaws.athena.connector.lambda.metadata.GetTableLayoutRequest)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 CatalogLocator (com.palantir.foundry.athena.api.CatalogLocator)1 FoundryAthenaMetadataServiceBlocking (com.palantir.foundry.athena.api.FoundryAthenaMetadataServiceBlocking)1 GetPartitionsRequest (com.palantir.foundry.athena.api.GetPartitionsRequest)1 GetPartitionsResponsePage (com.palantir.foundry.athena.api.GetPartitionsResponsePage)1 Optional (java.util.Optional)1