Search in sources :

Example 1 with BucketPartitionFunction

use of com.facebook.presto.operator.BucketPartitionFunction in project presto by prestodb.

the class NodePartitioningManager method getPartitionFunction.

public PartitionFunction getPartitionFunction(Session session, PartitioningScheme partitioningScheme, List<Type> partitionChannelTypes) {
    Optional<int[]> bucketToPartition = partitioningScheme.getBucketToPartition();
    checkArgument(bucketToPartition.isPresent(), "Bucket to partition must be set before a partition function can be created");
    PartitioningHandle partitioningHandle = partitioningScheme.getPartitioning().getHandle();
    BucketFunction bucketFunction;
    if (partitioningHandle.getConnectorHandle() instanceof SystemPartitioningHandle) {
        checkArgument(partitioningScheme.getBucketToPartition().isPresent(), "Bucket to partition must be set before a partition function can be created");
        return ((SystemPartitioningHandle) partitioningHandle.getConnectorHandle()).getPartitionFunction(partitionChannelTypes, partitioningScheme.getHashColumn().isPresent(), partitioningScheme.getBucketToPartition().get());
    } else {
        ConnectorNodePartitioningProvider partitioningProvider = partitioningProviderManager.getPartitioningProvider(partitioningHandle.getConnectorId().get());
        bucketFunction = partitioningProvider.getBucketFunction(partitioningHandle.getTransactionHandle().orElse(null), session.toConnectorSession(), partitioningHandle.getConnectorHandle(), partitionChannelTypes, bucketToPartition.get().length);
        checkArgument(bucketFunction != null, "No function %s", partitioningHandle);
    }
    return new BucketPartitionFunction(bucketFunction, partitioningScheme.getBucketToPartition().get());
}
Also used : BucketPartitionFunction(com.facebook.presto.operator.BucketPartitionFunction) ConnectorNodePartitioningProvider(com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider) BucketFunction(com.facebook.presto.spi.BucketFunction)

Example 2 with BucketPartitionFunction

use of com.facebook.presto.operator.BucketPartitionFunction in project presto by prestodb.

the class SystemPartitioningHandle method getPartitionFunction.

public PartitionFunction getPartitionFunction(List<Type> partitionChannelTypes, boolean isHashPrecomputed, int[] bucketToPartition) {
    requireNonNull(partitionChannelTypes, "partitionChannelTypes is null");
    requireNonNull(bucketToPartition, "bucketToPartition is null");
    BucketFunction bucketFunction = function.createBucketFunction(partitionChannelTypes, isHashPrecomputed, bucketToPartition.length);
    return new BucketPartitionFunction(bucketFunction, bucketToPartition);
}
Also used : BucketPartitionFunction(com.facebook.presto.operator.BucketPartitionFunction) BucketFunction(com.facebook.presto.spi.BucketFunction)

Example 3 with BucketPartitionFunction

use of com.facebook.presto.operator.BucketPartitionFunction in project presto by prestodb.

the class LocalExchange method createPartitionFunction.

static PartitionFunction createPartitionFunction(PartitioningProviderManager partitioningProviderManager, Session session, PartitioningHandle partitioning, int partitionCount, List<Type> partitioningChannelTypes, boolean isHashPrecomputed) {
    if (partitioning.getConnectorHandle() instanceof SystemPartitioningHandle) {
        HashGenerator hashGenerator;
        if (isHashPrecomputed) {
            hashGenerator = new PrecomputedHashGenerator(0);
        } else {
            hashGenerator = InterpretedHashGenerator.createPositionalWithTypes(partitioningChannelTypes);
        }
        return new LocalPartitionGenerator(hashGenerator, partitionCount);
    }
    ConnectorNodePartitioningProvider partitioningProvider = partitioningProviderManager.getPartitioningProvider(partitioning.getConnectorId().get());
    int bucketCount = partitioningProvider.getBucketCount(partitioning.getTransactionHandle().orElse(null), session.toConnectorSession(partitioning.getConnectorId().get()), partitioning.getConnectorHandle());
    int[] bucketToPartition = new int[bucketCount];
    for (int bucket = 0; bucket < bucketCount; bucket++) {
        bucketToPartition[bucket] = bucket % partitionCount;
    }
    BucketFunction bucketFunction = partitioningProvider.getBucketFunction(partitioning.getTransactionHandle().orElse(null), session.toConnectorSession(), partitioning.getConnectorHandle(), partitioningChannelTypes, bucketCount);
    checkArgument(bucketFunction != null, "No bucket function for partitioning: %s", partitioning);
    return new BucketPartitionFunction(bucketFunction, bucketToPartition);
}
Also used : BucketPartitionFunction(com.facebook.presto.operator.BucketPartitionFunction) ConnectorNodePartitioningProvider(com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider) SystemPartitioningHandle(com.facebook.presto.sql.planner.SystemPartitioningHandle) PrecomputedHashGenerator(com.facebook.presto.operator.PrecomputedHashGenerator) HashGenerator(com.facebook.presto.operator.HashGenerator) PrecomputedHashGenerator(com.facebook.presto.operator.PrecomputedHashGenerator) InterpretedHashGenerator(com.facebook.presto.operator.InterpretedHashGenerator) BucketFunction(com.facebook.presto.spi.BucketFunction)

Aggregations

BucketPartitionFunction (com.facebook.presto.operator.BucketPartitionFunction)3 BucketFunction (com.facebook.presto.spi.BucketFunction)3 ConnectorNodePartitioningProvider (com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider)2 HashGenerator (com.facebook.presto.operator.HashGenerator)1 InterpretedHashGenerator (com.facebook.presto.operator.InterpretedHashGenerator)1 PrecomputedHashGenerator (com.facebook.presto.operator.PrecomputedHashGenerator)1 SystemPartitioningHandle (com.facebook.presto.sql.planner.SystemPartitioningHandle)1