@Override
  public TsBlock next() throws Exception {
    TsBlock block = child.nextWithTimer();
    if (block == null) {
      return null;
    }

    checkArgument(
        outputColumnCount == block.getValueColumnCount(),
        "outputColumnCount is not equal to value column count of child operator's TsBlock");

    // current TsBlock's first row is not same group as the last row of previous TsBlock
    // we need to call reset the fill
    if (lastRow != null && groupKeyComparator.compare(lastRow, new SortKey(block, 0)) != 0) {
      resetFill();
    }

    // update lastRow
    this.lastRow = new SortKey(block, block.getPositionCount() - 1);
    // all rows in current TsBlock belong to same group
    if (lastRow.rowIndex == 0 || groupKeyComparator.compare(new SortKey(block, 0), lastRow) == 0) {
      Column[] valueColumns = new Column[outputColumnCount];

      for (int i = 0; i < outputColumnCount; i++) {
        valueColumns[i] = fillArray[i].fill(block.getColumn(helperColumnIndex), block.getColumn(i));
      }
      return TsBlock.wrapBlocksWithoutCopy(
          block.getPositionCount(), block.getTimeColumn(), valueColumns);
    } else {
      // otherwise, we need to split the current TsBlock and reset the fill between different groups
      resultBuilder.reset();
      SortKey currentGroupKey = new SortKey(block, 0);
      for (int i = 1; i <= lastRow.rowIndex; i++) {
        SortKey nextGroupKey = new SortKey(block, i);

        if (groupKeyComparator.compare(currentGroupKey, nextGroupKey) != 0) {
          // don't belong to same group, need to split here and build result for current group, then
          // reset the fill
          buildResultForCurrentGroup(block, currentGroupKey.rowIndex, i - 1);
          resetFill();
          currentGroupKey = nextGroupKey;
        }
      }

      // take care of the last group
      // we don't need to reset the fill, because we can only decide whether to reset once we get
      // next TsBlock
      buildResultForCurrentGroup(block, currentGroupKey.rowIndex, lastRow.rowIndex);

      return resultBuilder.build(block.getTimeColumn());
    }
  }
Used for table previous fill with group.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/PreviousFillWithGroupOperator.java