示例#1
0
  private Page extractOutput() {
    // INVARIANT: pagesIndex contains the full grouped & sorted data for one or more partitions

    // 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,
                frameInfo,
                peerGroupHashStrategy);
      }

      partition.processNextRow(pageBuilder);
    }

    Page page = pageBuilder.build();
    pageBuilder.reset();
    return page;
  }