Search in sources :

Example 1 with WindowPartition

use of com.facebook.presto.operator.window.WindowPartition 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 WindowPartition

use of com.facebook.presto.operator.window.WindowPartition in project presto by prestodb.

the class WindowOperator method extractOutput.

private Page extractOutput() {
    // Iterate through the positions sequentially until we have one full page
    while (!pageBuilder.isFull()) {
        if (partition == null || !partition.hasNext()) {
            int partitionStart = partition == null ? 0 : partition.getPartitionEnd();
            if (partitionStart >= pagesIndex.getPositionCount()) {
                // Finished all of the partitions in the current pagesIndex
                partition = null;
                pagesIndex.clear();
                // Try to extract more partitions from the pendingInput
                if (pendingInput != null && processPendingInput()) {
                    partitionStart = 0;
                } else if (state == State.FINISHING) {
                    state = State.FINISHED;
                    // Output the remaining page if we have anything buffered
                    if (!pageBuilder.isEmpty()) {
                        Page page = pageBuilder.build();
                        pageBuilder.reset();
                        return page;
                    }
                    return null;
                } else {
                    state = State.NEEDS_INPUT;
                    return null;
                }
            }
            int partitionEnd = findGroupEnd(pagesIndex, unGroupedPartitionHashStrategy, partitionStart);
            partition = new WindowPartition(pagesIndex, partitionStart, partitionEnd, outputChannels, windowFunctions, peerGroupHashStrategy);
        }
        partition.processNextRow(pageBuilder);
    }
    Page page = pageBuilder.build();
    pageBuilder.reset();
    return page;
}
Also used : WindowPartition(com.facebook.presto.operator.window.WindowPartition) Page(com.facebook.presto.spi.Page)

Aggregations

WindowPartition (com.facebook.presto.operator.window.WindowPartition)2 ProcessState (com.facebook.presto.operator.WorkProcessor.ProcessState)1 Page (com.facebook.presto.spi.Page)1