private double interpolate(long t) {
    if (t == source.get(1).time) {
      return source.get(1).value;
    } else if (t == source.get(0).time) {
      return source.get(0).value;
    }
    double ret = Double.NaN;
    switch (interpolator) {
      case "nan":
        break;
      case "ffill":
        if (t >= source.get(1).time) {
          ret = source.get(1).value;
        } else if (t >= source.get(0).time) {
          ret = source.get(0).value;
        }
        break;
      case "bfill":
        if (t <= source.get(0).time) {
          ret = source.get(0).value;
        } else if (t <= source.get(1).time) {
          ret = source.get(1).value;
        }
        break;
      case "linear":
        ret =
            source.get(0).value * (source.get(1).time - t)
                + source.get(1).value * (t - source.get(0).time);
        ret = ret / (source.get(1).time - source.get(0).time);
        break;
      default:
        throw new IllegalArgumentException("Error: Illegal Interpolation Algorithm.");
    }
    return ret;
  }
Interpolation. Transfer given timestamp to interpolated timestamp.
library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/Resampler.java