@Override
  public void terminate(PointCollector collector) throws Exception {
    if (count > 0) { // calculate R only when there is more than 1 point
      double pearson =
          (count * sumXY - sumX * sumY)
              / Math.sqrt(count * sumXX - sumX * sumX)
              / Math.sqrt(count * sumYY - sumY * sumY);
      collector.putDouble(0, pearson);
    } else {
      collector.putDouble(0, Double.NaN);
    }
  }
This function calculates Pearson's r between two input series.
library-udf/src/main/java/org/apache/iotdb/library/dmatch/UDAFPearson.java