Search in sources :

Example 1 with BucketFunction

use of com.facebook.presto.spi.BucketFunction in project presto by prestodb.

the class TestRaptorBucketFunction method testInteger.

@Test
public void testInteger() {
    BucketFunction function = bucketFunction(50, INTEGER);
    assertEquals(getBucket(function, createIntsBlock(454345325)), 16);
    assertEquals(getBucket(function, createIntsBlock(365363)), 42);
    assertEquals(getBucket(function, createIntsBlock(45645747)), 41);
    assertEquals(getBucket(function, createIntsBlock(3244)), 29);
}
Also used : BucketFunction(com.facebook.presto.spi.BucketFunction) Test(org.testng.annotations.Test)

Example 2 with BucketFunction

use of com.facebook.presto.spi.BucketFunction in project presto by prestodb.

the class TestRaptorBucketFunction method testBigint.

@Test
public void testBigint() throws Exception {
    BucketFunction function = bucketFunction(50, BIGINT);
    assertEquals(getBucket(function, createLongsBlock(123456789012L)), 12);
    assertEquals(getBucket(function, createLongsBlock(454345325)), 16);
    assertEquals(getBucket(function, createLongsBlock(365363)), 42);
    assertEquals(getBucket(function, createLongsBlock(45645747)), 41);
    assertEquals(getBucket(function, createLongsBlock(3244)), 29);
    function = bucketFunction(2, BIGINT);
    assertEquals(getBucket(function, createLongsBlock(123456789012L)), 0);
    assertEquals(getBucket(function, createLongsBlock(454345325)), 0);
    assertEquals(getBucket(function, createLongsBlock(365363)), 0);
    assertEquals(getBucket(function, createLongsBlock(45645747)), 1);
    assertEquals(getBucket(function, createLongsBlock(3244)), 1);
}
Also used : BucketFunction(com.facebook.presto.spi.BucketFunction) Test(org.testng.annotations.Test)

Example 3 with BucketFunction

use of com.facebook.presto.spi.BucketFunction 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 = partitioningProviders.get(partitioningHandle.getConnectorId().get());
        checkArgument(partitioningProvider != null, "No partitioning provider for connector %s", 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 PartitionFunction(bucketFunction, partitioningScheme.getBucketToPartition().get());
}
Also used : PartitionFunction(com.facebook.presto.operator.PartitionFunction) ConnectorNodePartitioningProvider(com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider) BucketFunction(com.facebook.presto.spi.BucketFunction)

Example 4 with BucketFunction

use of com.facebook.presto.spi.BucketFunction 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 PartitionFunction(bucketFunction, bucketToPartition);
}
Also used : PartitionFunction(com.facebook.presto.operator.PartitionFunction) BucketFunction(com.facebook.presto.spi.BucketFunction)

Example 5 with BucketFunction

use of com.facebook.presto.spi.BucketFunction in project presto by prestodb.

the class TestRaptorBucketFunction method testVarchar.

@Test
public void testVarchar() {
    BucketFunction function = bucketFunction(50, createUnboundedVarcharType());
    assertEquals(getBucket(function, createStringsBlock("lorem ipsum")), 2);
    assertEquals(getBucket(function, createStringsBlock("lorem")), 26);
    assertEquals(getBucket(function, createStringsBlock("ipsum")), 3);
    assertEquals(getBucket(function, createStringsBlock("hello")), 19);
}
Also used : BucketFunction(com.facebook.presto.spi.BucketFunction) Test(org.testng.annotations.Test)

Aggregations

BucketFunction (com.facebook.presto.spi.BucketFunction)6 Test (org.testng.annotations.Test)4 PartitionFunction (com.facebook.presto.operator.PartitionFunction)2 ConnectorNodePartitioningProvider (com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider)1