@Override
  public void terminate(PointCollector pc) throws Exception {
    if (samples != null) { // for pool sampling only
      int m = Math.min(num, k);
      Arrays.sort(samples, 0, m);
      for (int i = 0; i < m; i++) {
        Pair<Long, Object> p = samples[i];
        Util.putValue(pc, dataType, p.getLeft(), p.getRight());
      }
    }
  }
This function samples data by pool sampling.
library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFSample.java