use of com.facebook.presto.operator.HashGenerator in project presto by prestodb.
the class TypeUtils method getHashPosition.
public static long getHashPosition(List<? extends Type> hashTypes, Block[] hashBlocks, int position) {
HashGenerator hashGenerator = InterpretedHashGenerator.createPositionalWithTypes(ImmutableList.copyOf(hashTypes));
Page page = new Page(hashBlocks);
return hashGenerator.hashPosition(position, page);
}
use of com.facebook.presto.operator.HashGenerator in project presto by prestodb.
the class TypeUtils method getHashBlock.
public static Block getHashBlock(List<? extends Type> hashTypes, Block... hashBlocks) {
checkArgument(hashTypes.size() == hashBlocks.length);
HashGenerator hashGenerator = InterpretedHashGenerator.createPositionalWithTypes(ImmutableList.copyOf(hashTypes));
int positionCount = hashBlocks[0].getPositionCount();
BlockBuilder builder = BIGINT.createFixedSizeBlockBuilder(positionCount);
Page page = new Page(hashBlocks);
for (int i = 0; i < positionCount; i++) {
BIGINT.writeLong(builder, hashGenerator.hashPosition(i, page));
}
return builder.build();
}
use of com.facebook.presto.operator.HashGenerator in project presto by prestodb.
the class TestOptimizedPartitionedOutputOperator method testPartitioned.
private void testPartitioned(List<Type> types, List<Page> pages, DataSize maxMemory, List<Integer> partitionChannel, HashGenerator hashGenerator) {
TestingPartitionedOutputBuffer outputBuffer = createPartitionedOutputBuffer();
PartitionFunction partitionFunction = new LocalPartitionGenerator(hashGenerator, PARTITION_COUNT);
OptimizedPartitionedOutputOperator operator = createOptimizedPartitionedOutputOperator(types, partitionChannel, partitionFunction, outputBuffer, OptionalInt.empty(), maxMemory);
Map<Integer, List<Page>> expectedPageList = new HashMap<>();
for (Page page : pages) {
Map<Integer, List<Integer>> positionsByPartition = new HashMap<>();
for (int i = 0; i < page.getPositionCount(); i++) {
int partitionNumber = partitionFunction.getPartition(page, i);
positionsByPartition.computeIfAbsent(partitionNumber, k -> new ArrayList<>()).add(i);
}
for (Map.Entry<Integer, List<Integer>> entry : positionsByPartition.entrySet()) {
if (!entry.getValue().isEmpty()) {
expectedPageList.computeIfAbsent(entry.getKey(), k -> new ArrayList<>()).add(copyPositions(page, entry.getValue()));
}
}
operator.addInput(page);
}
operator.finish();
Map<Integer, Page> expectedPages = Maps.transformValues(expectedPageList, outputPages -> mergePages(types, outputPages));
Map<Integer, Page> actualPages = Maps.transformValues(outputBuffer.getPages(), outputPages -> mergePages(types, outputPages));
assertEquals(actualPages.size(), expectedPages.size());
assertEquals(actualPages.keySet(), expectedPages.keySet());
for (Map.Entry<Integer, Page> entry : expectedPages.entrySet()) {
int key = entry.getKey();
assertPageEquals(types, actualPages.get(key), entry.getValue());
}
}
use of com.facebook.presto.operator.HashGenerator 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);
}
Aggregations