@Override
  public void terminate(PointCollector collector) throws Exception {
    if (count > 0) { // calculate Cov only when there is more than 1 point
      double cov = (sumXY - sumX * sumY / count) / count;
      collector.putDouble(0, cov);
    } else {
      collector.putDouble(0, Double.NaN);
    }
  }
This function calculates Covariance between two input series.
library-udf/src/main/java/org/apache/iotdb/library/dmatch/UDAFCov.java