public static Map<PartialPath, List<AggregationDescriptor>> groupAlignedAggregations(
      Map<PartialPath, List<AggregationDescriptor>> pathToAggregations) {
    Map<PartialPath, List<AggregationDescriptor>> result = new HashMap<>();
    Map<String, List<MeasurementPath>> deviceToAlignedPathsMap = new HashMap<>();
    for (PartialPath path : pathToAggregations.keySet()) {
      MeasurementPath measurementPath = (MeasurementPath) path;
      if (!measurementPath.isUnderAlignedEntity()) {
        result
            .computeIfAbsent(measurementPath, key -> new ArrayList<>())
            .addAll(pathToAggregations.get(path));
      } else {
        deviceToAlignedPathsMap
            .computeIfAbsent(path.getIDeviceID().toString(), key -> new ArrayList<>())
            .add(measurementPath);
      }
    }
    for (Map.Entry<String, List<MeasurementPath>> alignedPathEntry :
        deviceToAlignedPathsMap.entrySet()) {
      List<MeasurementPath> measurementPathList = alignedPathEntry.getValue();
      AlignedPath alignedPath = null;
      List<AggregationDescriptor> aggregationDescriptorList = new ArrayList<>();
      for (int i = 0; i < measurementPathList.size(); i++) {
        MeasurementPath measurementPath = measurementPathList.get(i);
        if (i == 0) {
          alignedPath = new AlignedPath(measurementPath);
        } else {
          alignedPath.addMeasurement(measurementPath);
        }
        aggregationDescriptorList.addAll(pathToAggregations.get(measurementPath));
      }
      result.put(alignedPath, aggregationDescriptorList);
    }
    return result;
  }
Group all the series under an aligned entity into one AlignedPath and remove these series from
pathToAggrIndexesMap. For example, input map: d1[s1] -> [1, 3], d1[s2] -> [2,4], will return
d1[s1,s2], [[1,3], [2,4]]
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/utils/MetaUtils.java