Search in sources :

Example 11 with OutputBuffers

use of com.facebook.presto.execution.buffer.OutputBuffers in project presto by prestodb.

the class TestPartitionedOutputOperator method createPartitionedOutputOperator.

private static PartitionedOutputOperator createPartitionedOutputOperator(boolean shouldReplicate) {
    PartitionFunction partitionFunction = new LocalPartitionGenerator(new InterpretedHashGenerator(ImmutableList.of(BIGINT), new int[] { 0 }), PARTITION_COUNT);
    OutputPartitioning outputPartitioning;
    if (shouldReplicate) {
        outputPartitioning = new OutputPartitioning(partitionFunction, ImmutableList.of(0), ImmutableList.of(Optional.empty()), true, OptionalInt.of(0));
    } else {
        outputPartitioning = new OutputPartitioning(partitionFunction, ImmutableList.of(0), ImmutableList.of(Optional.empty(), Optional.empty()), false, OptionalInt.empty());
    }
    PagesSerdeFactory serdeFactory = new PagesSerdeFactory(new BlockEncodingManager(), false);
    DriverContext driverContext = TestingTaskContext.builder(EXECUTOR, SCHEDULER, TEST_SESSION).setMemoryPoolSize(MAX_MEMORY).setQueryMaxTotalMemory(MAX_MEMORY).build().addPipelineContext(0, true, true, false).addDriverContext();
    OutputBuffers buffers = createInitialEmptyOutputBuffers(PARTITIONED);
    for (int partition = 0; partition < PARTITION_COUNT; partition++) {
        buffers = buffers.withBuffer(new OutputBuffers.OutputBufferId(partition), partition);
    }
    PartitionedOutputBuffer buffer = new PartitionedOutputBuffer("task-instance-id", new StateMachine<>("bufferState", SCHEDULER, OPEN, TERMINAL_BUFFER_STATES), buffers.withNoMoreBufferIds(), new DataSize(Long.MAX_VALUE, BYTE), () -> new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), "test"), SCHEDULER);
    buffer.registerLifespanCompletionCallback(ignore -> {
    });
    PartitionedOutputOperator.PartitionedOutputFactory operatorFactory;
    if (shouldReplicate) {
        operatorFactory = new PartitionedOutputOperator.PartitionedOutputFactory(buffer, PARTITION_MAX_MEMORY);
        return (PartitionedOutputOperator) operatorFactory.createOutputOperator(0, new PlanNodeId("plan-node-0"), REPLICATION_TYPES, Function.identity(), Optional.of(outputPartitioning), serdeFactory).createOperator(driverContext);
    } else {
        operatorFactory = new PartitionedOutputOperator.PartitionedOutputFactory(buffer, PARTITION_MAX_MEMORY);
        return (PartitionedOutputOperator) operatorFactory.createOutputOperator(0, new PlanNodeId("plan-node-0"), TYPES, Function.identity(), Optional.of(outputPartitioning), serdeFactory).createOperator(driverContext);
    }
}
Also used : PartitionedOutputBuffer(com.facebook.presto.execution.buffer.PartitionedOutputBuffer) SimpleLocalMemoryContext(com.facebook.presto.memory.context.SimpleLocalMemoryContext) PartitionedOutputOperator(com.facebook.presto.operator.repartition.PartitionedOutputOperator) LocalPartitionGenerator(com.facebook.presto.operator.exchange.LocalPartitionGenerator) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) PagesSerdeFactory(com.facebook.presto.execution.buffer.PagesSerdeFactory) OutputBuffers.createInitialEmptyOutputBuffers(com.facebook.presto.execution.buffer.OutputBuffers.createInitialEmptyOutputBuffers) OutputBuffers(com.facebook.presto.execution.buffer.OutputBuffers) BlockEncodingManager(com.facebook.presto.common.block.BlockEncodingManager) DataSize(io.airlift.units.DataSize) OutputPartitioning(com.facebook.presto.sql.planner.OutputPartitioning)

Aggregations

OutputBuffers (com.facebook.presto.execution.buffer.OutputBuffers)11 OutputBuffers.createInitialEmptyOutputBuffers (com.facebook.presto.execution.buffer.OutputBuffers.createInitialEmptyOutputBuffers)9 OutputBufferId (com.facebook.presto.execution.buffer.OutputBuffers.OutputBufferId)5 DataSize (io.airlift.units.DataSize)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)4 Session (com.facebook.presto.Session)3 StageId (com.facebook.presto.execution.StageId)2 PrestoException (com.facebook.presto.spi.PrestoException)2 GENERIC_INTERNAL_ERROR (com.facebook.presto.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR)2 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)2 PlanFragment (com.facebook.presto.sql.planner.PlanFragment)2 SplitSourceFactory (com.facebook.presto.sql.planner.SplitSourceFactory)2 SubPlan (com.facebook.presto.sql.planner.SubPlan)2 PlanFragmentId (com.facebook.presto.sql.planner.plan.PlanFragmentId)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)2 Duration (io.airlift.units.Duration)2 String.format (java.lang.String.format)2