private TsBlock buildResult(Iterator<Integer> groupIds) {
    pageBuilder.reset();

    while (!pageBuilder.isFull() && groupIds.hasNext()) {
      int groupId = groupIds.next();

      groupByHash.appendValuesTo(groupId, pageBuilder);

      pageBuilder.declarePosition();
      for (int i = 0; i < groupedAggregators.size(); i++) {
        GroupedAggregator groupedAggregator = groupedAggregators.get(i);
        ColumnBuilder output = pageBuilder.getColumnBuilder(groupByChannels.length + i);
        groupedAggregator.evaluate(groupId, output);
      }
    }

    return TsBlock.wrapBlocksWithoutCopy(
        pageBuilder.getPositionCount(),
        new RunLengthEncodedColumn(
            TableScanOperator.TIME_COLUMN_TEMPLATE, pageBuilder.getPositionCount()),
        Arrays.stream(pageBuilder.getValueColumnBuilders())
            .map(ColumnBuilder::build)
            .toArray(Column[]::new));
  }
building hash sorted results requires memory for sorting group IDs. This method returns size of
that memory requirement.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/aggregation/grouped/builder/InMemoryHashAggregationBuilder.java