public List<Section> reduceSections(List<Section> sections, int n) {
    if (n >= sections.size() || n < 1) {
      return sections;
    }
    List<Section> newSections = new ArrayList<>(sections);
    while (n < newSections.size()) {
      Integer smallestSection = null;
      double sectionSizeAvg = 0;
      for (int i = 0; i < newSections.size(); i++) {
        sectionSizeAvg += newSections.get(i).sizeEucl();
        if (smallestSection == null
            || newSections.get(smallestSection).sizeEucl() > newSections.get(i).sizeEucl()) {
          smallestSection = i;
        }
      }
      sectionSizeAvg /= newSections.size();
      if (newSections.get(smallestSection).sizeEucl() > sectionSizeAvg * 0.8) {
        return null;
      }

      if (smallestSection == 0) {
        newSections.get(0).concat(newSections.get(1));
        newSections.remove(1);
      } else if (smallestSection == newSections.size() - 1) {
        newSections.get(newSections.size() - 2).concat(newSections.get(newSections.size() - 1));
        newSections.remove(newSections.size() - 1);
      } else if (newSections.get(smallestSection - 1).sizeEucl()
          <= newSections.get(smallestSection + 1).sizeEucl()) {
        newSections.get(smallestSection - 1).concat(newSections.get(smallestSection));
        newSections.remove(newSections.get(smallestSection));
      } else {
        newSections.get(smallestSection).concat(newSections.get(smallestSection + 1));
        newSections.remove(newSections.get(smallestSection + 1));
      }
    }
    return newSections;
  }
reduce the number of sections to n, joining the smallest sections to the smallest adjacent

@param sections
@param n
@return
library-udf/src/main/java/org/apache/iotdb/library/match/PatternExecutor.java