@Override
  @SuppressWarnings("javabugs:S6320")
  public void transform(RowWindow rowWindow, PointCollector collector) throws Exception {
    // equal-distance sampling
    int n = rowWindow.windowSize();

    if (this.k < n) {
      if (this.method == Method.TRIANGLE) {
        List<Pair<Long, Double>> input = new LinkedList<>();
        for (int i = 0; i < n; i++) {
          Row row = rowWindow.getRow(i);
          long time = row.getTime();
          double data = Util.getValueAsDouble(row);
          input.add(Pair.of(time, data));
        }
        if (k > 2) {
          // The first and last element will always be sampled so the buckets is k - 2
          List<Pair<Long, Double>> output = LTThreeBuckets.sorted(input, k - 2);
          for (Pair<Long, Double> p : output) {
            switch (dataType) {
              case INT32:
                collector.putInt(p.getLeft(), p.getRight().intValue());
                break;
              case INT64:
                collector.putLong(p.getLeft(), p.getRight().longValue());
                break;
              case FLOAT:
                collector.putFloat(p.getLeft(), p.getRight().floatValue());
                break;
              case DOUBLE:
                collector.putDouble(p.getLeft(), p.getRight());
                break;
              case TIMESTAMP:
              case DATE:
              case BLOB:
              case BOOLEAN:
              case STRING:
              case TEXT:
              default:
                throw new NoNumberException();
            }
          }
        } else { // For corner case of k == 1 and k == 2
          Row row = rowWindow.getRow(0); // Put first element
          Util.putValue(collector, dataType, row.getTime(), Util.getValueAsObject(row));
          if (k == 2) {
            row = rowWindow.getRow(n - 1); // Put last element
            Util.putValue(collector, dataType, row.getTime(), Util.getValueAsObject(row));
          }
        }
      } else { // Method.ISOMETRIC
        for (long i = 0; i < this.k; i++) {
          long j = Math.floorDiv(i * n, (long) k); // avoid intermediate result overflows
          Row row = rowWindow.getRow((int) j);
          Util.putValue(collector, dataType, row.getTime(), Util.getValueAsObject(row));
        }
      }
    } else { // when k is larger than series length, output all points
      RowIterator iterator = rowWindow.getRowIterator();
      while (iterator.hasNextRow()) {
        Row row = iterator.next();
        Util.putValue(collector, dataType, row.getTime(), Util.getValueAsObject(row));
      }
    }
  }
This function samples data by pool sampling.
library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFSample.java