@Override
  public void beforeStart(UDFParameters parameters, UDTFConfigurations configurations)
      throws Exception {
    this.k = parameters.getIntOrDefault("k", 1);
    this.dataType = parameters.getDataType(0);
    String methodIn = parameters.getStringOrDefault("method", METHOD_RESERVOIR);
    if ("triangle".equalsIgnoreCase(methodIn)) {
      this.method = Method.TRIANGLE;
    } else if ("isometric".equalsIgnoreCase(methodIn)) {
      this.method = Method.ISOMETRIC;
    } else {
      this.method = Method.RESERVOIR;
    }
    if (this.method == Method.ISOMETRIC || this.method == Method.TRIANGLE) {
      configurations
          .setAccessStrategy(new SlidingSizeWindowAccessStrategy(Integer.MAX_VALUE))
          .setOutputDataType(parameters.getDataType(0));
    } else {
      configurations
          .setAccessStrategy(new RowByRowAccessStrategy())
          .setOutputDataType(parameters.getDataType(0));
      this.samples = new Pair[this.k];
      this.random = new Random();
    }
  }
This function samples data by pool sampling.
library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFSample.java