@Override
  public void terminate(PointCollector collector) throws Exception {
    try {
      if (exact) {
        collector.putDouble(0, statistics.getMedian());
      } else {
        collector.putDouble(0, sketch.query(0.5));
      }
    } catch (NoSuchElementException e) {
      // just ignore it
    }
  }
calculate the exact or approximate median.
library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFMedian.java