Search in sources :

Example 1 with ProcessState

use of com.facebook.presto.operator.WorkProcessor.ProcessState in project presto by prestodb.

the class WindowOperator method pagesIndexToWindowPartitions.

private WorkProcessor<WindowPartition> pagesIndexToWindowPartitions(PagesIndexWithHashStrategies pagesIndexWithHashStrategies) {
    PagesIndex pagesIndex = pagesIndexWithHashStrategies.pagesIndex;
    // pagesIndex contains the full grouped & sorted data for one or more partitions
    windowInfo.addIndex(pagesIndex);
    return WorkProcessor.create(new WorkProcessor.Process<WindowPartition>() {

        int partitionStart;

        @Override
        public ProcessState<WindowPartition> process() {
            if (partitionStart == pagesIndex.getPositionCount()) {
                return ProcessState.finished();
            }
            int partitionEnd = findGroupEnd(pagesIndex, pagesIndexWithHashStrategies.unGroupedPartitionHashStrategy, partitionStart);
            WindowPartition partition = new WindowPartition(pagesIndex, partitionStart, partitionEnd, outputChannels, windowFunctions, pagesIndexWithHashStrategies.peerGroupHashStrategy);
            windowInfo.addPartition(partition);
            partitionStart = partitionEnd;
            return ProcessState.ofResult(partition);
        }
    });
}
Also used : ProcessState(com.facebook.presto.operator.WorkProcessor.ProcessState) WindowPartition(com.facebook.presto.operator.window.WindowPartition)

Example 2 with ProcessState

use of com.facebook.presto.operator.WorkProcessor.ProcessState in project presto by prestodb.

the class MergeSortedPages method pageWithPositions.

private static WorkProcessor<PageWithPosition> pageWithPositions(WorkProcessor<Page> pages, AggregatedMemoryContext aggregatedMemoryContext) {
    return pages.flatMap(page -> {
        LocalMemoryContext memoryContext = aggregatedMemoryContext.newLocalMemoryContext(MergeSortedPages.class.getSimpleName());
        memoryContext.setBytes(page.getRetainedSizeInBytes());
        return WorkProcessor.create(new WorkProcessor.Process<PageWithPosition>() {

            int position;

            @Override
            public ProcessState<PageWithPosition> process() {
                if (position >= page.getPositionCount()) {
                    memoryContext.close();
                    return ProcessState.finished();
                }
                return ProcessState.ofResult(new PageWithPosition(page, position++));
            }
        });
    });
}
Also used : ProcessState(com.facebook.presto.operator.WorkProcessor.ProcessState) LocalMemoryContext(com.facebook.presto.memory.context.LocalMemoryContext) WorkProcessor(com.facebook.presto.operator.WorkProcessor)

Example 3 with ProcessState

use of com.facebook.presto.operator.WorkProcessor.ProcessState in project presto by prestodb.

the class TestWorkProcessor method testYield.

@Test(timeOut = 5000)
public void testYield() {
    SettableFuture<?> future = SettableFuture.create();
    List<ProcessState<Integer>> baseScenario = ImmutableList.of(ProcessState.ofResult(1), ProcessState.ofResult(2), ProcessState.blocked(future), ProcessState.ofResult(3), ProcessState.ofResult(4), ProcessState.finished());
    AtomicBoolean yieldSignal = new AtomicBoolean();
    WorkProcessor<Integer> processor = processorFrom(baseScenario).yielding(yieldSignal::get);
    // no yield, process normally
    assertResult(processor, 1);
    yieldSignal.set(true);
    assertYields(processor);
    // processor should progress since it yielded last time
    assertResult(processor, 2);
    // base scenario future blocks
    assertBlocks(processor);
    assertUnblocks(processor, future);
    // yield signal is still set
    assertYields(processor);
    // continue to process normally
    yieldSignal.set(false);
    assertResult(processor, 3);
    assertResult(processor, 4);
    assertFinishes(processor);
}
Also used : ProcessState(com.facebook.presto.operator.WorkProcessor.ProcessState) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.testng.annotations.Test)

Aggregations

ProcessState (com.facebook.presto.operator.WorkProcessor.ProcessState)3 LocalMemoryContext (com.facebook.presto.memory.context.LocalMemoryContext)1 WorkProcessor (com.facebook.presto.operator.WorkProcessor)1 WindowPartition (com.facebook.presto.operator.window.WindowPartition)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Test (org.testng.annotations.Test)1