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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations