Search in sources :

Example 1 with PrecomputedHashGenerator

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);
    }
}
Also used : PartitionFunction(com.facebook.presto.operator.PartitionFunction) ArrayType(com.facebook.presto.common.type.ArrayType) Type(com.facebook.presto.common.type.Type) BlockAssertions.createMapType(com.facebook.presto.block.BlockAssertions.createMapType) DecimalType.createDecimalType(com.facebook.presto.common.type.DecimalType.createDecimalType) LocalPartitionGenerator(com.facebook.presto.operator.exchange.LocalPartitionGenerator) PrecomputedHashGenerator(com.facebook.presto.operator.PrecomputedHashGenerator)

Example 2 with PrecomputedHashGenerator

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);
}
Also used : BucketPartitionFunction(com.facebook.presto.operator.BucketPartitionFunction) ConnectorNodePartitioningProvider(com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider) SystemPartitioningHandle(com.facebook.presto.sql.planner.SystemPartitioningHandle) PrecomputedHashGenerator(com.facebook.presto.operator.PrecomputedHashGenerator) HashGenerator(com.facebook.presto.operator.HashGenerator) PrecomputedHashGenerator(com.facebook.presto.operator.PrecomputedHashGenerator) InterpretedHashGenerator(com.facebook.presto.operator.InterpretedHashGenerator) BucketFunction(com.facebook.presto.spi.BucketFunction)

Example 3 with PrecomputedHashGenerator

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));
}
Also used : PartitionFunction(com.facebook.presto.operator.PartitionFunction) LocalPartitionGenerator(com.facebook.presto.operator.exchange.LocalPartitionGenerator) Page(com.facebook.presto.common.Page) SerializedPage(com.facebook.presto.spi.page.SerializedPage) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) PrecomputedHashGenerator(com.facebook.presto.operator.PrecomputedHashGenerator)

Aggregations

PrecomputedHashGenerator (com.facebook.presto.operator.PrecomputedHashGenerator)3 PartitionFunction (com.facebook.presto.operator.PartitionFunction)2 LocalPartitionGenerator (com.facebook.presto.operator.exchange.LocalPartitionGenerator)2 BlockAssertions.createMapType (com.facebook.presto.block.BlockAssertions.createMapType)1 Page (com.facebook.presto.common.Page)1 ArrayType (com.facebook.presto.common.type.ArrayType)1 DecimalType.createDecimalType (com.facebook.presto.common.type.DecimalType.createDecimalType)1 Type (com.facebook.presto.common.type.Type)1 BucketPartitionFunction (com.facebook.presto.operator.BucketPartitionFunction)1 HashGenerator (com.facebook.presto.operator.HashGenerator)1 InterpretedHashGenerator (com.facebook.presto.operator.InterpretedHashGenerator)1 BucketFunction (com.facebook.presto.spi.BucketFunction)1 ConnectorNodePartitioningProvider (com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider)1 SerializedPage (com.facebook.presto.spi.page.SerializedPage)1 SystemPartitioningHandle (com.facebook.presto.sql.planner.SystemPartitioningHandle)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1