Search in sources :

Example 1 with GetSlicesResponse

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

the class SplitsFetcher method getSplits.

GetSplitsResponse getSplits(GetSplitsRequest request, SpillLocationFactory spillLocationFactory, EncryptionKey encryptionKey) {
    CatalogLocator locator = FoundryAthenaObjectMapper.objectMapper().convertValue(request.getSchema().getCustomMetadata(), CatalogLocator.class);
    Optional<Filter> filter;
    if (request.getConstraints().getSummary().isEmpty()) {
        filter = Optional.empty();
    } else {
        // we just push down all constraints which will include those for any partition columns
        filter = Optional.of(Filter.and(AndFilter.of(request.getConstraints().getSummary().entrySet().stream().map(entry -> ConstraintConverter.convert(entry.getKey(), entry.getValue())).collect(Collectors.toList()))));
    }
    Set<Split> splits = new HashSet<>();
    Optional<String> pageToken = Optional.empty();
    while (true) {
        GetSlicesResponse response = metadataService.getSlices(authProvider.getAuthHeader(), GetSlicesRequest.builder().locator(locator).filter(filter).nextPageToken(pageToken).build());
        splits.addAll(response.getSlices().stream().map(slice -> slices.toSplit(spillLocationFactory.makeSpillLocation(), encryptionKey, slice)).collect(Collectors.toSet()));
        if (response.getNextPageToken().isPresent()) {
            pageToken = response.getNextPageToken();
        } else {
            log.debug("finished planning splits. number of splits: {}", splits.size());
            return new GetSplitsResponse(request.getCatalogName(), splits);
        }
    }
}
Also used : CatalogLocator(com.palantir.foundry.athena.api.CatalogLocator) GetSplitsResponse(com.amazonaws.athena.connector.lambda.metadata.GetSplitsResponse) Filter(com.palantir.foundry.athena.api.Filter) Logger(org.slf4j.Logger) CatalogLocator(com.palantir.foundry.athena.api.CatalogLocator) Split(com.amazonaws.athena.connector.lambda.domain.Split) LoggerFactory(org.slf4j.LoggerFactory) GetSlicesRequest(com.palantir.foundry.athena.api.GetSlicesRequest) Set(java.util.Set) SpillLocation(com.amazonaws.athena.connector.lambda.domain.spill.SpillLocation) GetSlicesResponse(com.palantir.foundry.athena.api.GetSlicesResponse) Collectors(java.util.stream.Collectors) AndFilter(com.palantir.foundry.athena.api.AndFilter) HashSet(java.util.HashSet) FoundryAthenaMetadataServiceBlocking(com.palantir.foundry.athena.api.FoundryAthenaMetadataServiceBlocking) EncryptionKey(com.amazonaws.athena.connector.lambda.security.EncryptionKey) Optional(java.util.Optional) GetSplitsRequest(com.amazonaws.athena.connector.lambda.metadata.GetSplitsRequest) GetSlicesResponse(com.palantir.foundry.athena.api.GetSlicesResponse) Filter(com.palantir.foundry.athena.api.Filter) AndFilter(com.palantir.foundry.athena.api.AndFilter) GetSplitsResponse(com.amazonaws.athena.connector.lambda.metadata.GetSplitsResponse) Split(com.amazonaws.athena.connector.lambda.domain.Split) HashSet(java.util.HashSet)

Aggregations

Split (com.amazonaws.athena.connector.lambda.domain.Split)1 SpillLocation (com.amazonaws.athena.connector.lambda.domain.spill.SpillLocation)1 GetSplitsRequest (com.amazonaws.athena.connector.lambda.metadata.GetSplitsRequest)1 GetSplitsResponse (com.amazonaws.athena.connector.lambda.metadata.GetSplitsResponse)1 EncryptionKey (com.amazonaws.athena.connector.lambda.security.EncryptionKey)1 AndFilter (com.palantir.foundry.athena.api.AndFilter)1 CatalogLocator (com.palantir.foundry.athena.api.CatalogLocator)1 Filter (com.palantir.foundry.athena.api.Filter)1 FoundryAthenaMetadataServiceBlocking (com.palantir.foundry.athena.api.FoundryAthenaMetadataServiceBlocking)1 GetSlicesRequest (com.palantir.foundry.athena.api.GetSlicesRequest)1 GetSlicesResponse (com.palantir.foundry.athena.api.GetSlicesResponse)1 HashSet (java.util.HashSet)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1