@Override
  public void transform(RowWindow rowWindow, PointCollector collector) throws Exception {
    DoubleArrayList a = new DoubleArrayList();
    DoubleArrayList b = new DoubleArrayList();
    int n = rowWindow.windowSize();
    for (int i = 0; i < n; i++) {
      Row row = rowWindow.getRow(i);
      if (row.isNull(0) || row.isNull(1)) {
        continue;
      }
      a.add(Util.getValueAsDouble(row, 0));
      b.add(Util.getValueAsDouble(row, 1));
    }
    m = a.size();
    dp = new double[m + 1][m + 1];
    for (int i = 1; i <= m; i++) {
      dp[0][i] = dp[i][0] = Double.MAX_VALUE;
    }
    dp[0][0] = 0;
    for (int i = 1; i <= m; i++) {
      for (int j = 1; j <= m; j++) {
        dp[i][j] =
            Math.abs(a.get(i - 1) - b.get(j - 1))
                + Math.min(Math.min(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]);
      }
    }
  }
This function calculates DTW distance between two input series.
library-udf/src/main/java/org/apache/iotdb/library/dmatch/UDAFDtw.java