Search in sources :

Example 1 with BucketFunction

use of io.trino.spi.connector.BucketFunction in project trino by trinodb.

the class SystemPartitioningHandle method getPartitionFunction.

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

Example 2 with BucketFunction

use of io.trino.spi.connector.BucketFunction in project trino by trinodb.

the class TestRaptorBucketFunction method testVarcharBigint.

@Test
public void testVarcharBigint() {
    BucketFunction function = bucketFunction(50, createUnboundedVarcharType(), BIGINT);
    assertEquals(getBucket(function, createStringsBlock("lorem ipsum"), createLongsBlock(123456789012L)), 24);
    assertEquals(getBucket(function, createStringsBlock("lorem"), createLongsBlock(454345325)), 32);
    assertEquals(getBucket(function, createStringsBlock("ipsum"), createLongsBlock(365363)), 21);
    assertEquals(getBucket(function, createStringsBlock("hello"), createLongsBlock(45645747)), 34);
    assertEquals(getBucket(function, createStringsBlock("world"), createLongsBlock(3244)), 4);
}
Also used : BucketFunction(io.trino.spi.connector.BucketFunction) Test(org.testng.annotations.Test)

Example 3 with BucketFunction

use of io.trino.spi.connector.BucketFunction in project trino by trinodb.

the class TestRaptorBucketFunction method testBigint.

@Test
public void testBigint() {
    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(io.trino.spi.connector.BucketFunction) Test(org.testng.annotations.Test)

Example 4 with BucketFunction

use of io.trino.spi.connector.BucketFunction in project trino by trinodb.

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(io.trino.spi.connector.BucketFunction) Test(org.testng.annotations.Test)

Example 5 with BucketFunction

use of io.trino.spi.connector.BucketFunction in project trino by trinodb.

the class TestHivePartitionedBucketFunction method testConsecutiveBucketsWithinPartition.

/**
 * Make sure that hashes for single partitions are consecutive. This makes
 * sure that single partition insert will be distributed across all worker nodes
 * (when number of workers is less or equal to number of partition buckets) because
 * workers are assigned to consecutive buckets in sequence.
 */
@Test(dataProvider = "hiveBucketingVersion")
public void testConsecutiveBucketsWithinPartition(BucketingVersion hiveBucketingVersion) {
    BlockBuilder bucketColumn = BIGINT.createFixedSizeBlockBuilder(10);
    BlockBuilder partitionColumn = BIGINT.createFixedSizeBlockBuilder(10);
    for (int i = 0; i < 100; ++i) {
        bucketColumn.writeLong(i);
        partitionColumn.writeLong(42);
    }
    Page page = new Page(bucketColumn, partitionColumn);
    BucketFunction hivePartitionedBucketFunction = partitionedBucketFunction(hiveBucketingVersion, 10, ImmutableList.of(HIVE_LONG), ImmutableList.of(BIGINT), 4000);
    List<Integer> positions = new ArrayList<>();
    for (int i = 0; i < 100; ++i) {
        positions.add(hivePartitionedBucketFunction.getBucket(page, i));
    }
    int minPosition = min(positions);
    int maxPosition = max(positions);
    // assert that every bucket number was generated
    assertEquals(maxPosition - minPosition + 1, 10);
}
Also used : ArrayList(java.util.ArrayList) Page(io.trino.spi.Page) BucketFunction(io.trino.spi.connector.BucketFunction) BlockBuilder(io.trino.spi.block.BlockBuilder) Test(org.testng.annotations.Test)

Aggregations

BucketFunction (io.trino.spi.connector.BucketFunction)11 Test (org.testng.annotations.Test)8 Page (io.trino.spi.Page)4 ImmutableList (com.google.common.collect.ImmutableList)2 BlockAssertions.createLongRepeatBlock (io.trino.block.BlockAssertions.createLongRepeatBlock)2 BlockAssertions.createLongsBlock (io.trino.block.BlockAssertions.createLongsBlock)2 CatalogName (io.trino.connector.CatalogName)2 BucketPartitionFunction (io.trino.operator.BucketPartitionFunction)2 Block (io.trino.spi.block.Block)2 BlockBuilder (io.trino.spi.block.BlockBuilder)2 ConnectorNodePartitioningProvider (io.trino.spi.connector.ConnectorNodePartitioningProvider)2 BIGINT (io.trino.spi.type.BigintType.BIGINT)2 Type (io.trino.spi.type.Type)2 TypeOperators (io.trino.spi.type.TypeOperators)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Assert.assertEquals (org.testng.Assert.assertEquals)2