@Override
  public void terminate(PointCollector collector) throws Exception {
    long[] ts = timestamp.stream().mapToLong(Long::valueOf).toArray();
    double[] v = value.stream().mapToDouble(Double::valueOf).toArray();
    List<double[]> seg = new ArrayList<>();
    if (method.equals(METHOD_BOTTOM_UP)) {
      List<double[]> temp = Segment.bottomUp(v, maxError);
      seg.addAll(temp);
    } else if (method.equals("swab")) { // haven't tested yet
      seg = Segment.swabAlg(v, maxError, windowSize);
    }
    ArrayList<double[]> res = new ArrayList<>();
    for (double[] doubles : seg) {
      res.add(Segment.approximatedSegment(doubles));
    }
    int index = 0;
    if (output.equals(OUTPUT_FIRST)) {
      for (double[] doubles : res) {
        collector.putDouble(ts[index], doubles[0]);
        index += doubles.length;
      }
    } else if (output.equals("all")) {
      for (double[] doubles : res) {
        for (double aDouble : doubles) {
          collector.putDouble(ts[index], aDouble);
          index++;
        }
      }
    }
  }
This function segment input series into linear parts.
library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFSegment.java