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);
}
});
}
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++));
}
});
});
}
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);
}
Aggregations