presto-main/src/main/java/io/prestosql/operator/project/MergingPageOutput.java/MergingPageOutput/getOutput
class MergingPageOutput:    @Nullable
    public Page getOutput()
    {
        if (!outputQueue.isEmpty()) {
            return outputQueue.poll();
        }

        while (currentInput != null) {
            if (!currentInput.hasNext()) {
                currentInput = null;
                break;
            }

            if (!outputQueue.isEmpty()) {
                break;
            }

            Optional<Page> next = currentInput.next();
            if (next.isPresent()) {
                process(next.get());
            }
            else {
                break;
            }
        }

        if (currentInput == null && finishing) {
            flush();
        }

        return outputQueue.poll();
    }