use of com.facebook.presto.operator.PrecomputedHashGenerator in project presto by prestodb.
the class TestOptimizedPartitionedOutputOperator method createOptimizedPartitionedOutputOperator.
private OptimizedPartitionedOutputOperator createOptimizedPartitionedOutputOperator(List<Type> types, boolean replicateAllRows) {
TestingPartitionedOutputBuffer outputBuffer = createPartitionedOutputBuffer();
PartitionFunction partitionFunction = new LocalPartitionGenerator(new PrecomputedHashGenerator(0), PARTITION_COUNT);
if (replicateAllRows) {
List<Type> replicatedTypes = updateBlockTypesWithHashBlockAndNullBlock(types, false, true);
return createOptimizedPartitionedOutputOperator(replicatedTypes, ImmutableList.of(0), partitionFunction, outputBuffer, OptionalInt.of(replicatedTypes.size() - 1), MAX_MEMORY);
} else {
return createOptimizedPartitionedOutputOperator(types, ImmutableList.of(0), partitionFunction, outputBuffer, OptionalInt.empty(), MAX_MEMORY);
}
}
use of com.facebook.presto.operator.PrecomputedHashGenerator 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);
}
use of com.facebook.presto.operator.PrecomputedHashGenerator in project presto by prestodb.
the class TestOptimizedPartitionedOutputOperator method testReplicated.
private void testReplicated(List<Type> types, List<Page> pages, DataSize maxMemory) {
TestingPartitionedOutputBuffer outputBuffer = createPartitionedOutputBuffer();
PartitionFunction partitionFunction = new LocalPartitionGenerator(new PrecomputedHashGenerator(0), PARTITION_COUNT);
OptimizedPartitionedOutputOperator operator = createOptimizedPartitionedOutputOperator(types, ImmutableList.of(0), partitionFunction, outputBuffer, OptionalInt.of(types.size() - 1), maxMemory);
for (Page page : pages) {
operator.addInput(page);
}
operator.finish();
Map<Integer, List<Page>> acutualPageLists = outputBuffer.getPages();
assertEquals(acutualPageLists.size(), PARTITION_COUNT);
Page expectedPage = mergePages(types, pages);
acutualPageLists.values().forEach(pageList -> assertPageEquals(types, mergePages(types, pageList), expectedPage));
}
Aggregations