You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ro...@apache.org on 2023/06/25 16:39:47 UTC

[iotdb] branch master updated: UDF: fix bugs & smells reported by SonarCloud (org.apache.iotdb.library) (#10289)

This is an automated email from the ASF dual-hosted git repository.

rong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 1e35786c7e7 UDF: fix bugs & smells reported by SonarCloud (org.apache.iotdb.library) (#10289)
1e35786c7e7 is described below

commit 1e35786c7e7e9005509481a48d123ce83f8b0f5c
Author: 马子坤 <55...@users.noreply.github.com>
AuthorDate: Mon Jun 26 00:39:40 2023 +0800

    UDF: fix bugs & smells reported by SonarCloud (org.apache.iotdb.library) (#10289)
    
    Co-authored-by: Steve Yurong Su <ro...@apache.org>
---
 .../org/apache/iotdb/library/anomaly/UDTFIQR.java  |  21 +-
 .../apache/iotdb/library/anomaly/UDTFKSigma.java   |  30 +--
 .../org/apache/iotdb/library/anomaly/UDTFLOF.java  |  18 +-
 .../apache/iotdb/library/anomaly/UDTFOutlier.java  |  14 +-
 .../apache/iotdb/library/anomaly/UDTFRange.java    |   7 +-
 .../iotdb/library/anomaly/UDTFTwoSidedFilter.java  |   7 +-
 .../iotdb/library/anomaly/util/MissDetector.java   |   8 +-
 .../library/anomaly/util/StreamMissDetector.java   |  24 ++-
 .../iotdb/library/anomaly/util/WindowDetect.java   |   6 +-
 .../org/apache/iotdb/library/dlearn/UDTFAR.java    |  19 +-
 .../org/apache/iotdb/library/dmatch/UDAFCov.java   |  20 +-
 .../apache/iotdb/library/dmatch/UDAFPearson.java   |  36 ++--
 .../org/apache/iotdb/library/dmatch/UDTFXCorr.java |   7 +-
 .../library/dmatch/util/CrossCorrelation.java      |  13 +-
 .../iotdb/library/dprofile/UDAFIntegral.java       |   5 +-
 .../iotdb/library/dprofile/UDAFIntegralAvg.java    |   2 +-
 .../org/apache/iotdb/library/dprofile/UDAFMad.java |   2 +-
 .../apache/iotdb/library/dprofile/UDAFMedian.java  |   2 +-
 .../iotdb/library/dprofile/UDAFPercentile.java     |  14 +-
 .../apache/iotdb/library/dprofile/UDAFPeriod.java  |  28 +--
 .../iotdb/library/dprofile/UDAFQuantile.java       |  19 +-
 .../apache/iotdb/library/dprofile/UDAFSpread.java  |  36 ++--
 .../org/apache/iotdb/library/dprofile/UDTFACF.java |   5 +-
 .../iotdb/library/dprofile/UDTFDistinct.java       |  12 ++
 .../iotdb/library/dprofile/UDTFHistogram.java      |   1 +
 .../apache/iotdb/library/dprofile/UDTFMinMax.java  |  20 +-
 .../apache/iotdb/library/dprofile/UDTFMvAvg.java   |   6 +-
 .../apache/iotdb/library/dprofile/UDTFPACF.java    |   1 +
 .../org/apache/iotdb/library/dprofile/UDTFQLB.java |   1 +
 .../iotdb/library/dprofile/UDTFResample.java       |  12 +-
 .../apache/iotdb/library/dprofile/UDTFSample.java  |  19 +-
 .../apache/iotdb/library/dprofile/UDTFSegment.java |  34 +--
 .../apache/iotdb/library/dprofile/UDTFSpline.java  |   2 +-
 .../apache/iotdb/library/dprofile/UDTFZScore.java  |  20 +-
 .../library/dprofile/util/CrossCorrelation.java    |  14 +-
 .../dprofile/util/ExactOrderStatistics.java        | 139 ++++++------
 .../iotdb/library/dprofile/util/GKArray.java       |  22 +-
 .../library/dprofile/util/HeapLongKLLSketch.java   | 237 ++++++++++-----------
 .../dprofile/util/KLLSketchForQuantile.java        | 155 +++++++-------
 .../iotdb/library/dprofile/util/MADSketch.java     | 157 +++++++-------
 .../apache/iotdb/library/dprofile/util/Mad.java    |   9 +-
 .../iotdb/library/dprofile/util/MaxSelector.java   |   3 +-
 .../iotdb/library/dprofile/util/Resampler.java     |  17 +-
 .../iotdb/library/dprofile/util/Segment.java       | 141 ++++++------
 .../iotdb/library/dprofile/util/YuleWalker.java    |  11 +-
 .../iotdb/library/dquality/UDTFCompleteness.java   |   2 +-
 .../iotdb/library/dquality/UDTFConsistency.java    |   2 +-
 .../iotdb/library/dquality/UDTFTimeliness.java     |   2 +-
 .../iotdb/library/dquality/UDTFValidity.java       |   2 +-
 .../library/dquality/util/TimeSeriesQuality.java   |  21 +-
 .../iotdb/library/drepair/UDTFTimestampRepair.java |   5 +-
 .../iotdb/library/drepair/UDTFValueFill.java       |   6 +-
 .../iotdb/library/drepair/UDTFValueRepair.java     |   3 +-
 .../apache/iotdb/library/drepair/util/ARFill.java  |  34 ++-
 .../iotdb/library/drepair/util/LikelihoodFill.java |  15 +-
 .../iotdb/library/drepair/util/LinearFill.java     |   1 +
 .../iotdb/library/drepair/util/LsGreedy.java       |  12 +-
 .../apache/iotdb/library/drepair/util/MAFill.java  |  21 +-
 .../iotdb/library/drepair/util/MeanFill.java       |   1 +
 .../iotdb/library/drepair/util/PreviousFill.java   |   1 +
 .../apache/iotdb/library/drepair/util/Screen.java  |   4 +-
 .../iotdb/library/drepair/util/ScreenFill.java     |  30 +--
 .../library/drepair/util/TimestampInterval.java    |  13 +-
 .../library/drepair/util/TimestampRepair.java      |  56 ++---
 .../iotdb/library/drepair/util/ValueFill.java      |  21 +-
 .../iotdb/library/drepair/util/ValueRepair.java    |  11 +-
 .../apache/iotdb/library/frequency/UDTFDWT.java    |   1 +
 .../apache/iotdb/library/frequency/UDTFDeconv.java |  18 +-
 .../apache/iotdb/library/frequency/UDTFFFT.java    |   7 +-
 .../iotdb/library/frequency/UDTFHighPass.java      |   8 +-
 .../apache/iotdb/library/frequency/UDTFIDWT.java   |   1 +
 .../apache/iotdb/library/frequency/UDTFIFFT.java   |  11 +-
 .../iotdb/library/frequency/UDTFLowPass.java       |   8 +-
 .../iotdb/library/frequency/util/DWTUtil.java      |  12 +-
 .../iotdb/library/frequency/util/FFTUtil.java      |  12 +-
 .../library/series/UDTFConsecutiveWindows.java     |   4 +-
 .../iotdb/library/series/util/ConsecutiveUtil.java |  18 +-
 .../iotdb/library/util/BooleanCircularQueue.java   |  31 +--
 .../apache/iotdb/library/util/CircularQueue.java   |  29 +--
 .../iotdb/library/util/DoubleCircularQueue.java    |  31 +--
 .../iotdb/library/util/LinearRegression.java       |  15 +-
 .../iotdb/library/util/LongCircularQueue.java      |  35 +--
 .../iotdb/library/util/NoNumberException.java      |   1 +
 .../java/org/apache/iotdb/library/util/Util.java   |  63 +++---
 84 files changed, 1011 insertions(+), 933 deletions(-)

diff --git a/library-udf/src/main/java/org/apache/iotdb/library/anomaly/UDTFIQR.java b/library-udf/src/main/java/org/apache/iotdb/library/anomaly/UDTFIQR.java
index cdb8cd0bd92..ce13cd1296e 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/anomaly/UDTFIQR.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/anomaly/UDTFIQR.java
@@ -40,19 +40,24 @@ Stream swap require user to provide Q1 and Q3, while global swap does not.
 public class UDTFIQR implements UDTF {
   ArrayList<Double> value = new ArrayList<>();
   ArrayList<Long> timestamp = new ArrayList<>();
-  String compute = "batch";
+  static final String BATCH_COMPUTE = "batch";
+  static final String STREAM_COMPUTE = "stream";
+  String compute = BATCH_COMPUTE;
   double q1 = 0.0d;
   double q3 = 0.0d;
   double iqr = 0.0d;
 
+  @Override
   public void validate(UDFParameterValidator validator) throws Exception {
     validator
         .validateInputSeriesNumber(1)
         .validateInputSeriesDataType(0, Type.INT32, Type.INT64, Type.FLOAT, Type.DOUBLE)
         .validate(
-            x -> ((String) x).equalsIgnoreCase("batch") || ((String) x).equalsIgnoreCase("stream"),
+            x ->
+                ((String) x).equalsIgnoreCase(BATCH_COMPUTE)
+                    || ((String) x).equalsIgnoreCase(STREAM_COMPUTE),
             "Parameter \"compute\" is illegal. Please use \"batch\" (for default) or \"stream\".",
-            validator.getParameters().getStringOrDefault("compute", "batch"))
+            validator.getParameters().getStringOrDefault("compute", BATCH_COMPUTE))
         .validate(
             params -> (double) params[0] < (double) params[1],
             "parameter $q1$ should be smaller than $q3$",
@@ -69,8 +74,8 @@ public class UDTFIQR implements UDTF {
     q3 = 0.0d;
     iqr = 0.0d;
     configurations.setAccessStrategy(new RowByRowAccessStrategy()).setOutputDataType(Type.DOUBLE);
-    compute = parameters.getStringOrDefault("compute", "batch");
-    if (compute.equalsIgnoreCase("stream")) {
+    compute = parameters.getStringOrDefault("compute", BATCH_COMPUTE);
+    if (compute.equalsIgnoreCase(STREAM_COMPUTE)) {
       q1 = parameters.getDouble("q1");
       q3 = parameters.getDouble("q3");
       iqr = q3 - q1;
@@ -79,12 +84,12 @@ public class UDTFIQR implements UDTF {
 
   @Override
   public void transform(Row row, PointCollector collector) throws Exception {
-    if (compute.equalsIgnoreCase("stream") && q3 > q1) {
+    if (compute.equalsIgnoreCase(STREAM_COMPUTE) && q3 > q1) {
       double v = Util.getValueAsDouble(row);
       if (v < q1 - 1.5 * iqr || v > q3 + 1.5 * iqr) {
         collector.putDouble(row.getTime(), v);
       }
-    } else if (compute.equalsIgnoreCase("batch")) {
+    } else if (compute.equalsIgnoreCase(BATCH_COMPUTE)) {
       double v = Util.getValueAsDouble(row);
       value.add(v);
       timestamp.add(row.getTime());
@@ -93,7 +98,7 @@ public class UDTFIQR implements UDTF {
 
   @Override
   public void terminate(PointCollector collector) throws Exception {
-    if (compute.equalsIgnoreCase("batch")) {
+    if (compute.equalsIgnoreCase(BATCH_COMPUTE)) {
       q1 = Quantiles.quartiles().index(1).compute(value);
       q3 = Quantiles.quartiles().index(3).compute(value);
       iqr = q3 - q1;
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/anomaly/UDTFKSigma.java b/library-udf/src/main/java/org/apache/iotdb/library/anomaly/UDTFKSigma.java
index e5544419342..beab9bb3227 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/anomaly/UDTFKSigma.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/anomaly/UDTFKSigma.java
@@ -34,7 +34,7 @@ import org.apache.iotdb.udf.api.type.Type;
 /** This function detects outliers which lies over average +/- k * sigma. */
 public class UDTFKSigma implements UDTF {
   private double mean = 0.0;
-  private double var = 0.0;
+  private double variance = 0.0;
   private double sumX2 = 0.0;
   private double sumX1 = 0.0;
   private double multipleK;
@@ -77,7 +77,7 @@ public class UDTFKSigma implements UDTF {
     long timestamp = row.getTime();
     if (Double.isFinite(value) && !Double.isNaN(value)) {
       if (v.isFull()) {
-        double frontValue = Double.parseDouble(v.pop().toString());
+        final double frontValue = Double.parseDouble(v.pop().toString());
         switch (dataType) {
           case INT32:
             v.push(row.getInt(0));
@@ -91,15 +91,17 @@ public class UDTFKSigma implements UDTF {
           case FLOAT:
             v.push(row.getFloat(0));
             break;
+          default:
+            break;
         }
         t.pop();
         t.push(timestamp);
         this.sumX1 = this.sumX1 - frontValue + value;
         this.sumX2 = this.sumX2 - frontValue * frontValue + value * value;
         this.mean = this.sumX1 / v.getSize();
-        this.var = this.sumX2 / v.getSize() - this.mean * this.mean;
+        this.variance = this.sumX2 / v.getSize() - this.mean * this.mean;
         if (Math.abs(value - mean)
-            > multipleK * Math.sqrt(this.var * v.getSize() / (v.getSize() - 1))) {
+            > multipleK * Math.sqrt(this.variance * v.getSize() / (v.getSize() - 1))) {
           Util.putValue(collector, dataType, timestamp, Util.getValueAsObject(row));
         }
       } else {
@@ -116,19 +118,21 @@ public class UDTFKSigma implements UDTF {
           case FLOAT:
             v.push(row.getFloat(0));
             break;
+          default:
+            break;
         }
         t.push(timestamp);
         this.sumX1 = this.sumX1 + value;
         this.sumX2 = this.sumX2 + value * value;
         this.mean = this.sumX1 / v.getSize();
-        this.var = this.sumX2 / v.getSize() - this.mean * this.mean;
+        this.variance = this.sumX2 / v.getSize() - this.mean * this.mean;
         if (v.getSize() == this.windowSize) {
-          double stddev = Math.sqrt(this.var * v.getSize() / (v.getSize() - 1));
+          double stddev = Math.sqrt(this.variance * v.getSize() / (v.getSize() - 1));
           for (int i = 0; i < v.getSize(); i++) {
-            Object v = this.v.get(i);
+            Object vi = this.v.get(i);
             timestamp = this.t.get(i);
-            if (Math.abs(Double.parseDouble(v.toString()) - mean) > multipleK * stddev) {
-              Util.putValue(collector, dataType, timestamp, v);
+            if (Math.abs(Double.parseDouble(vi.toString()) - mean) > multipleK * stddev) {
+              Util.putValue(collector, dataType, timestamp, vi);
             }
           }
         }
@@ -139,12 +143,12 @@ public class UDTFKSigma implements UDTF {
   @Override
   public void terminate(PointCollector collector) throws Exception {
     if (!v.isFull() && v.getSize() > 1) {
-      double stddev = Math.sqrt(this.var * v.getSize() / (v.getSize() - 1));
+      double stddev = Math.sqrt(this.variance * v.getSize() / (v.getSize() - 1));
       for (int i = 0; i < v.getSize(); i++) {
-        Object v = this.v.get(i);
+        Object vi = this.v.get(i);
         long timestamp = this.t.get(i);
-        if (Math.abs(Double.parseDouble(v.toString()) - mean) > multipleK * stddev) {
-          Util.putValue(collector, dataType, timestamp, v);
+        if (Math.abs(Double.parseDouble(vi.toString()) - mean) > multipleK * stddev) {
+          Util.putValue(collector, dataType, timestamp, vi);
         }
       }
     }
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/anomaly/UDTFLOF.java b/library-udf/src/main/java/org/apache/iotdb/library/anomaly/UDTFLOF.java
index d845e8e0611..5e9284a5ca0 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/anomaly/UDTFLOF.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/anomaly/UDTFLOF.java
@@ -27,14 +27,15 @@ import org.apache.iotdb.udf.api.customizer.config.UDTFConfigurations;
 import org.apache.iotdb.udf.api.customizer.parameter.UDFParameterValidator;
 import org.apache.iotdb.udf.api.customizer.parameter.UDFParameters;
 import org.apache.iotdb.udf.api.customizer.strategy.SlidingSizeWindowAccessStrategy;
+import org.apache.iotdb.udf.api.exception.UDFException;
 import org.apache.iotdb.udf.api.type.Type;
 
 /** This function is used to detect density anomaly of time series. */
 public class UDTFLOF implements UDTF {
-  private double threshold;
   private int multipleK;
   private int dim;
-  private String method = "default";
+  private static final String DEFAULT_METHOD = "default";
+  private String method = DEFAULT_METHOD;
   private int window;
 
   int partition(Double[][] a, int left, int right) {
@@ -94,7 +95,6 @@ public class UDTFLOF implements UDTF {
 
   public Double[] findKthPoint(Double[][] knn, Double[] x, int length) {
     int index;
-    double minDist = dist(knn[0], x);
     Double[][] d = new Double[length][2];
     for (int i = 0; i < length; i++) {
       d[i][0] = (double) i;
@@ -130,13 +130,13 @@ public class UDTFLOF implements UDTF {
         .setOutputDataType(Type.DOUBLE);
     this.multipleK = parameters.getIntOrDefault("k", 3);
     this.dim = parameters.getChildExpressionsSize();
-    this.method = parameters.getStringOrDefault("method", "default");
+    this.method = parameters.getStringOrDefault("method", DEFAULT_METHOD);
     this.window = parameters.getIntOrDefault("window", 5);
   }
 
   @Override
   public void transform(RowWindow rowWindow, PointCollector collector) throws Exception {
-    if (this.method.equals("default")) {
+    if (this.method.equals(DEFAULT_METHOD)) {
       int size = rowWindow.windowSize();
       Double[][] knn = new Double[size][dim];
       long[] timestamp = new long[size];
@@ -163,7 +163,7 @@ public class UDTFLOF implements UDTF {
             lof[m] = getLOF(knn, knn[m], size);
             collector.putDouble(timestamp[m], lof[m]);
           } catch (Exception e) {
-            throw new Exception("Fail to get LOF " + m, e);
+            throw new UDFException("Fail to get LOF " + m, e);
           }
         }
       }
@@ -201,7 +201,7 @@ public class UDTFLOF implements UDTF {
               lof[m] = getLOF(knn, knn[m], size);
               collector.putDouble(timestamp[m], lof[m]);
             } catch (Exception e) {
-              throw new Exception("Fail to get LOF " + m, e);
+              throw new UDFException("Fail to get LOF " + m, e);
             }
           }
         }
@@ -210,5 +210,7 @@ public class UDTFLOF implements UDTF {
   }
 
   @Override
-  public void terminate(PointCollector collector) throws Exception {}
+  public void terminate(PointCollector collector)
+      throws Exception { // default implementation ignored
+  }
 }
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/anomaly/UDTFOutlier.java b/library-udf/src/main/java/org/apache/iotdb/library/anomaly/UDTFOutlier.java
index a3c3c13a7e8..bf80003f98e 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/anomaly/UDTFOutlier.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/anomaly/UDTFOutlier.java
@@ -67,7 +67,9 @@ public class UDTFOutlier implements UDTF {
   @Override
   public void transform(Row row, PointCollector collector) throws Exception {
     if (!row.isNull(0)) {
-      if (i >= w && (i - w) % s == 0) detect();
+      if (i >= w && (i - w) % s == 0) {
+        detect();
+      }
 
       if (i >= w) {
         currentValueWindow.remove(0);
@@ -90,10 +92,14 @@ public class UDTFOutlier implements UDTF {
   private void detect() {
     for (int j = 0; j < w; j++) {
       int cnt = 0;
-      for (int l = 0; l < w; l++)
-        if (Math.abs(currentValueWindow.get(j) - currentValueWindow.get(l)) <= this.r) cnt++;
-      if (cnt < this.k && !outliers.keySet().contains(currentTimeWindow.get(j)))
+      for (int l = 0; l < w; l++) {
+        if (Math.abs(currentValueWindow.get(j) - currentValueWindow.get(l)) <= this.r) {
+          cnt++;
+        }
+      }
+      if (cnt < this.k && !outliers.keySet().contains(currentTimeWindow.get(j))) {
         outliers.put(currentTimeWindow.get(j), currentValueWindow.get(j));
+      }
     }
   }
 }
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/anomaly/UDTFRange.java b/library-udf/src/main/java/org/apache/iotdb/library/anomaly/UDTFRange.java
index 46468cf2612..fefbbbf7c24 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/anomaly/UDTFRange.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/anomaly/UDTFRange.java
@@ -27,6 +27,7 @@ import org.apache.iotdb.udf.api.customizer.config.UDTFConfigurations;
 import org.apache.iotdb.udf.api.customizer.parameter.UDFParameterValidator;
 import org.apache.iotdb.udf.api.customizer.parameter.UDFParameters;
 import org.apache.iotdb.udf.api.customizer.strategy.RowByRowAccessStrategy;
+import org.apache.iotdb.udf.api.exception.UDFException;
 import org.apache.iotdb.udf.api.type.Type;
 
 /** This function is used to detect range anomaly of time series. */
@@ -87,10 +88,12 @@ public class UDTFRange implements UDTF {
         }
         break;
       default:
-        throw new Exception("No such kind of data type.");
+        throw new UDFException("No such kind of data type.");
     }
   }
 
   @Override
-  public void terminate(PointCollector collector) throws Exception {}
+  public void terminate(PointCollector collector)
+      throws Exception { // default implementation ignored
+  }
 }
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/anomaly/UDTFTwoSidedFilter.java b/library-udf/src/main/java/org/apache/iotdb/library/anomaly/UDTFTwoSidedFilter.java
index c02be6a3640..018f8c95a42 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/anomaly/UDTFTwoSidedFilter.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/anomaly/UDTFTwoSidedFilter.java
@@ -27,6 +27,7 @@ import org.apache.iotdb.udf.api.customizer.config.UDTFConfigurations;
 import org.apache.iotdb.udf.api.customizer.parameter.UDFParameterValidator;
 import org.apache.iotdb.udf.api.customizer.parameter.UDFParameters;
 import org.apache.iotdb.udf.api.customizer.strategy.SlidingSizeWindowAccessStrategy;
+import org.apache.iotdb.udf.api.exception.UDFException;
 import org.apache.iotdb.udf.api.type.Type;
 
 /**
@@ -81,10 +82,12 @@ public class UDTFTwoSidedFilter implements UDTF {
         }
         break;
       default:
-        throw new Exception("No such kind of data type.");
+        throw new UDFException("No such kind of data type.");
     }
   }
 
   @Override
-  public void terminate(PointCollector collector) throws Exception {}
+  public void terminate(PointCollector collector)
+      throws Exception { // default implementation ignored
+  }
 }
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/anomaly/util/MissDetector.java b/library-udf/src/main/java/org/apache/iotdb/library/anomaly/util/MissDetector.java
index 771fc8f7643..0141ae01ae5 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/anomaly/util/MissDetector.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/anomaly/util/MissDetector.java
@@ -68,7 +68,7 @@ public class MissDetector {
     SimpleRegression regression = new SimpleRegression();
     while (i + windowSize < getLen()) {
       for (int j = 0; j < windowSize; j++) {
-        data[j][0] = getTime().get(i + j) - startTime;
+        data[j][0] = (double) getTime().get(i + j) - startTime;
         data[j][1] = getValue().get(i + j);
       }
       regression.addData(data);
@@ -91,19 +91,19 @@ public class MissDetector {
     int bindex = start;
     while (bindex > 0) {
       bindex--;
-      regression.addData(getTime().get(bindex) - startTime, getValue().get(bindex));
+      regression.addData((double) getTime().get(bindex) - startTime, getValue().get(bindex));
       double alpha = regression.getRSquare();
       if ((horizon && getValue().get(bindex) != standard) || (!horizon && alpha < threshold)) {
         break;
       }
     }
-    regression.removeData(getTime().get(bindex) - startTime, getValue().get(bindex));
+    regression.removeData((double) getTime().get(bindex) - startTime, getValue().get(bindex));
     if (bindex == 0) {
       return end;
     }
     int findex = end;
     while (findex < getLen()) {
-      regression.addData(getTime().get(findex) - startTime, getValue().get(findex));
+      regression.addData((double) getTime().get(findex) - startTime, getValue().get(findex));
       double alpha = regression.getRSquare();
       if ((horizon && getValue().get(findex) != standard) || (!horizon && alpha < threshold)) {
         break;
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/anomaly/util/StreamMissDetector.java b/library-udf/src/main/java/org/apache/iotdb/library/anomaly/util/StreamMissDetector.java
index fe902e6c13f..ceadbb50938 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/anomaly/util/StreamMissDetector.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/anomaly/util/StreamMissDetector.java
@@ -33,7 +33,7 @@ public class StreamMissDetector {
   private final LongCircularQueue timeBuffer = new LongCircularQueue();
   private final BooleanCircularQueue labelBuffer = new BooleanCircularQueue();
   private final SimpleRegression regression = new SimpleRegression();
-  private final double threshold = 0.9999;
+  private static final double THRESHOLD = 0.9999;
   private int minLength;
   private int state;
   private long startTime;
@@ -58,7 +58,7 @@ public class StreamMissDetector {
         if (timeWindow.getSize() >= getWindowSize()) {
           linearRegress(0, getWindowSize());
           double alpha = regression.getRSquare();
-          if (Double.isNaN(alpha) || alpha > threshold) {
+          if (Double.isNaN(alpha) || alpha > THRESHOLD) {
             missingStartIndex = 0;
             state = 2;
           } else {
@@ -71,7 +71,7 @@ public class StreamMissDetector {
         if (timeWindow.getSize() >= getWindowSize() * 2) {
           linearRegress(getWindowSize(), getWindowSize() * 2);
           double alpha = regression.getRSquare();
-          if (Double.isNaN(alpha) || alpha > threshold) {
+          if (Double.isNaN(alpha) || alpha > THRESHOLD) {
             missingStartIndex = backExtend();
             state = 2;
           } else {
@@ -86,9 +86,9 @@ public class StreamMissDetector {
         }
         break;
       case 2:
-        regression.addData(time - startTime, value);
+        regression.addData((double) time - startTime, value);
         double alpha = regression.getRSquare();
-        if ((horizon && value != standard) || (!horizon && alpha < threshold)) {
+        if ((horizon && value != standard) || (!horizon && alpha < THRESHOLD)) {
           int missingEndIndex = timeWindow.getSize() - 1;
           for (int i = 0; i < missingStartIndex; i++) {
             timeBuffer.push(timeWindow.pop());
@@ -104,6 +104,9 @@ public class StreamMissDetector {
           regression.clear();
           state = 0;
         }
+        break;
+      default:
+        break;
     }
   }
 
@@ -129,6 +132,9 @@ public class StreamMissDetector {
           labelBuffer.push(label);
           valueWindow.pop();
         }
+        break;
+      default:
+        break;
     }
   }
 
@@ -138,20 +144,20 @@ public class StreamMissDetector {
     int bindex = getWindowSize();
     while (bindex > 0) {
       bindex--;
-      regression.addData(timeWindow.get(bindex) - startTime, valueWindow.get(bindex));
+      regression.addData((double) timeWindow.get(bindex) - startTime, valueWindow.get(bindex));
       double alpha = regression.getRSquare();
-      if ((horizon && valueWindow.get(bindex) != standard) || (!horizon && alpha < threshold)) {
+      if ((horizon && valueWindow.get(bindex) != standard) || (!horizon && alpha < THRESHOLD)) {
         break;
       }
     }
-    regression.removeData(timeWindow.get(bindex) - startTime, valueWindow.get(bindex));
+    regression.removeData((double) timeWindow.get(bindex) - startTime, valueWindow.get(bindex));
     return bindex + 1;
   }
 
   private void linearRegress(int start, int end) {
     double[][] data = new double[getWindowSize()][2];
     for (int i = start; i < end; i++) {
-      data[i - start][0] = timeWindow.get(i) - startTime;
+      data[i - start][0] = (double) timeWindow.get(i) - startTime;
       data[i - start][1] = valueWindow.get(i);
     }
     regression.addData(data);
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/anomaly/util/WindowDetect.java b/library-udf/src/main/java/org/apache/iotdb/library/anomaly/util/WindowDetect.java
index ca47101f2a9..475e4b02995 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/anomaly/util/WindowDetect.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/anomaly/util/WindowDetect.java
@@ -55,15 +55,15 @@ public class WindowDetect {
     repair();
   }
 
-  private void repair() throws Exception {
+  private void repair() {
     ArrayList<Double> repairedList = new ArrayList<>();
     ArrayList<Long> timeList = new ArrayList<>();
     for (int i = 0; i < timeLength; i++) {
       long curTime = time[i];
-      double curValue = original[i];
+      final double curValue = original[i];
       double valueBefore = 0.0;
       double valueAfter = 0.0;
-      for (int j = (int) Math.max(0, i - len); j <= Math.min(timeLength - 1, i + len); j++) {
+      for (int j = (int) Math.max(0, i - len); j <= Math.min(timeLength - 1.0d, i + len); j++) {
         if (j < i && Math.abs(time[j] - curTime) <= len * 1000) {
           valueBefore += original[j];
         }
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dlearn/UDTFAR.java b/library-udf/src/main/java/org/apache/iotdb/library/dlearn/UDTFAR.java
index cceebb8531a..ab9ae58719f 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dlearn/UDTFAR.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dlearn/UDTFAR.java
@@ -34,7 +34,6 @@ import java.util.List;
 
 public class UDTFAR implements UDTF {
   private int p;
-  private long interval;
   private List<Long> timeWindow = new ArrayList<>();
   private List<Double> valueWindow = new ArrayList<>();
 
@@ -67,8 +66,9 @@ public class UDTFAR implements UDTF {
     int count = 0;
     long maxFreqInterval = timeWindow.get(1) - timeWindow.get(0);
     for (int i = 2; i < timeWindow.size(); i++) {
-      if (maxFreqInterval == timeWindow.get(i) - timeWindow.get(i - 1)) count++;
-      else {
+      if (maxFreqInterval == timeWindow.get(i) - timeWindow.get(i - 1)) {
+        count++;
+      } else {
         count--;
         if (count == 0) {
           maxFreqInterval = timeWindow.get(i) - timeWindow.get(i - 1);
@@ -76,7 +76,7 @@ public class UDTFAR implements UDTF {
         }
       }
     }
-    this.interval = maxFreqInterval;
+    long interval = maxFreqInterval;
 
     List<Long> imputedTimeWindow = new ArrayList<>();
     List<Double> imputedValueWindow = new ArrayList<>();
@@ -102,8 +102,9 @@ public class UDTFAR implements UDTF {
     for (int i = 0; i <= p; i++) {
       resultCovariances[i] = 0;
       for (int j = 0; j < newLength - i; j++) {
-        if (j + i < newLength)
+        if (j + i < newLength) {
           resultCovariances[i] += imputedValueWindow.get(j) * imputedValueWindow.get(j + i);
+        }
       }
       resultCovariances[i] /= newLength - i;
     }
@@ -111,16 +112,18 @@ public class UDTFAR implements UDTF {
     double[] epsilons = new double[p + 1];
     double[] kappas = new double[p + 1];
     double[][] alphas = new double[p + 1][p + 1];
-    // alphas[i][j] denotes alpha_i^{(j)}
     epsilons[0] = resultCovariances[0];
     for (int i = 1; i <= p; i++) {
       double tmpSum = 0.0;
-      for (int j = 1; j <= i - 1; j++) tmpSum += alphas[j][i - 1] * resultCovariances[i - j];
+      for (int j = 1; j <= i - 1; j++) {
+        tmpSum += alphas[j][i - 1] * resultCovariances[i - j];
+      }
       kappas[i] = (resultCovariances[i] - tmpSum) / epsilons[i - 1];
       alphas[i][i] = kappas[i];
       if (i > 1) {
-        for (int j = 1; j <= i - 1; j++)
+        for (int j = 1; j <= i - 1; j++) {
           alphas[j][i] = alphas[j][i - 1] - kappas[i] * alphas[i - j][i - 1];
+        }
       }
       epsilons[i] = (1 - kappas[i] * kappas[i]) * epsilons[i - 1];
     }
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dmatch/UDAFCov.java b/library-udf/src/main/java/org/apache/iotdb/library/dmatch/UDAFCov.java
index 9f8a8e845f3..219c4d8de57 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dmatch/UDAFCov.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dmatch/UDAFCov.java
@@ -33,9 +33,9 @@ import org.apache.iotdb.udf.api.type.Type;
 public class UDAFCov implements UDTF {
 
   private long count = 0;
-  private double sum_x = 0.0;
-  private double sum_y = 0.0;
-  private double sum_xy = 0.0;
+  private double sumX = 0.0;
+  private double sumY = 0.0;
+  private double sumXY = 0.0;
 
   @Override
   public void validate(UDFParameterValidator validator) throws Exception {
@@ -50,9 +50,9 @@ public class UDAFCov implements UDTF {
       throws Exception {
     configurations.setAccessStrategy(new RowByRowAccessStrategy()).setOutputDataType(Type.DOUBLE);
     count = 0;
-    sum_x = 0;
-    sum_y = 0;
-    sum_xy = 0;
+    sumX = 0;
+    sumY = 0;
+    sumXY = 0;
   }
 
   @Override
@@ -64,16 +64,16 @@ public class UDAFCov implements UDTF {
     double y = Util.getValueAsDouble(row, 1);
     if (Double.isFinite(x) && Double.isFinite(y)) { // skip NaN rows
       count++;
-      sum_x += x;
-      sum_y += y;
-      sum_xy += x * y;
+      sumX += x;
+      sumY += y;
+      sumXY += x * y;
     }
   }
 
   @Override
   public void terminate(PointCollector collector) throws Exception {
     if (count > 0) { // calculate Cov only when there is more than 1 point
-      double cov = (sum_xy - sum_x * sum_y / count) / count;
+      double cov = (sumXY - sumX * sumY / count) / count;
       collector.putDouble(0, cov);
     } else {
       collector.putDouble(0, Double.NaN);
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dmatch/UDAFPearson.java b/library-udf/src/main/java/org/apache/iotdb/library/dmatch/UDAFPearson.java
index 714a789f675..30ef838b84b 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dmatch/UDAFPearson.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dmatch/UDAFPearson.java
@@ -33,11 +33,11 @@ import org.apache.iotdb.udf.api.type.Type;
 public class UDAFPearson implements UDTF {
 
   private long count = 0;
-  private double sum_x = 0.0;
-  private double sum_y = 0.0;
-  private double sum_xy = 0.0;
-  private double sum_xx = 0.0;
-  private double sum_yy = 0.0;
+  private double sumX = 0.0;
+  private double sumY = 0.0;
+  private double sumXY = 0.0;
+  private double sumXX = 0.0;
+  private double sumYY = 0.0;
 
   @Override
   public void validate(UDFParameterValidator validator) throws Exception {
@@ -52,11 +52,11 @@ public class UDAFPearson implements UDTF {
       throws Exception {
     configurations.setAccessStrategy(new RowByRowAccessStrategy()).setOutputDataType(Type.DOUBLE);
     count = 0;
-    sum_x = 0.0;
-    sum_y = 0.0;
-    sum_xy = 0.0;
-    sum_xx = 0.0;
-    sum_yy = 0.0;
+    sumX = 0.0;
+    sumY = 0.0;
+    sumXY = 0.0;
+    sumXX = 0.0;
+    sumYY = 0.0;
   }
 
   @Override
@@ -68,11 +68,11 @@ public class UDAFPearson implements UDTF {
     double y = Util.getValueAsDouble(row, 1);
     if (Double.isFinite(x) && Double.isFinite(y)) { // skip NaN rows
       count++;
-      sum_x += x;
-      sum_y += y;
-      sum_xy += x * y;
-      sum_xx += x * x;
-      sum_yy += y * y;
+      sumX += x;
+      sumY += y;
+      sumXY += x * y;
+      sumXX += x * x;
+      sumYY += y * y;
     }
   }
 
@@ -80,9 +80,9 @@ public class UDAFPearson implements UDTF {
   public void terminate(PointCollector collector) throws Exception {
     if (count > 0) { // calculate R only when there is more than 1 point
       double pearson =
-          (count * sum_xy - sum_x * sum_y)
-              / Math.sqrt(count * sum_xx - sum_x * sum_x)
-              / Math.sqrt(count * sum_yy - sum_y * sum_y);
+          (count * sumXY - sumX * sumY)
+              / Math.sqrt(count * sumXX - sumX * sumX)
+              / Math.sqrt(count * sumYY - sumY * sumY);
       collector.putDouble(0, pearson);
     } else {
       collector.putDouble(0, Double.NaN);
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dmatch/UDTFXCorr.java b/library-udf/src/main/java/org/apache/iotdb/library/dmatch/UDTFXCorr.java
index ce47f3613e8..646f498a834 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dmatch/UDTFXCorr.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dmatch/UDTFXCorr.java
@@ -31,12 +31,13 @@ import org.apache.iotdb.udf.api.customizer.strategy.RowByRowAccessStrategy;
 import org.apache.iotdb.udf.api.type.Type;
 
 import java.util.ArrayList;
+import java.util.List;
 
 /** This function calculates cross correlation between two input series. */
 public class UDTFXCorr implements UDTF {
 
-  private final ArrayList<Double> valueArrayList0 = new ArrayList<>();
-  private final ArrayList<Double> valueArrayList1 = new ArrayList<>();
+  private final List<Double> valueArrayList0 = new ArrayList<>();
+  private final List<Double> valueArrayList1 = new ArrayList<>();
 
   @Override
   public void beforeStart(UDFParameters udfParameters, UDTFConfigurations udtfConfigurations)
@@ -61,7 +62,7 @@ public class UDTFXCorr implements UDTF {
 
   @Override
   public void terminate(PointCollector collector) throws Exception {
-    ArrayList<Double> correlationArrayList =
+    List<Double> correlationArrayList =
         CrossCorrelation.calculateCrossCorrelation(valueArrayList0, valueArrayList1);
     for (int i = 0; i < correlationArrayList.size(); i++) {
       collector.putDouble(i, correlationArrayList.get(i));
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dmatch/util/CrossCorrelation.java b/library-udf/src/main/java/org/apache/iotdb/library/dmatch/util/CrossCorrelation.java
index 2e3efcc0f56..cbf14dd79d7 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dmatch/util/CrossCorrelation.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dmatch/util/CrossCorrelation.java
@@ -20,12 +20,17 @@
 package org.apache.iotdb.library.dmatch.util;
 
 import java.util.ArrayList;
+import java.util.List;
 
-/** util for UDTFXCorr and UDTFACF */
+/** util for UDTFXCorr and UDTFACF. */
 public class CrossCorrelation {
-  public static ArrayList<Double> calculateCrossCorrelation(
-      ArrayList<Double> valueArrayList1, ArrayList<Double> valueArrayList2) {
-    ArrayList<Double> correlationArrayList = new ArrayList<>();
+  private CrossCorrelation() {
+    throw new IllegalStateException("Utility class");
+  }
+
+  public static List<Double> calculateCrossCorrelation(
+      List<Double> valueArrayList1, List<Double> valueArrayList2) {
+    List<Double> correlationArrayList = new ArrayList<>();
     int length = valueArrayList1.size();
     for (int shift = 1; shift <= length; shift++) {
       double correlation = 0.0;
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFIntegral.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFIntegral.java
index 5b1f22957d6..2bb938d5f32 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFIntegral.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFIntegral.java
@@ -27,11 +27,12 @@ import org.apache.iotdb.udf.api.customizer.config.UDTFConfigurations;
 import org.apache.iotdb.udf.api.customizer.parameter.UDFParameterValidator;
 import org.apache.iotdb.udf.api.customizer.parameter.UDFParameters;
 import org.apache.iotdb.udf.api.customizer.strategy.RowByRowAccessStrategy;
+import org.apache.iotdb.udf.api.exception.UDFException;
 import org.apache.iotdb.udf.api.type.Type;
 
 /**
  * calculate the integral or the area under the curve of input series $unit$ is the time scale for
- * the area calculation, chosen from 1s(second, default), 1m(minute), 1h(hour), 1d(day)
+ * the area calculation, chosen from 1s(second, default), 1m(minute), 1h(hour), 1d(day).
  */
 public class UDAFIntegral implements UDTF {
 
@@ -83,7 +84,7 @@ public class UDAFIntegral implements UDTF {
         unitTime = 3600000L * 24L;
         break;
       default:
-        throw new Exception(
+        throw new UDFException(
             "Unknown time unit input: "
                 + parameters.getStringOrDefault(TIME_UNIT_KEY, TIME_UNIT_S));
     }
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFIntegralAvg.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFIntegralAvg.java
index c94146dbe7b..76a5f31419f 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFIntegralAvg.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFIntegralAvg.java
@@ -31,7 +31,7 @@ import org.apache.iotdb.udf.api.type.Type;
 
 /**
  * calculate the integral or the area under the curve of input series $unit$ is the time scale for
- * the area calculation, chosen from 1s(second, default), 1m(minute), 1h(hour), 1d(day)
+ * the area calculation, chosen from 1s(second, default), 1m(minute), 1h(hour), 1d(day).
  */
 public class UDAFIntegralAvg implements UDTF {
 
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFMad.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFMad.java
index b8176449892..fb3ffca8043 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFMad.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFMad.java
@@ -31,7 +31,7 @@ import org.apache.iotdb.udf.api.customizer.parameter.UDFParameters;
 import org.apache.iotdb.udf.api.customizer.strategy.RowByRowAccessStrategy;
 import org.apache.iotdb.udf.api.type.Type;
 
-/** calculate the exact or approximate median absolute deviation (mad) */
+/** calculate the exact or approximate median absolute deviation (mad). */
 public class UDAFMad implements UDTF {
 
   private ExactOrderStatistics statistics;
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFMedian.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFMedian.java
index c3710ac8a0e..89f43fdccc7 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFMedian.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFMedian.java
@@ -31,7 +31,7 @@ import org.apache.iotdb.udf.api.customizer.parameter.UDFParameters;
 import org.apache.iotdb.udf.api.customizer.strategy.RowByRowAccessStrategy;
 import org.apache.iotdb.udf.api.type.Type;
 
-/** calculate the exact or approximate median */
+/** calculate the exact or approximate median. */
 public class UDAFMedian implements UDTF {
 
   private ExactOrderStatistics statistics;
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFPercentile.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFPercentile.java
index 1ef44817b6c..8f45200777f 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFPercentile.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFPercentile.java
@@ -32,13 +32,14 @@ import org.apache.iotdb.udf.api.customizer.strategy.RowByRowAccessStrategy;
 import org.apache.iotdb.udf.api.type.Type;
 
 import java.util.HashMap;
+import java.util.Map;
 
-/** calculate the approximate percentile */
+/** calculate the approximate percentile. */
 public class UDAFPercentile implements UDTF {
-  public static HashMap<Integer, Long> intDic;
-  public static HashMap<Long, Long> longDic;
-  public static HashMap<Float, Long> floatDic;
-  public static HashMap<Double, Long> doubleDic;
+  protected static Map<Integer, Long> intDic;
+  protected static Map<Long, Long> longDic;
+  protected static Map<Float, Long> floatDic;
+  protected static Map<Double, Long> doubleDic;
   private ExactOrderStatistics statistics;
   private GKArray sketch;
   private boolean exact;
@@ -161,6 +162,9 @@ public class UDAFPercentile implements UDTF {
           break;
         case DOUBLE:
           collector.putDouble(0, res);
+          break;
+        default:
+          break;
       }
     }
   }
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFPeriod.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFPeriod.java
index d3f6d67ffa1..5e189d16367 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFPeriod.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFPeriod.java
@@ -118,24 +118,24 @@ public class UDAFPeriod implements UDTF {
     return corr;
   }
 
-  /** auto correlation (pearson of subseries) */
+  /** auto correlation (pearson of subseries). */
   private double pearson(double[] x, int subLength) {
-    double sum_x = 0;
-    double sum_y = 0;
-    double sum_xx = 0;
-    double sum_yy = 0;
-    double sum_xy = 0;
+    double sumX = 0;
+    double sumY = 0;
+    double sumXX = 0;
+    double sumYY = 0;
+    double sumXY = 0;
     int s1 = 0;
     int s2 = x.length - subLength;
     for (int i = 0; i < subLength; i++) {
-      sum_x += x[s1 + i];
-      sum_y += x[s2 + i];
-      sum_xx += x[s1 + i] * x[s1 + i];
-      sum_yy += x[s2 + i] * x[s2 + i];
-      sum_xy += x[s1 + i] * x[s2 + i];
+      sumX += x[s1 + i];
+      sumY += x[s2 + i];
+      sumXX += x[s1 + i] * x[s1 + i];
+      sumYY += x[s2 + i] * x[s2 + i];
+      sumXY += x[s1 + i] * x[s2 + i];
     }
-    return (subLength * sum_xy - sum_x * sum_y)
-        / Math.sqrt(subLength * sum_xx - sum_x * sum_x)
-        / Math.sqrt(subLength * sum_yy - sum_y * sum_y);
+    return (subLength * sumXY - sumX * sumY)
+        / Math.sqrt(subLength * sumXX - sumX * sumX)
+        / Math.sqrt(subLength * sumYY - sumY * sumY);
   }
 }
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFQuantile.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFQuantile.java
index a60bf98e4fc..67523a5ff60 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFQuantile.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFQuantile.java
@@ -29,7 +29,7 @@ import org.apache.iotdb.udf.api.customizer.parameter.UDFParameters;
 import org.apache.iotdb.udf.api.customizer.strategy.RowByRowAccessStrategy;
 import org.apache.iotdb.udf.api.type.Type;
 
-/** calculate the approximate percentile */
+/** calculate the approximate percentile. */
 public class UDAFQuantile implements UDTF {
   private org.apache.iotdb.library.dprofile.util.HeapLongKLLSketch sketch;
   private double rank;
@@ -41,7 +41,7 @@ public class UDAFQuantile implements UDTF {
         .validateInputSeriesNumber(1)
         .validateInputSeriesDataType(0, Type.INT32, Type.INT64, Type.FLOAT, Type.DOUBLE)
         .validate(
-            K -> (int) K >= 100,
+            k -> (int) k >= 100,
             "Size K has to be greater or equal than 100.",
             validator.getParameters().getIntOrDefault("K", 800))
         .validate(
@@ -57,10 +57,10 @@ public class UDAFQuantile implements UDTF {
         .setAccessStrategy(new RowByRowAccessStrategy())
         .setOutputDataType(parameters.getDataType(0));
     dataType = parameters.getDataType(0);
-    int K = parameters.getIntOrDefault("K", 800);
+    int k = parameters.getIntOrDefault("K", 800);
     rank = parameters.getDoubleOrDefault("rank", 0.5);
 
-    sketch = new org.apache.iotdb.library.dprofile.util.HeapLongKLLSketch(K * 8);
+    sketch = new org.apache.iotdb.library.dprofile.util.HeapLongKLLSketch(k * 8);
   }
 
   @Override
@@ -85,6 +85,9 @@ public class UDAFQuantile implements UDTF {
         break;
       case DOUBLE:
         collector.putDouble(0, res);
+        break;
+      default:
+        break;
     }
   }
 
@@ -108,18 +111,16 @@ public class UDAFQuantile implements UDTF {
 
   private double longToResult(long result) {
     switch (dataType) {
-      case INT32:
-        return (double) (result);
       case FLOAT:
         result = (result >>> 31) == 0 ? result : result ^ Long.MAX_VALUE;
         return Float.intBitsToFloat((int) (result));
-      case INT64:
-        return (double) (result);
       case DOUBLE:
         result = (result >>> 63) == 0 ? result : result ^ Long.MAX_VALUE;
         return Double.longBitsToDouble(result);
+      case INT64:
+      case INT32:
       default:
-        return (double) (result);
+        return (result);
     }
   }
 }
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFSpread.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFSpread.java
index cef155181f6..7c615662355 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFSpread.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFSpread.java
@@ -29,16 +29,22 @@ import org.apache.iotdb.udf.api.customizer.parameter.UDFParameters;
 import org.apache.iotdb.udf.api.customizer.strategy.RowByRowAccessStrategy;
 import org.apache.iotdb.udf.api.type.Type;
 
+import java.io.IOException;
+
 /**
  * This function is used to calculate the spread of time series, that is, the maximum value minus
  * the minimum value.
  */
 public class UDAFSpread implements UDTF {
 
-  int intMin = Integer.MAX_VALUE, intMax = Integer.MIN_VALUE;
-  long longMin = Long.MAX_VALUE, longMax = Long.MIN_VALUE;
-  float floatMin = Float.MAX_VALUE, floatMax = -Float.MAX_VALUE;
-  double doubleMin = Double.MAX_VALUE, doubleMax = -Double.MAX_VALUE;
+  int intMin = Integer.MAX_VALUE;
+  int intMax = Integer.MIN_VALUE;
+  long longMin = Long.MAX_VALUE;
+  long longMax = Long.MIN_VALUE;
+  float floatMin = Float.MAX_VALUE;
+  float floatMax = -Float.MAX_VALUE;
+  double doubleMin = Double.MAX_VALUE;
+  double doubleMax = -Double.MAX_VALUE;
   Type dataType;
 
   @Override
@@ -59,16 +65,18 @@ public class UDAFSpread implements UDTF {
   public void transform(Row row, PointCollector pc) throws Exception {
     switch (dataType) {
       case INT32:
-        transformInt(row, pc);
+        transformInt(row);
         break;
       case INT64:
-        transformLong(row, pc);
+        transformLong(row);
         break;
       case FLOAT:
-        transformFloat(row, pc);
+        transformFloat(row);
         break;
       case DOUBLE:
-        transformDouble(row, pc);
+        transformDouble(row);
+        break;
+      default:
         break;
     }
   }
@@ -93,19 +101,19 @@ public class UDAFSpread implements UDTF {
     }
   }
 
-  private void transformInt(Row row, PointCollector pc) throws Exception {
+  private void transformInt(Row row) throws IOException {
     int v = row.getInt(0);
     intMin = Math.min(intMin, v);
     intMax = Math.max(intMax, v);
   }
 
-  private void transformLong(Row row, PointCollector pc) throws Exception {
+  private void transformLong(Row row) throws IOException {
     long v = row.getLong(0);
     longMin = Math.min(longMin, v);
     longMax = Math.max(longMax, v);
   }
 
-  private void transformFloat(Row row, PointCollector pc) throws Exception {
+  private void transformFloat(Row row) throws IOException {
     float v = row.getFloat(0);
     if (Float.isFinite(v)) {
       floatMin = Math.min(floatMin, v);
@@ -113,11 +121,11 @@ public class UDAFSpread implements UDTF {
     }
   }
 
-  private void transformDouble(Row row, PointCollector pc) throws Exception {
+  private void transformDouble(Row row) throws IOException {
     double v = row.getDouble(0);
     if (Double.isFinite(v)) {
-      doubleMin = doubleMin < v ? doubleMin : v;
-      doubleMax = doubleMax > v ? doubleMax : v;
+      doubleMin = Math.min(doubleMin, v);
+      doubleMax = Math.max(doubleMax, v);
     }
   }
 }
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFACF.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFACF.java
index 6a88b952227..51af92b3273 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFACF.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFACF.java
@@ -31,11 +31,12 @@ import org.apache.iotdb.udf.api.customizer.strategy.RowByRowAccessStrategy;
 import org.apache.iotdb.udf.api.type.Type;
 
 import java.util.ArrayList;
+import java.util.List;
 
 /** This function calculates auto-correlation factor of a single input series. */
 public class UDTFACF implements UDTF {
 
-  private final ArrayList<Double> valueArrayList = new ArrayList<>();
+  private final List<Double> valueArrayList = new ArrayList<>();
 
   @Override
   public void validate(UDFParameterValidator validator) throws Exception {
@@ -62,7 +63,7 @@ public class UDTFACF implements UDTF {
 
   @Override
   public void terminate(PointCollector collector) throws Exception {
-    ArrayList<Double> correlationArrayList =
+    List<Double> correlationArrayList =
         CrossCorrelation.calculateCrossCorrelation(valueArrayList, valueArrayList);
     for (int i = 0; i < correlationArrayList.size(); i++) {
       collector.putDouble(i, correlationArrayList.get(i));
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFDistinct.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFDistinct.java
index c53c930df7f..778fd60db8e 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFDistinct.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFDistinct.java
@@ -85,6 +85,9 @@ public class UDTFDistinct implements UDTF {
         break;
       case BOOLEAN:
         booleanSet = new BooleanHashSet();
+        break;
+      default:
+        break;
     }
   }
 
@@ -108,6 +111,9 @@ public class UDTFDistinct implements UDTF {
         break;
       case BOOLEAN:
         booleanSet.add(row.getBoolean(0));
+        break;
+      default:
+        break;
     }
   }
 
@@ -155,6 +161,9 @@ public class UDTFDistinct implements UDTF {
           pc.putBoolean(i, booleanIterator.next());
           i++;
         }
+        break;
+      default:
+        break;
     }
   }
 
@@ -178,6 +187,9 @@ public class UDTFDistinct implements UDTF {
         break;
       case BOOLEAN:
         booleanSet.clear();
+        break;
+      default:
+        break;
     }
   }
 }
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFHistogram.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFHistogram.java
index ab5fe3c4af7..9976875b21a 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFHistogram.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFHistogram.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.dprofile;
 
 import org.apache.iotdb.library.util.Util;
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFMinMax.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFMinMax.java
index 6cd9851084a..a4eb892e778 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFMinMax.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFMinMax.java
@@ -35,7 +35,9 @@ import java.util.ArrayList;
 public class UDTFMinMax implements UDTF {
   ArrayList<Double> value = new ArrayList<>();
   ArrayList<Long> timestamp = new ArrayList<>();
-  String compute = "batch";
+  static final String BATCH_COMPUTE = "batch";
+  static final String STREAM_COMPUTE = "stream";
+  String compute = BATCH_COMPUTE;
   double min = 0.0d;
   double max = 0.0d;
   boolean flag = true;
@@ -46,9 +48,11 @@ public class UDTFMinMax implements UDTF {
         .validateInputSeriesNumber(1)
         .validateInputSeriesDataType(0, Type.INT32, Type.INT64, Type.FLOAT, Type.DOUBLE)
         .validate(
-            x -> ((String) x).equalsIgnoreCase("batch") || ((String) x).equalsIgnoreCase("stream"),
+            x ->
+                ((String) x).equalsIgnoreCase(BATCH_COMPUTE)
+                    || ((String) x).equalsIgnoreCase(STREAM_COMPUTE),
             "Parameter \"compute\" is illegal. Please use \"batch\" (for default) or \"stream\".",
-            validator.getParameters().getStringOrDefault("compute", "batch"))
+            validator.getParameters().getStringOrDefault("compute", BATCH_COMPUTE))
         .validate(
             params -> (double) params[0] < (double) params[1],
             "parameter $min$ should be smaller than $max$.",
@@ -65,8 +69,8 @@ public class UDTFMinMax implements UDTF {
     max = 0.0d;
     flag = true;
     configurations.setAccessStrategy(new RowByRowAccessStrategy()).setOutputDataType(Type.DOUBLE);
-    compute = parameters.getStringOrDefault("compute", "batch");
-    if (compute.equalsIgnoreCase("stream")) {
+    compute = parameters.getStringOrDefault("compute", BATCH_COMPUTE);
+    if (compute.equalsIgnoreCase(STREAM_COMPUTE)) {
       min = parameters.getDouble("min");
       max = parameters.getDouble("max");
     }
@@ -74,9 +78,9 @@ public class UDTFMinMax implements UDTF {
 
   @Override
   public void transform(Row row, PointCollector collector) throws Exception {
-    if (compute.equalsIgnoreCase("stream") && max > min) {
+    if (compute.equalsIgnoreCase(STREAM_COMPUTE) && max > min) {
       collector.putDouble(row.getTime(), (Util.getValueAsDouble(row) - min) / (max - min));
-    } else if (compute.equalsIgnoreCase("batch")) {
+    } else if (compute.equalsIgnoreCase(BATCH_COMPUTE)) {
       double v = Util.getValueAsDouble(row);
       if (Double.isFinite(v)) {
         value.add(v);
@@ -98,7 +102,7 @@ public class UDTFMinMax implements UDTF {
 
   @Override
   public void terminate(PointCollector collector) throws Exception {
-    if (compute.equalsIgnoreCase("batch") && max > min) {
+    if (compute.equalsIgnoreCase(BATCH_COMPUTE) && max > min) {
       for (int i = 0; i < value.size(); i++) {
         collector.putDouble(timestamp.get(i), (value.get(i) - min) / (max - min));
       }
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFMvAvg.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFMvAvg.java
index ab9c84578a3..7152e07ce80 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFMvAvg.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFMvAvg.java
@@ -68,11 +68,13 @@ public class UDTFMvAvg implements UDTF {
       v.push(value);
       windowSum += value;
       if (v.isFull()) {
-        collector.putDouble(t, windowSum / (double) windowSize);
+        collector.putDouble(t, windowSum / windowSize);
       }
     }
   }
 
   @Override
-  public void terminate(PointCollector collector) throws Exception {}
+  public void terminate(PointCollector collector)
+      throws Exception { // default implementation ignored
+  }
 }
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFPACF.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFPACF.java
index 7e7a8de36b8..4eb180a541c 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFPACF.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFPACF.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.dprofile;
 
 import org.apache.iotdb.library.dprofile.util.YuleWalker;
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFQLB.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFQLB.java
index b6209773591..85ce3e7411e 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFQLB.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFQLB.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.dprofile;
 
 import org.apache.iotdb.library.util.Util;
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFResample.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFResample.java
index 4179bccdefc..91cbf24ae2c 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFResample.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFResample.java
@@ -35,6 +35,7 @@ import java.text.SimpleDateFormat;
 /** This function does upsample or downsample of input series. */
 public class UDTFResample implements UDTF {
 
+  private static final String START_PARAM = "start";
   private Resampler resampler;
 
   @Override
@@ -61,11 +62,11 @@ public class UDTFResample implements UDTF {
             "aggr should be min, max, mean, median, first, last.",
             validator.getParameters().getStringOrDefault("interp", "nan").toLowerCase());
     SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-    if (validator.getParameters().hasAttribute("start")) {
+    if (validator.getParameters().hasAttribute(START_PARAM)) {
       validator.validate(
           x -> (long) x > 0,
           "start should conform to the format yyyy-MM-dd HH:mm:ss.",
-          format.parse(validator.getParameters().getString("start")).getTime());
+          format.parse(validator.getParameters().getString(START_PARAM)).getTime());
     }
     if (validator.getParameters().hasAttribute("end")) {
       validator.validate(
@@ -83,9 +84,10 @@ public class UDTFResample implements UDTF {
     String aggregator = parameters.getStringOrDefault("aggr", "mean").toLowerCase();
     String interpolator = parameters.getStringOrDefault("interp", "nan").toLowerCase();
     SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-    long startTime = -1, endTime = -1;
-    if (parameters.hasAttribute("start")) {
-      startTime = format.parse(parameters.getString("start")).getTime();
+    long startTime = -1;
+    long endTime = -1;
+    if (parameters.hasAttribute(START_PARAM)) {
+      startTime = format.parse(parameters.getString(START_PARAM)).getTime();
     }
     if (parameters.hasAttribute("end")) {
       endTime = format.parse(parameters.getString("end")).getTime();
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFSample.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFSample.java
index 67b1b8d1da9..96dc975d086 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFSample.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFSample.java
@@ -54,6 +54,7 @@ public class UDTFSample implements UDTF {
 
   private int k; // sample numbers
   private Method method;
+  private static final String METHOD_RESERVOIR = "reservoir";
   // These variables occurs in pool sampling
   private Pair<Long, Object>[] samples; // sampled data
   private int num = 0; // number of points already sampled
@@ -71,10 +72,10 @@ public class UDTFSample implements UDTF {
         .validate(
             method ->
                 "isometric".equalsIgnoreCase((String) method)
-                    || "reservoir".equalsIgnoreCase((String) method)
+                    || METHOD_RESERVOIR.equalsIgnoreCase((String) method)
                     || "triangle".equalsIgnoreCase((String) method),
             "Illegal sampling method.",
-            validator.getParameters().getStringOrDefault("method", "reservoir"));
+            validator.getParameters().getStringOrDefault("method", METHOD_RESERVOIR));
   }
 
   @Override
@@ -82,10 +83,14 @@ public class UDTFSample implements UDTF {
       throws Exception {
     this.k = parameters.getIntOrDefault("k", 1);
     this.dataType = parameters.getDataType(0);
-    String method = parameters.getStringOrDefault("method", "reservoir");
-    if ("triangle".equalsIgnoreCase(method)) this.method = Method.TRIANGLE;
-    else if ("isometric".equalsIgnoreCase(method)) this.method = Method.ISOMETRIC;
-    else this.method = Method.RESERVOIR;
+    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))
@@ -161,7 +166,7 @@ public class UDTFSample implements UDTF {
         }
       } else { // Method.ISOMETRIC
         for (long i = 0; i < this.k; i++) {
-          long j = Math.floorDiv(i * (long) n, (long) k); // avoid intermediate result overflows
+          long j = Math.floorDiv(i * n, k); // avoid intermediate result overflows
           Row row = rowWindow.getRow((int) j);
           Util.putValue(collector, dataType, row.getTime(), Util.getValueAsObject(row));
         }
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFSegment.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFSegment.java
index b9e6254c383..aead60e7942 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFSegment.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFSegment.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.dprofile;
 
 import org.apache.iotdb.library.dprofile.util.Segment;
@@ -30,6 +31,7 @@ import org.apache.iotdb.udf.api.customizer.strategy.RowByRowAccessStrategy;
 import org.apache.iotdb.udf.api.type.Type;
 
 import java.util.ArrayList;
+import java.util.List;
 
 /** This function segment input series into linear parts. */
 public class UDTFSegment implements UDTF {
@@ -37,9 +39,11 @@ public class UDTFSegment implements UDTF {
   private int windowSize;
   private double maxError;
   private String method;
+  private static final String METHOD_BOTTOM_UP = "bottom-up";
   private String output;
-  private static final ArrayList<Long> timestamp = new ArrayList<>();
-  private static final ArrayList<Double> value = new ArrayList<>();
+  private static final String OUTPUT_FIRST = "first";
+  private static final List<Long> timestamp = new ArrayList<>();
+  private static final List<Double> value = new ArrayList<>();
 
   @Override
   public void validate(UDFParameterValidator validator) throws Exception {
@@ -55,13 +59,15 @@ public class UDTFSegment implements UDTF {
             validator.getParameters().getDoubleOrDefault("error", 0.1))
         .validate(
             x ->
-                ((String) x).equalsIgnoreCase("bottom-up") || ((String) x).equalsIgnoreCase("swab"),
+                ((String) x).equalsIgnoreCase(METHOD_BOTTOM_UP)
+                    || ((String) x).equalsIgnoreCase("swab"),
             "Method is illegal.",
-            validator.getParameters().getStringOrDefault("method", "bottom-up"))
+            validator.getParameters().getStringOrDefault("method", METHOD_BOTTOM_UP))
         .validate(
-            x -> ((String) x).equalsIgnoreCase("first") || ((String) x).equalsIgnoreCase("all"),
+            x ->
+                ((String) x).equalsIgnoreCase(OUTPUT_FIRST) || ((String) x).equalsIgnoreCase("all"),
             "Output type is invalid.",
-            validator.getParameters().getStringOrDefault("output", "first"));
+            validator.getParameters().getStringOrDefault("output", OUTPUT_FIRST));
   }
 
   @Override
@@ -72,9 +78,9 @@ public class UDTFSegment implements UDTF {
     value.clear();
     this.windowSize = parameters.getIntOrDefault("window", 10);
     this.maxError = parameters.getDoubleOrDefault("error", 0.1);
-    this.method = parameters.getStringOrDefault("method", "bottom-up");
+    this.method = parameters.getStringOrDefault("method", METHOD_BOTTOM_UP);
     this.method = this.method.toLowerCase();
-    this.output = parameters.getStringOrDefault("output", "first");
+    this.output = parameters.getStringOrDefault("output", OUTPUT_FIRST);
     this.output = this.output.toLowerCase();
   }
 
@@ -91,19 +97,19 @@ public class UDTFSegment implements UDTF {
   public void terminate(PointCollector collector) throws Exception {
     long[] ts = timestamp.stream().mapToLong(Long::valueOf).toArray();
     double[] v = value.stream().mapToDouble(Double::valueOf).toArray();
-    ArrayList<double[]> seg = new ArrayList<>();
-    if (method.equals("bottom-up")) {
-      ArrayList<double[]> temp = Segment.bottom_up(v, maxError);
+    List<double[]> seg = new ArrayList<>();
+    if (method.equals(METHOD_BOTTOM_UP)) {
+      List<double[]> temp = Segment.bottomUp(v, maxError);
       seg.addAll(temp);
     } else if (method.equals("swab")) { // haven't tested yet
-      seg = Segment.swab_alg(v, ts, maxError, windowSize);
+      seg = Segment.swabAlg(v, maxError, windowSize);
     }
     ArrayList<double[]> res = new ArrayList<>();
     for (double[] doubles : seg) {
-      res.add(Segment.approximated_segment(doubles));
+      res.add(Segment.approximatedSegment(doubles));
     }
     int index = 0;
-    if (output.equals("first")) {
+    if (output.equals(OUTPUT_FIRST)) {
       for (double[] doubles : res) {
         collector.putDouble(ts[index], doubles[0]);
         index += doubles.length;
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFSpline.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFSpline.java
index d9c214033ac..34f213c571a 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFSpline.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFSpline.java
@@ -90,7 +90,7 @@ public class UDTFSpline implements UDTF {
                             / (samplePoints - 1)
                         + 0.5);
         double yhead = psf.value(approximation);
-        collector.putDouble(minimumTimestamp + (long) approximation, yhead);
+        collector.putDouble(minimumTimestamp + approximation, yhead);
       }
     }
   }
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFZScore.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFZScore.java
index 75115e5b655..f8485af8461 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFZScore.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFZScore.java
@@ -38,7 +38,9 @@ import java.util.ArrayList;
 public class UDTFZScore implements UDTF {
   ArrayList<Double> value = new ArrayList<>();
   ArrayList<Long> timestamp = new ArrayList<>();
-  String compute = "batch";
+  static final String BATCH_COMPUTE = "batch";
+  static final String STREAM_COMPUTE = "stream";
+  String compute = BATCH_COMPUTE;
   double avg = 0.0d;
   double sd = 0.0d;
   double sum = 0.0d;
@@ -50,9 +52,11 @@ public class UDTFZScore implements UDTF {
         .validateInputSeriesNumber(1)
         .validateInputSeriesDataType(0, Type.FLOAT, Type.DOUBLE, Type.INT32, Type.INT64)
         .validate(
-            x -> ((String) x).equalsIgnoreCase("batch") || ((String) x).equalsIgnoreCase("stream"),
+            x ->
+                ((String) x).equalsIgnoreCase(BATCH_COMPUTE)
+                    || ((String) x).equalsIgnoreCase(STREAM_COMPUTE),
             "Parameter \"compute\" is illegal. Please use \"batch\" (for default) or \"stream\".",
-            validator.getParameters().getStringOrDefault("compute", "batch"))
+            validator.getParameters().getStringOrDefault("compute", BATCH_COMPUTE))
         .validate(
             x -> ((Double) x) > 0,
             "Parameter \"sd\" is illegal. It should be larger than 0.",
@@ -67,8 +71,8 @@ public class UDTFZScore implements UDTF {
     sum = 0.0d;
     squareSum = 0.0d;
     configurations.setAccessStrategy(new RowByRowAccessStrategy()).setOutputDataType(Type.DOUBLE);
-    compute = parameters.getStringOrDefault("compute", "batch");
-    if (compute.equalsIgnoreCase("stream")) {
+    compute = parameters.getStringOrDefault("compute", BATCH_COMPUTE);
+    if (compute.equalsIgnoreCase(STREAM_COMPUTE)) {
       avg = parameters.getDouble("avg");
       sd = parameters.getDouble("sd");
     }
@@ -76,9 +80,9 @@ public class UDTFZScore implements UDTF {
 
   @Override
   public void transform(Row row, PointCollector collector) throws Exception {
-    if (compute.equalsIgnoreCase("stream") && sd > 0) {
+    if (compute.equalsIgnoreCase(STREAM_COMPUTE) && sd > 0) {
       collector.putDouble(row.getTime(), (Util.getValueAsDouble(row) - avg) / sd);
-    } else if (compute.equalsIgnoreCase("batch")) {
+    } else if (compute.equalsIgnoreCase(BATCH_COMPUTE)) {
       double v = Util.getValueAsDouble(row);
       if (Double.isFinite(v)) {
         value.add(v);
@@ -91,7 +95,7 @@ public class UDTFZScore implements UDTF {
 
   @Override
   public void terminate(PointCollector collector) throws Exception {
-    if (compute.equalsIgnoreCase("batch")) {
+    if (compute.equalsIgnoreCase(BATCH_COMPUTE)) {
       avg = sum / value.size();
       sd = Math.sqrt(squareSum / value.size() - avg * avg);
       for (int i = 0; i < value.size(); i++) {
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/CrossCorrelation.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/CrossCorrelation.java
index ef782b64d1f..9f6ff41f45e 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/CrossCorrelation.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/CrossCorrelation.java
@@ -16,15 +16,21 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.dprofile.util;
 
 import java.util.ArrayList;
+import java.util.List;
 
-/** util for UDTFXCorr and UDTFACF */
+/** util for UDTFXCorr and UDTFACF. */
 public class CrossCorrelation {
-  public static ArrayList<Double> calculateCrossCorrelation(
-      ArrayList<Double> valueArrayList1, ArrayList<Double> valueArrayList2) {
-    ArrayList<Double> correlationArrayList = new ArrayList<>();
+  private CrossCorrelation() {
+    throw new IllegalStateException("Utility class");
+  }
+
+  public static List<Double> calculateCrossCorrelation(
+      List<Double> valueArrayList1, List<Double> valueArrayList2) {
+    List<Double> correlationArrayList = new ArrayList<>();
     int length = valueArrayList1.size();
     for (int shift = 1; shift <= length; shift++) {
       double correlation = 0.0;
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/ExactOrderStatistics.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/ExactOrderStatistics.java
index 00ea12bd125..5eb0b4701ee 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/ExactOrderStatistics.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/ExactOrderStatistics.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.dprofile.util;
 
 import org.apache.iotdb.udf.api.access.Row;
@@ -30,7 +31,7 @@ import org.eclipse.collections.impl.list.mutable.primitive.LongArrayList;
 import java.io.IOException;
 import java.util.NoSuchElementException;
 
-/** Util for computing median, MAD, percentile */
+/** Util for computing median, MAD, percentile. */
 public class ExactOrderStatistics {
 
   private final Type dataType;
@@ -105,40 +106,6 @@ public class ExactOrderStatistics {
     }
   }
 
-  public double getMad() throws UDFInputSeriesDataTypeNotValidException {
-    switch (dataType) {
-      case INT32:
-        return getMad(intArrayList);
-      case INT64:
-        return getMad(longArrayList);
-      case FLOAT:
-        return getMad(floatArrayList);
-      case DOUBLE:
-        return getMad(doubleArrayList);
-      default:
-        // This will not happen.
-        throw new UDFInputSeriesDataTypeNotValidException(
-            0, dataType, Type.INT32, Type.INT64, Type.FLOAT, Type.DOUBLE);
-    }
-  }
-
-  public String getPercentile(double phi) throws UDFInputSeriesDataTypeNotValidException {
-    switch (dataType) {
-      case INT32:
-        return Integer.toString(getPercentile(intArrayList, phi));
-      case INT64:
-        return Long.toString(getPercentile(longArrayList, phi));
-      case FLOAT:
-        return Float.toString(getPercentile(floatArrayList, phi));
-      case DOUBLE:
-        return Double.toString(getPercentile(doubleArrayList, phi));
-      default:
-        // This will not happen.
-        throw new UDFInputSeriesDataTypeNotValidException(
-            0, dataType, Type.INT32, Type.INT64, Type.FLOAT, Type.DOUBLE);
-    }
-  }
-
   public static double getMedian(FloatArrayList nums) {
     if (nums.isEmpty()) {
       throw new NoSuchElementException();
@@ -152,29 +119,33 @@ public class ExactOrderStatistics {
     }
   }
 
-  public static double getMad(FloatArrayList nums) {
+  public static double getMedian(DoubleArrayList nums) {
     if (nums.isEmpty()) {
       throw new NoSuchElementException();
     } else {
-      double median = getMedian(nums);
-      DoubleArrayList dal = new DoubleArrayList();
-      for (int i = 0; i < nums.size(); ++i) {
-        dal.set(i, Math.abs(nums.get(i) - median));
+      nums.sortThis();
+      if (nums.size() % 2 == 0) {
+        return (nums.get(nums.size() / 2) + nums.get(nums.size() / 2 - 1)) / 2.0;
+      } else {
+        return nums.get((nums.size() - 1) / 2);
       }
-      return getMedian(dal);
     }
   }
 
-  public static float getPercentile(FloatArrayList nums, double phi) {
+  public static double getMedian(IntArrayList nums) {
     if (nums.isEmpty()) {
       throw new NoSuchElementException();
     } else {
       nums.sortThis();
-      return nums.get((int) Math.ceil(nums.size() * phi));
+      if (nums.size() % 2 == 0) {
+        return (nums.get(nums.size() / 2) + nums.get(nums.size() / 2 - 1)) / 2.0;
+      } else {
+        return nums.get((nums.size() - 1) / 2);
+      }
     }
   }
 
-  public static double getMedian(DoubleArrayList nums) {
+  public static double getMedian(LongArrayList nums) {
     if (nums.isEmpty()) {
       throw new NoSuchElementException();
     } else {
@@ -187,7 +158,7 @@ public class ExactOrderStatistics {
     }
   }
 
-  public static double getMad(DoubleArrayList nums) {
+  public static double getMad(FloatArrayList nums) {
     if (nums.isEmpty()) {
       throw new NoSuchElementException();
     } else {
@@ -200,29 +171,50 @@ public class ExactOrderStatistics {
     }
   }
 
-  public static double getPercentile(DoubleArrayList nums, double phi) {
+  public double getMad() throws UDFInputSeriesDataTypeNotValidException {
+    switch (dataType) {
+      case INT32:
+        return getMad(intArrayList);
+      case INT64:
+        return getMad(longArrayList);
+      case FLOAT:
+        return getMad(floatArrayList);
+      case DOUBLE:
+        return getMad(doubleArrayList);
+      default:
+        // This will not happen.
+        throw new UDFInputSeriesDataTypeNotValidException(
+            0, dataType, Type.INT32, Type.INT64, Type.FLOAT, Type.DOUBLE);
+    }
+  }
+
+  public static double getMad(DoubleArrayList nums) {
     if (nums.isEmpty()) {
       throw new NoSuchElementException();
     } else {
-      nums.sortThis();
-      return nums.get((int) Math.ceil(nums.size() * phi));
+      double median = getMedian(nums);
+      DoubleArrayList dal = new DoubleArrayList();
+      for (int i = 0; i < nums.size(); ++i) {
+        dal.set(i, Math.abs(nums.get(i) - median));
+      }
+      return getMedian(dal);
     }
   }
 
-  public static double getMedian(IntArrayList nums) {
+  public static double getMad(IntArrayList nums) {
     if (nums.isEmpty()) {
       throw new NoSuchElementException();
     } else {
-      nums.sortThis();
-      if (nums.size() % 2 == 0) {
-        return (nums.get(nums.size() / 2) + nums.get(nums.size() / 2 - 1)) / 2.0;
-      } else {
-        return nums.get((nums.size() - 1) / 2);
+      double median = getMedian(nums);
+      DoubleArrayList dal = new DoubleArrayList();
+      for (int i = 0; i < nums.size(); ++i) {
+        dal.set(i, Math.abs(nums.get(i) - median));
       }
+      return getMedian(dal);
     }
   }
 
-  public static double getMad(IntArrayList nums) {
+  public static double getMad(LongArrayList nums) {
     if (nums.isEmpty()) {
       throw new NoSuchElementException();
     } else {
@@ -235,7 +227,7 @@ public class ExactOrderStatistics {
     }
   }
 
-  public static int getPercentile(IntArrayList nums, double phi) {
+  public static float getPercentile(FloatArrayList nums, double phi) {
     if (nums.isEmpty()) {
       throw new NoSuchElementException();
     } else {
@@ -244,29 +236,38 @@ public class ExactOrderStatistics {
     }
   }
 
-  public static double getMedian(LongArrayList nums) {
+  public static double getPercentile(DoubleArrayList nums, double phi) {
     if (nums.isEmpty()) {
       throw new NoSuchElementException();
     } else {
       nums.sortThis();
-      if (nums.size() % 2 == 0) {
-        return (nums.get(nums.size() / 2) + nums.get(nums.size() / 2 - 1)) / 2.0;
-      } else {
-        return nums.get((nums.size() - 1) / 2);
-      }
+      return nums.get((int) Math.ceil(nums.size() * phi));
     }
   }
 
-  public static double getMad(LongArrayList nums) {
+  public String getPercentile(double phi) throws UDFInputSeriesDataTypeNotValidException {
+    switch (dataType) {
+      case INT32:
+        return Integer.toString(getPercentile(intArrayList, phi));
+      case INT64:
+        return Long.toString(getPercentile(longArrayList, phi));
+      case FLOAT:
+        return Float.toString(getPercentile(floatArrayList, phi));
+      case DOUBLE:
+        return Double.toString(getPercentile(doubleArrayList, phi));
+      default:
+        // This will not happen.
+        throw new UDFInputSeriesDataTypeNotValidException(
+            0, dataType, Type.INT32, Type.INT64, Type.FLOAT, Type.DOUBLE);
+    }
+  }
+
+  public static int getPercentile(IntArrayList nums, double phi) {
     if (nums.isEmpty()) {
       throw new NoSuchElementException();
     } else {
-      double median = getMedian(nums);
-      DoubleArrayList dal = new DoubleArrayList();
-      for (int i = 0; i < nums.size(); ++i) {
-        dal.set(i, Math.abs(nums.get(i) - median));
-      }
-      return getMedian(dal);
+      nums.sortThis();
+      return nums.get((int) Math.ceil(nums.size() * phi));
     }
   }
 
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/GKArray.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/GKArray.java
index 5cfcf2ad352..1870bdfb7a4 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/GKArray.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/GKArray.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.dprofile.util;
 
 import java.io.Serializable;
@@ -23,7 +24,7 @@ import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.List;
 
-/** Util for UDAFPercentile */
+/** Util for UDAFPercentile. */
 public class GKArray {
 
   private final double rankAccuracy;
@@ -105,21 +106,10 @@ public class GKArray {
     final ArrayList<Tuple> mergedEntries =
         new ArrayList<>(entries.size() + additionalEntries.size() / 3);
 
-    int i = 0, j = 0;
+    int i = 0;
+    int j = 0;
     while (i < additionalEntries.size() || j < entries.size()) {
-      if (i == additionalEntries.size()) {
-        if (j + 1 < entries.size()
-            && entries.get(j).g + entries.get(j + 1).g + entries.get(j + 1).delta
-                <= removalThreshold) {
-          // Removable from sketch.
-          entries.get(j + 1).g += entries.get(j).g;
-        } else {
-          mergedEntries.add(entries.get(j));
-        }
-
-        j++;
-
-      } else if (j == entries.size()) {
+      if (j == entries.size()) {
         // Done with sketch; now only considering incoming.
         if (i + 1 < additionalEntries.size()
             && additionalEntries.get(i).g
@@ -146,7 +136,7 @@ public class GKArray {
 
         i++;
 
-      } else {
+      } else { // the same as i == additionalEntries.size()
         if (j + 1 < entries.size()
             && entries.get(j).g + entries.get(j + 1).g + entries.get(j + 1).delta
                 <= removalThreshold) {
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/HeapLongKLLSketch.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/HeapLongKLLSketch.java
index 39767fc08e6..d6d320b0803 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/HeapLongKLLSketch.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/HeapLongKLLSketch.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.dprofile.util;
 
 import java.util.Arrays;
@@ -28,7 +29,7 @@ import java.util.List;
 public class HeapLongKLLSketch extends org.apache.iotdb.library.dprofile.util.KLLSketchForQuantile {
 
   public HeapLongKLLSketch(int maxMemoryByte) { // maxN=7000 for PAGE, 1.6e6 for CHUNK
-    N = 0;
+    n = 0;
     calcParameters(maxMemoryByte);
     calcLevelMaxSize(1);
   }
@@ -49,114 +50,125 @@ public class HeapLongKLLSketch extends org.apache.iotdb.library.dprofile.util.KL
   protected void calcLevelMaxSize(int setLevel) { // set cntLevel.  cntLevel won't decrease
     int[] tmpArr = new int[setLevel + 1];
     int maxPos = cntLevel > 0 ? Math.max(maxMemoryNum, levelPos[cntLevel]) : maxMemoryNum;
-    for (int i = 0; i < setLevel + 1; i++) tmpArr[i] = i < cntLevel ? levelPos[i] : maxPos;
+    for (int i = 0; i < setLevel + 1; i++) {
+      tmpArr[i] = i < cntLevel ? levelPos[i] : maxPos;
+    }
     levelPos = tmpArr;
     cntLevel = setLevel;
     levelMaxSize = new int[cntLevel];
     int newK = 0;
     for (int addK = 1 << 28; addK > 0; addK >>>= 1) { // find a new K to fit the memory limit.
       int need = 0;
-      for (int i = 0; i < cntLevel; i++)
+      for (int i = 0; i < cntLevel; i++) {
         need +=
-            Math.max(8, (int) Math.round(((newK + addK) * Math.pow(2.0 / 3, cntLevel - i - 1))));
-      if (need <= maxMemoryNum) newK += addK;
+            Math.max(8, (int) Math.round(((newK + addK) * Math.pow(2.0 / 3, cntLevel - i - 1.0d))));
+      }
+      if (need <= maxMemoryNum) {
+        newK += addK;
+      }
+    }
+    for (int i = 0; i < cntLevel; i++) {
+      levelMaxSize[i] =
+          Math.max(8, (int) Math.round((newK * Math.pow(2.0 / 3, cntLevel - i - 1.0d))));
     }
-    for (int i = 0; i < cntLevel; i++)
-      levelMaxSize[i] = Math.max(8, (int) Math.round((newK * Math.pow(2.0 / 3, cntLevel - i - 1))));
-    //    show();
   }
 
   public String toString() {
     final StringBuilder sb = new StringBuilder();
-    sb.append(N);
+    sb.append(n);
     sb.append(levelMaxSize[cntLevel - 1]);
     sb.append(cntLevel);
     sb.append((levelPos[cntLevel] - levelPos[0]));
-    for (int i = 0; i < cntLevel; i++) sb.append(levelPos[i]);
+    for (int i = 0; i < cntLevel; i++) {
+      sb.append(levelPos[i]);
+    }
     return sb.toString();
   }
 
-  public void showLevelMaxSize() {
-    int numLEN = levelPos[cntLevel] - levelPos[0];
-    System.out.println("\t\t//maxMemNum:" + maxMemoryNum + "\t//N:" + N);
-    for (int i = 0; i < cntLevel; i++) System.out.print("\t\t" + levelMaxSize[i] + "\t");
-    System.out.println();
-    System.out.println("-------------------------------------------------------");
-  }
-
   private static int mergeSort(
-      long[] a1, int L1, int R1, long[] a2, int L2, int R2, long[] a3, int pos) {
-    if (L1 == R1) System.arraycopy(a2, L2, a3, pos, R2 - L2);
-    else if (L2 == R2) System.arraycopy(a1, L1, a3, pos, R1 - L1);
-    else {
-      int p1 = L1, p2 = L2;
-      while (p1 < R1 || p2 < R2)
-        if (p1 < R1 && (p2 == R2 || a1[p1] < a2[p2])) a3[pos++] = a1[p1++];
-        else a3[pos++] = a2[p2++];
+      long[] a1, int l1, int r1, long[] a2, int l2, int r2, long[] a3, int pos) {
+    if (l1 == r1) {
+      System.arraycopy(a2, l2, a3, pos, r2 - l2);
+    } else if (l2 == r2) {
+      System.arraycopy(a1, l1, a3, pos, r1 - l1);
+    } else {
+      int p1 = l1;
+      int p2 = l2;
+      while (p1 < r1 || p2 < r2) {
+        if (p1 < r1 && (p2 == r2 || a1[p1] < a2[p2])) {
+          a3[pos++] = a1[p1++];
+        } else {
+          a3[pos++] = a2[p2++];
+        }
+      }
     }
-    return R1 - L1 + R2 - L2;
+    return r1 - l1 + r2 - l2;
   }
 
   private void compactOneLevel(int level) { // compact half of data when numToReduce is small
-    if (level == cntLevel - 1) calcLevelMaxSize(cntLevel + 1);
-    int L1 = levelPos[level], R1 = levelPos[level + 1]; // [L,R)
-    //    System.out.println("T_T\t"+(R1-L1));
+    if (level == cntLevel - 1) {
+      calcLevelMaxSize(cntLevel + 1);
+    }
+    int l1 = levelPos[level];
+    int r1 = levelPos[level + 1]; // [L,R)
     if (level == 0 && !level0Sorted) {
-      Arrays.sort(num, L1, R1);
+      Arrays.sort(num, l1, r1);
       level0Sorted = true;
     }
-    L1 += (R1 - L1) & 1;
-    if (L1 == R1) return;
+    l1 += (r1 - l1) & 1;
+    if (l1 == r1) {
+      return;
+    }
 
-    randomlyHalveDownToLeft(L1, R1);
+    randomlyHalveDownToLeft(l1, r1);
 
-    int mid = (L1 + R1) >>> 1;
-    mergeSortWithoutSpace(L1, mid, levelPos[level + 1], levelPos[level + 2]);
+    int mid = (l1 + r1) >>> 1;
+    mergeSortWithoutSpace(l1, mid, levelPos[level + 1], levelPos[level + 2]);
     levelPos[level + 1] = mid;
-    int newP = levelPos[level + 1] - 1, oldP = L1 - 1;
-    for (int i = oldP; i >= levelPos[0]; i--) num[newP--] = num[oldP--];
+    int newP = levelPos[level + 1] - 1;
+    int oldP = l1 - 1;
+    for (int i = oldP; i >= levelPos[0]; i--) {
+      num[newP--] = num[oldP--];
+    }
 
-    levelPos[level] = levelPos[level + 1] - (L1 - levelPos[level]);
-    int numReduced = (R1 - L1) >>> 1;
-    for (int i = level - 1; i >= 0; i--) levelPos[i] += numReduced;
+    levelPos[level] = levelPos[level + 1] - (l1 - levelPos[level]);
+    int numReduced = (r1 - l1) >>> 1;
+    for (int i = level - 1; i >= 0; i--) {
+      levelPos[i] += numReduced;
+    }
   }
 
   @Override
   public void compact() {
     int compactLevel = cntLevel - 1;
-    double mxRate = 0;
-    for (int i = 0; i < cntLevel; i++)
+    for (int i = 0; i < cntLevel; i++) {
       if (levelPos[i + 1] - levelPos[i] > levelMaxSize[i]) {
-        //      double rate = 1.0*(levelPos[i+1]-levelPos[i])/Math.pow(2,i);
-        //      if(rate>mxRate&&(i<cntLevel-1 || mxRate==0)) {
         compactLevel = i;
-        //        mxRate=rate;
-        //      }
-        //      break;
       }
+    }
 
     compactOneLevel(compactLevel);
   }
 
   public void merge(org.apache.iotdb.library.dprofile.util.KLLSketchForQuantile another) {
-    //    System.out.println("[MERGE]");
-    //    show();
-    //    another.show();
-    if (another.cntLevel > cntLevel) calcLevelMaxSize(another.cntLevel);
+    if (another.cntLevel > cntLevel) {
+      calcLevelMaxSize(another.cntLevel);
+    }
     for (int i = 0; i < another.cntLevel; i++) {
       int numToMerge = another.levelPos[i + 1] - another.levelPos[i];
-      if (numToMerge == 0) continue;
+      if (numToMerge == 0) {
+        continue;
+      }
       int mergingL = another.levelPos[i];
       while (numToMerge > 0) {
-        //        System.out.println("\t\t"+levelPos[0]);show();showLevelMaxSize();
-        if (levelPos[0] == 0) compact();
-        //        if(levelPos[0]==0){
-        //          show();
-        //          showLevelMaxSize();
-        //        }
+        if (levelPos[0] == 0) {
+          compact();
+        }
         int delta = Math.min(numToMerge, levelPos[0]);
         if (i > 0) { // move to give space for level i
-          for (int j = 0; j < i; j++) levelPos[j] -= delta;
+          for (int j = 0; j < i; j++) {
+            levelPos[j] -= delta;
+          }
           System.arraycopy(num, delta, num, 0, levelPos[i] - delta);
         }
         System.arraycopy(another.num, mergingL, num, levelPos[i] - delta, delta);
@@ -165,17 +177,11 @@ public class HeapLongKLLSketch extends org.apache.iotdb.library.dprofile.util.KL
         mergingL += delta;
       }
     }
-    this.N += another.N;
-    //    System.out.println("[MERGE result]");
-    //    show();
-    //    System.out.println();
+    this.n += another.n;
   }
 
   public void mergeWithTempSpace(
       org.apache.iotdb.library.dprofile.util.KLLSketchForQuantile another) {
-    //    System.out.println("[MERGE]");
-    //    show();
-    //    another.show();
     int[] oldLevelPos = levelPos;
     int oldCntLevel = cntLevel;
     calcLevelMaxSize(Math.max(cntLevel, another.cntLevel));
@@ -183,11 +189,7 @@ public class HeapLongKLLSketch extends org.apache.iotdb.library.dprofile.util.KL
       int cntPos = oldLevelPos[0] - another.getNumLen();
       for (int i = 0; i < cntLevel; i++) {
         int tmpL = cntPos;
-        //        if(i<oldCntLevel)
-        //
-        // System.out.println("\t\t\t\t"+tmpL+"\t\t"+levelPos[i]+"\t"+oldLevelPos[i]+"---"+oldLevelPos[i+1]);
-        //        levelPos[i] = tmpL;
-        if (i < oldCntLevel && i < another.cntLevel)
+        if (i < oldCntLevel && i < another.cntLevel) {
           cntPos +=
               mergeSort(
                   num,
@@ -198,10 +200,10 @@ public class HeapLongKLLSketch extends org.apache.iotdb.library.dprofile.util.KL
                   another.levelPos[i + 1],
                   num,
                   cntPos);
-        else if (i < oldCntLevel)
+        } else if (i < oldCntLevel) {
           cntPos +=
               mergeSort(num, oldLevelPos[i], oldLevelPos[i + 1], another.num, 0, 0, num, cntPos);
-        else if (i < another.cntLevel)
+        } else if (i < another.cntLevel) {
           cntPos +=
               mergeSort(
                   num,
@@ -212,17 +214,18 @@ public class HeapLongKLLSketch extends org.apache.iotdb.library.dprofile.util.KL
                   another.levelPos[i + 1],
                   num,
                   cntPos);
+        }
         levelPos[i] = tmpL;
       }
       levelPos[cntLevel] = cntPos;
-      this.N += another.N;
+      this.n += another.n;
     } else {
       long[] oldNum = num;
       num = new long[getNumLen() + another.getNumLen()];
       int numLen = 0;
       for (int i = 0; i < cntLevel; i++) {
         int tmpL = numLen;
-        if (i < oldCntLevel && i < another.cntLevel)
+        if (i < oldCntLevel && i < another.cntLevel) {
           numLen +=
               mergeSort(
                   oldNum,
@@ -233,10 +236,10 @@ public class HeapLongKLLSketch extends org.apache.iotdb.library.dprofile.util.KL
                   another.levelPos[i + 1],
                   num,
                   numLen);
-        else if (i < oldCntLevel)
+        } else if (i < oldCntLevel) {
           numLen +=
               mergeSort(oldNum, oldLevelPos[i], oldLevelPos[i + 1], another.num, 0, 0, num, numLen);
-        else if (i < another.cntLevel)
+        } else if (i < another.cntLevel) {
           numLen +=
               mergeSort(
                   oldNum,
@@ -247,50 +250,38 @@ public class HeapLongKLLSketch extends org.apache.iotdb.library.dprofile.util.KL
                   another.levelPos[i + 1],
                   num,
                   numLen);
+        }
         levelPos[i] = tmpL;
       }
       levelPos[cntLevel] = numLen;
-      //    System.out.println("-------------------------------.............---------");
-      //    show();
-      while (getNumLen() > maxMemoryNum) compact();
-      //    show();
-      //    System.out.println("\t\t??\t\t"+Arrays.toString(num));
+      while (getNumLen() > maxMemoryNum) {
+        compact();
+      }
       int newPos0 = maxMemoryNum - getNumLen();
       System.arraycopy(num, levelPos[0], oldNum, newPos0, getNumLen());
-      for (int i = cntLevel; i >= 0; i--) levelPos[i] = levelPos[i] - levelPos[0] + newPos0;
+      for (int i = cntLevel; i >= 0; i--) {
+        levelPos[i] = levelPos[i] - levelPos[0] + newPos0;
+      }
       num = oldNum;
-      this.N += another.N;
+      this.n += another.n;
     }
-    //    System.out.println("\t\t??\t\t"+Arrays.toString(num));
-    //    System.out.println("\t\t??\t\t"+Arrays.toString(levelPos));
-    //    System.out.println("-------------------------------.............---------");
-    //    System.out.println("[MERGE result]");
-    //    show();
-    //    System.out.println();
   }
 
   public void mergeWithTempSpace(
       List<org.apache.iotdb.library.dprofile.util.KLLSketchForQuantile> otherList) {
-    //    System.out.println("[MERGE]");
-    //    show();
-    //
-    // System.out.println("[mergeWithTempSpace]\t???\t"+num.length+"\t??\t"+cntLevel+"\t??\toldPos0:"+levelPos[0]);
-    //    System.out.println("[mergeWithTempSpace]\t???\tmaxMemNum:"+maxMemoryNum);
-    //    another.show();
     int[] oldLevelPos = Arrays.copyOf(levelPos, cntLevel + 1);
     int oldCntLevel = cntLevel;
     int otherNumLen = 0;
     long otherN = 0;
-    //    System.out.print("\t\t\t\t[mergeWithTempSpace] others:");
-    for (org.apache.iotdb.library.dprofile.util.KLLSketchForQuantile another : otherList)
+    for (org.apache.iotdb.library.dprofile.util.KLLSketchForQuantile another : otherList) {
       if (another != null) {
-        //      System.out.print("\t"+another.getN());
-        if (another.cntLevel > cntLevel) calcLevelMaxSize(another.cntLevel);
+        if (another.cntLevel > cntLevel) {
+          calcLevelMaxSize(another.cntLevel);
+        }
         otherNumLen += another.getNumLen();
         otherN += another.getN();
       }
-    //    System.out.println();
-    //    System.out.println("[mergeWithTempSpace]\totherNumLen:"+otherNumLen);
+    }
     if (getNumLen() + otherNumLen <= maxMemoryNum) {
       int cntPos = oldLevelPos[0] - otherNumLen;
       for (int i = 0; i < cntLevel; i++) {
@@ -299,58 +290,48 @@ public class HeapLongKLLSketch extends org.apache.iotdb.library.dprofile.util.KL
           System.arraycopy(num, oldLevelPos[i], num, cntPos, oldLevelPos[i + 1] - oldLevelPos[i]);
           cntPos += oldLevelPos[i + 1] - oldLevelPos[i];
         }
-        for (org.apache.iotdb.library.dprofile.util.KLLSketchForQuantile another : otherList)
+        for (org.apache.iotdb.library.dprofile.util.KLLSketchForQuantile another : otherList) {
           if (another != null && i < another.cntLevel) {
             System.arraycopy(
                 another.num, another.levelPos[i], num, cntPos, another.getLevelSize(i));
             cntPos += another.getLevelSize(i);
           }
+        }
         Arrays.sort(num, levelPos[i], cntPos);
-        //        System.out.println("\t\t!!\t"+cntPos);
       }
       levelPos[cntLevel] = cntPos;
-      this.N += otherN;
+      this.n += otherN;
     } else {
       long[] oldNum = num;
       num = new long[getNumLen() + otherNumLen];
-      //      System.out.println("\t\t\t\ttmp_num:"+num.length+"
-      // old_num:"+levelPos[0]+"..."+levelPos[oldCntLevel]);
       int numLen = 0;
       for (int i = 0; i < cntLevel; i++) {
         levelPos[i] = numLen;
         if (i < oldCntLevel) {
-          //          System.out.println("\t\t\tlv"+i+"\toldPos:"+oldLevelPos[i]+"\t"+numLen+"
-          // this_level_old_len:"+(oldLevelPos[i + 1] - oldLevelPos[i]));
-          //          System.out.println("\t\t\t"+oldNum[oldLevelPos[i + 1]-1]);
-          System.arraycopy(
-              oldNum, oldLevelPos[i], num, numLen, oldLevelPos[i + 1] - oldLevelPos[i]);
-          numLen += oldLevelPos[i + 1] - oldLevelPos[i];
+          int length = oldLevelPos[i + 1] - oldLevelPos[i];
+          System.arraycopy(oldNum, oldLevelPos[i], num, numLen, length);
+          numLen += length;
         }
-        for (org.apache.iotdb.library.dprofile.util.KLLSketchForQuantile another : otherList)
+        for (org.apache.iotdb.library.dprofile.util.KLLSketchForQuantile another : otherList) {
           if (another != null && i < another.cntLevel) {
             System.arraycopy(
                 another.num, another.levelPos[i], num, numLen, another.getLevelSize(i));
             numLen += another.getLevelSize(i);
           }
+        }
         Arrays.sort(num, levelPos[i], numLen);
       }
       levelPos[cntLevel] = numLen;
-      this.N += otherN;
-      //    System.out.println("-------------------------------.............---------");
-      //      show();System.out.println("\t?\t"+levelPos[0]);
-      while (getNumLen() > maxMemoryNum) compact();
-      //      show();System.out.println("\t?\t"+levelPos[0]);
-      //    System.out.println("\t\t??\t\t"+Arrays.toString(num));
+      this.n += otherN;
+      while (getNumLen() > maxMemoryNum) {
+        compact();
+      }
       int newPos0 = maxMemoryNum - getNumLen();
       System.arraycopy(num, levelPos[0], oldNum, newPos0, getNumLen());
-      for (int i = cntLevel; i >= 0; i--) levelPos[i] += newPos0 - levelPos[0];
+      for (int i = cntLevel; i >= 0; i--) {
+        levelPos[i] += newPos0 - levelPos[0];
+      }
       num = oldNum;
     }
-    //    System.out.println("\t\t??\t\t"+Arrays.toString(num));
-    //    System.out.println("\t\t??\t\t"+Arrays.toString(levelPos));
-    //    System.out.println("-------------------------------.............---------");
-    //    System.out.println("[MERGE result]");
-    //    show();
-    //    System.out.println();
   }
 }
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/KLLSketchForQuantile.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/KLLSketchForQuantile.java
index ee52016595d..be24edc06b3 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/KLLSketchForQuantile.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/KLLSketchForQuantile.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.dprofile.util;
 
 import java.util.Arrays;
@@ -24,16 +25,18 @@ import java.util.Random;
 // based on KLL Sketch in DataSketch. See
 // https://github.com/apache/datasketches-java/tree/master/src/main/java/org/apache/datasketches/kll
 public abstract class KLLSketchForQuantile {
-  long N;
+  long n;
   int maxMemoryNum;
   long[] num;
   boolean level0Sorted;
   int cntLevel;
-  int[] levelPos, levelMaxSize;
-  long XORSHIFT = new Random().nextInt(); // 0x2333333319260817L;
-  //  Random test_random = new Random();
+  int[] levelPos;
+  int[] levelMaxSize;
+  long XORSHIFT;
 
-  public KLLSketchForQuantile() {}
+  protected KLLSketchForQuantile() {
+    XORSHIFT = new Random().nextInt();
+  }
 
   protected abstract int calcMaxMemoryNum(int maxMemoryByte);
 
@@ -43,34 +46,13 @@ public abstract class KLLSketchForQuantile {
     return levelPos[level + 1] - levelPos[level];
   }
 
-  public void show() {
-    for (int i = 0; i < cntLevel; i++) {
-      System.out.print("\t");
-      System.out.print("[" + (levelPos[i + 1] - levelPos[i]) + "]");
-      System.out.print("\t");
-    }
-    System.out.println();
-  }
-
-  public void showNum() {
-    for (int i = 0; i < cntLevel; i++) {
-      System.out.print("\t|");
-      for (int j = levelPos[i]; j < levelPos[i + 1]; j++) System.out.print(num[j] + ",");
-      System.out.print("|\t");
-    }
-    System.out.println();
-  }
-
   public void update(long x) { // signed long
-    if (levelPos[0] == 0) compact();
+    if (levelPos[0] == 0) {
+      compact();
+    }
     num[--levelPos[0]] = x;
-    N++;
+    n++;
     level0Sorted = false;
-
-    //    boolean flag=false;
-    //    for(int i=0;i<cntLevel;i++)if(levelPos[i+1]-levelPos[i]>levelMaxSize[i])flag=true;
-    //    if(flag)compact();
-    //    System.out.println("\t\t\t"+x);
   }
 
   protected abstract void compact();
@@ -80,73 +62,97 @@ public abstract class KLLSketchForQuantile {
     XORSHIFT ^= XORSHIFT << 25;
     XORSHIFT ^= XORSHIFT >>> 27;
     return (int) ((XORSHIFT * 0x2545F4914F6CDD1DL) & 1);
-    //    return test_random.nextInt()&1;
   }
 
-  protected void randomlyHalveDownToLeft(int L, int R) {
+  protected void randomlyHalveDownToLeft(int l, int r) {
     int delta = getNextRand01();
-    int mid = (L + R) >>> 1;
-    for (int i = L, j = L; i < mid; i++, j += 2) num[i] = num[j + delta];
+    int mid = (l + r) >>> 1;
+    for (int i = l, j = l; i < mid; i++, j += 2) {
+      num[i] = num[j + delta];
+    }
   }
 
-  protected void mergeSortWithoutSpace(int L1, int mid, int L2, int R2) {
-    int p1 = L1, p2 = L2, cntPos = mid;
-    while (p1 < mid || p2 < R2) {
-      if (p1 < mid && (p2 == R2 || num[p1] < num[p2])) num[cntPos++] = num[p1++];
-      else num[cntPos++] = num[p2++];
+  protected void mergeSortWithoutSpace(int l1, int mid, int l2, int r2) {
+    int p1 = l1;
+    int p2 = l2;
+    int cntPos = mid;
+    while (p1 < mid || p2 < r2) {
+      if (p1 < mid && (p2 == r2 || num[p1] < num[p2])) {
+        num[cntPos++] = num[p1++];
+      } else {
+        num[cntPos++] = num[p2++];
+      }
     }
   }
 
   protected int findRankInLevel(int level, long v) {
-    int L = levelPos[level], R = levelPos[level + 1];
+    int l = levelPos[level];
+    int r = levelPos[level + 1];
     if (level == 0 && !level0Sorted) {
-      Arrays.sort(num, L, R);
+      Arrays.sort(num, l, r);
       level0Sorted = true;
     }
-    R--;
-    if (L > R || num[L] >= v) return 0;
-    while (L < R) {
-      int mid = (L + R + 1) >> 1;
-      if (num[mid] < v) L = mid;
-      else R = mid - 1;
+    r--;
+    if (l > r || num[l] >= v) {
+      return 0;
+    }
+    while (l < r) {
+      int mid = (l + r + 1) >> 1;
+      if (num[mid] < v) {
+        l = mid;
+      } else {
+        r = mid - 1;
+      }
     }
-    return (L - levelPos[level] + 1) * (1 << level);
+    return (l - levelPos[level] + 1) * (1 << level);
   }
 
   public int getApproxRank(long v) {
     int approxRank = 0;
     for (int i = 0; i < cntLevel; i++) {
       approxRank += findRankInLevel(i, v);
-      //      for (int j = levelPos[i]; j < levelPos[i + 1]; j++)
-      //        if (num[j] < v) approxRank += 1 << i;
     }
     return approxRank;
   }
 
-  public long findMaxValueWithRank(long K) {
-    long L = Long.MIN_VALUE, R = Long.MAX_VALUE, mid;
-    while (L < R) {
-      mid = L + ((R - L) >>> 1);
-      if (mid == L) mid++;
-      if (getApproxRank(mid) <= K) L = mid;
-      else R = mid - 1;
+  public long findMaxValueWithRank(long k) {
+    long l = Long.MIN_VALUE;
+    long r = Long.MAX_VALUE;
+    long mid;
+    while (l < r) {
+      mid = l + ((r - l) >>> 1);
+      if (mid == l) {
+        mid++;
+      }
+      if (getApproxRank(mid) <= k) {
+        l = mid;
+      } else {
+        r = mid - 1;
+      }
     }
-    return L;
-  }
-
-  public long findMinValueWithRank(long K) {
-    long L = Long.MIN_VALUE, R = Long.MAX_VALUE, mid;
-    while (L < R) {
-      mid = L + ((R - L) >>> 1);
-      if (mid == R) mid--;
-      if (getApproxRank(mid) >= K) R = mid;
-      else L = mid + 1;
+    return l;
+  }
+
+  public long findMinValueWithRank(long k) {
+    long l = Long.MIN_VALUE;
+    long r = Long.MAX_VALUE;
+    long mid;
+    while (l < r) {
+      mid = l + ((r - l) >>> 1);
+      if (mid == r) {
+        mid--;
+      }
+      if (getApproxRank(mid) >= k) {
+        r = mid;
+      } else {
+        l = mid + 1;
+      }
     }
-    return L;
+    return l;
   }
 
   public long getN() {
-    return N;
+    return n;
   }
 
   public int getMaxMemoryNum() {
@@ -158,15 +164,16 @@ public abstract class KLLSketchForQuantile {
   }
 
   public boolean exactResult() {
-    return this.N == this.getNumLen();
+    return this.n == this.getNumLen();
   }
 
-  public long getExactResult(int K) {
-    int L = levelPos[0], R = levelPos[1];
+  public long getExactResult(int k) {
+    int l = levelPos[0];
+    int r = levelPos[1];
     if (!level0Sorted) {
-      Arrays.sort(num, L, R);
+      Arrays.sort(num, l, r);
       level0Sorted = true;
     }
-    return num[L + K];
+    return num[l + k];
   }
 }
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/MADSketch.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/MADSketch.java
index ab8bca6dfa4..34aab9d70fe 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/MADSketch.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/MADSketch.java
@@ -16,11 +16,10 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.dprofile.util;
 
 import org.eclipse.collections.impl.map.mutable.UnifiedMap;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import java.util.Arrays;
 import java.util.Comparator;
@@ -29,43 +28,41 @@ import java.util.NoSuchElementException;
 
 public class MADSketch {
 
-  private long zero_count;
+  private long zeroCount;
   private double beta;
-  private final double[] valid_range;
+  private final double[] validRange;
 
   private final double alpha;
   private final double gamma;
   private final double multiplier;
 
-  private final UnifiedMap<Integer, Long> positive_buckets;
-  private final UnifiedMap<Integer, Long> negative_buckets;
+  private final UnifiedMap<Integer, Long> positiveBuckets;
+  private final UnifiedMap<Integer, Long> negativeBuckets;
 
   private static final double MIN_POSITIVE_VALUE = 1e-6;
 
-  private static final Logger logger = LoggerFactory.getLogger(MADSketch.class);
-
   public MADSketch(double alpha) {
     this.alpha = alpha;
 
     this.gamma = 2 * alpha / (1 - alpha) + 1;
     this.multiplier = Math.log(Math.E) / (Math.log1p(gamma - 1));
     this.beta = 1;
-    this.positive_buckets = new UnifiedMap<>();
-    this.negative_buckets = new UnifiedMap<>();
-    this.zero_count = 0;
-    this.valid_range = new double[6];
+    this.positiveBuckets = new UnifiedMap<>();
+    this.negativeBuckets = new UnifiedMap<>();
+    this.zeroCount = 0;
+    this.validRange = new double[6];
   }
 
   public void insert(double v) {
     if (Double.isFinite(v)) {
       if (v > MIN_POSITIVE_VALUE) {
         int i = (int) Math.ceil(Math.log(v) * multiplier);
-        positive_buckets.put(i, positive_buckets.getOrDefault(i, 0L) + 1);
+        positiveBuckets.put(i, positiveBuckets.getOrDefault(i, 0L) + 1);
       } else if (v < -MIN_POSITIVE_VALUE) {
         int i = (int) Math.ceil(Math.log(-v) * multiplier);
-        negative_buckets.put(i, negative_buckets.getOrDefault(i, 0L) + 1);
+        negativeBuckets.put(i, negativeBuckets.getOrDefault(i, 0L) + 1);
       } else {
-        zero_count++;
+        zeroCount++;
       }
     }
   }
@@ -83,10 +80,10 @@ public class MADSketch {
     insert(v);
   }
 
-  private Bucket[] union_buckets() {
-    Bucket[] buckets = new Bucket[sketch_size()];
+  private Bucket[] unionBuckets() {
+    Bucket[] buckets = new Bucket[sketchSize()];
     int i = 0;
-    for (Map.Entry<Integer, Long> e : positive_buckets.entrySet()) {
+    for (Map.Entry<Integer, Long> e : positiveBuckets.entrySet()) {
       buckets[i++] =
           new Bucket(
               e.getKey(),
@@ -94,7 +91,7 @@ public class MADSketch {
               Math.pow(gamma, e.getKey()),
               e.getValue());
     }
-    for (Map.Entry<Integer, Long> e : negative_buckets.entrySet()) {
+    for (Map.Entry<Integer, Long> e : negativeBuckets.entrySet()) {
       buckets[i++] =
           new Bucket(
               e.getKey(),
@@ -102,22 +99,22 @@ public class MADSketch {
               -Math.pow(gamma, (double) e.getKey() - 1.0),
               e.getValue());
     }
-    if (zero_count > 0) {
-      buckets[i] = new Bucket(0, 0, 0, zero_count);
+    if (zeroCount > 0) {
+      buckets[i] = new Bucket(0, 0, 0, zeroCount);
     }
-    Arrays.sort(buckets, Comparator.comparingDouble(o -> o.lower_bound));
+    Arrays.sort(buckets, Comparator.comparingDouble(o -> o.lowerBound));
     return buckets;
   }
 
-  public long total_count() {
-    return positive_buckets.values().stream().mapToLong(l -> l).sum()
-        + negative_buckets.values().stream().mapToLong(l -> l).sum()
-        + zero_count;
+  public long totalCount() {
+    return positiveBuckets.values().stream().mapToLong(l -> l).sum()
+        + negativeBuckets.values().stream().mapToLong(l -> l).sum()
+        + zeroCount;
   }
 
-  private int find_p_index(Bucket[] buckets, long total_count) {
+  private int findPIndex(Bucket[] buckets, long totalCount) {
     long count = 0;
-    double rank = 0.5 * (total_count - 1);
+    double rank = 0.5 * (totalCount - 1);
     for (int i = 0; i < buckets.length; ++i) {
       count += buckets[i].count;
       if (count > rank) {
@@ -127,15 +124,15 @@ public class MADSketch {
     return -1;
   }
 
-  private int find_q_index(int p, Bucket[] buckets, long total_count) {
+  private int findQIndex(int p, Bucket[] buckets, long totalCount) {
     int q = p;
     long count = buckets[p].count;
-    double rank = 0.5 * (total_count - 1);
+    double rank = 0.5 * (totalCount - 1);
     int l = p - 1;
     int r = p + 1;
     while (count <= rank && l >= 0 && r < buckets.length) {
-      if (buckets[p].lower_bound - buckets[l].upper_bound
-          < buckets[r].lower_bound - buckets[p].upper_bound) {
+      if (buckets[p].lowerBound - buckets[l].upperBound
+          < buckets[r].lowerBound - buckets[p].upperBound) {
         q = l--;
       } else {
         q = r++;
@@ -153,30 +150,30 @@ public class MADSketch {
       count += buckets[q].count;
     }
 
-    double m_lower_bound = buckets[p].lower_bound + buckets[p].upper_bound - buckets[q].upper_bound;
-    double m_upper_bound = buckets[p].lower_bound + buckets[p].upper_bound - buckets[q].lower_bound;
+    double mLowerBound = buckets[p].lowerBound + buckets[p].upperBound - buckets[q].upperBound;
+    double mUpperBound = buckets[p].lowerBound + buckets[p].upperBound - buckets[q].lowerBound;
     if (p > q) {
       r--;
-      if (buckets[r].lower_bound <= m_lower_bound && buckets[r].upper_bound >= m_upper_bound) {
+      if (buckets[r].lowerBound <= mLowerBound && buckets[r].upperBound >= mUpperBound) {
         q = r;
       }
     } else if (p < q) {
       l++;
-      if (buckets[l].lower_bound <= m_lower_bound && buckets[l].upper_bound >= m_upper_bound) {
+      if (buckets[l].lowerBound <= mLowerBound && buckets[l].upperBound >= mUpperBound) {
         q = l;
       }
     }
     return q;
   }
 
-  private void setValid_range(Bucket p, Bucket q) {
-    valid_range[0] = p.lower_bound;
-    valid_range[1] = p.upper_bound;
-    valid_range[2] = p.lower_bound + q.lower_bound - p.upper_bound;
-    valid_range[3] = p.upper_bound + q.upper_bound - p.lower_bound;
-    valid_range[4] = 2 * p.lower_bound - q.upper_bound;
-    valid_range[5] = 2 * p.upper_bound - q.lower_bound;
-    Arrays.sort(valid_range);
+  private void setValidRange(Bucket p, Bucket q) {
+    validRange[0] = p.lowerBound;
+    validRange[1] = p.upperBound;
+    validRange[2] = p.lowerBound + q.lowerBound - p.upperBound;
+    validRange[3] = p.upperBound + q.upperBound - p.lowerBound;
+    validRange[4] = 2 * p.lowerBound - q.upperBound;
+    validRange[5] = 2 * p.upperBound - q.lowerBound;
+    Arrays.sort(validRange);
   }
 
   private double minDelta(double delta1, double delta2) {
@@ -195,44 +192,44 @@ public class MADSketch {
 
   public Mad getMad() {
     beta = 1;
-    Bucket[] buckets = union_buckets();
-    long total_count = total_count();
-    int p_index = find_p_index(buckets, total_count);
+    Bucket[] buckets = unionBuckets();
+    long totalCount = totalCount();
+    int pIndex = findPIndex(buckets, totalCount);
 
-    if (p_index == -1) {
+    if (pIndex == -1) {
       throw new NoSuchElementException("No values in the time series");
     }
 
-    int q_index = find_q_index(p_index, buckets, total_count);
-    Bucket p = buckets[p_index];
-    Bucket q = buckets[q_index];
+    int qIndex = findQIndex(pIndex, buckets, totalCount);
+    Bucket p = buckets[pIndex];
+    Bucket q = buckets[qIndex];
 
-    if (p.lower_bound * q.lower_bound > 0) {
-      if (p.lower_bound == q.lower_bound) {
+    if (p.lowerBound * q.lowerBound > 0) {
+      if (p.lowerBound == q.lowerBound) {
         return new Mad(0, Double.MAX_VALUE);
       } else {
         double mad =
             2
-                * (p.upper_bound - q.lower_bound)
-                * (p.lower_bound - q.upper_bound)
-                / ((gamma + 1) * Math.abs(p.lower_bound - q.lower_bound));
-        double gamma_p_q = Math.max(p.upper_bound / q.upper_bound, q.upper_bound / p.upper_bound);
+                * (p.upperBound - q.lowerBound)
+                * (p.lowerBound - q.upperBound)
+                / ((gamma + 1) * Math.abs(p.lowerBound - q.lowerBound));
+        double gammaPQ = Math.max(p.upperBound / q.upperBound, q.upperBound / p.upperBound);
         double delta;
-        if (Math.abs(p.lower_bound) < Math.abs(q.lower_bound)) {
+        if (Math.abs(p.lowerBound) < Math.abs(q.lowerBound)) {
           delta =
               minDelta(
-                  gamma_p_q / Math.pow(gamma, 2) - 1 / gamma + Math.pow(gamma, -3),
-                  1 / (Math.pow(gamma, 3) - gamma_p_q * gamma + Math.pow(gamma, 2)));
+                  gammaPQ / Math.pow(gamma, 2) - 1 / gamma + Math.pow(gamma, -3),
+                  1 / (Math.pow(gamma, 3) - gammaPQ * gamma + Math.pow(gamma, 2)));
         } else {
           delta =
               minDelta(
-                  Math.pow(gamma, -2) + Math.pow(gamma, -3) - 1 / (gamma_p_q * gamma),
-                  1 / (Math.pow(gamma, 2) / gamma_p_q + Math.pow(gamma, 3) - gamma));
+                  Math.pow(gamma, -2) + Math.pow(gamma, -3) - 1 / (gammaPQ * gamma),
+                  1 / (Math.pow(gamma, 2) / gammaPQ + Math.pow(gamma, 3) - gamma));
         }
         beta = 1 - 2 / (1 + delta);
-        if (need_two_pass()) {
-          setValid_range(p, q);
-          return new Mad(mad, (1 + 2 / (gamma_p_q - 1)) * alpha);
+        if (needTwoPass()) {
+          setValidRange(p, q);
+          return new Mad(mad, (1 + 2 / (gammaPQ - 1)) * alpha);
         } else {
           return new Mad(0, Double.MAX_VALUE);
         }
@@ -241,17 +238,17 @@ public class MADSketch {
       double mad =
           2
               * Math.max(
-                  Math.abs(p.upper_bound - q.lower_bound), Math.abs(q.upper_bound - p.lower_bound))
+                  Math.abs(p.upperBound - q.lowerBound), Math.abs(q.upperBound - p.lowerBound))
               / (gamma + 1);
       return new Mad(mad, alpha);
     }
   }
 
-  public int sketch_size() {
-    return positive_buckets.size() + negative_buckets.size() + (zero_count == 0 ? 0 : 1);
+  public int sketchSize() {
+    return positiveBuckets.size() + negativeBuckets.size() + (zeroCount == 0 ? 0 : 1);
   }
 
-  public boolean need_two_pass() {
+  public boolean needTwoPass() {
     return beta > 0 && beta < 1;
   }
 
@@ -259,29 +256,21 @@ public class MADSketch {
     return beta;
   }
 
-  public double[] getValid_range() {
-    return valid_range;
-  }
-
-  public void show(Bucket[] buckets) {
-    for (Bucket bucket : buckets) {
-      if (logger.isDebugEnabled()) {
-        logger.debug(bucket.index + ": " + bucket.count);
-      }
-    }
+  public double[] getValidRange() {
+    return validRange;
   }
 
   private static class Bucket {
 
     int index;
-    double lower_bound;
-    double upper_bound;
+    double lowerBound;
+    double upperBound;
     long count;
 
-    Bucket(int index, double lower_bound, double upper_bound, long count) {
+    Bucket(int index, double lowerBound, double upperBound, long count) {
       this.index = index;
-      this.lower_bound = lower_bound;
-      this.upper_bound = upper_bound;
+      this.lowerBound = lowerBound;
+      this.upperBound = upperBound;
       this.count = count;
     }
   }
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/Mad.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/Mad.java
index 69acfe17b7f..2e740820a4b 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/Mad.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/Mad.java
@@ -16,19 +16,20 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.dprofile.util;
 
 /** Interface for getting MAD with error. */
 public class Mad {
   public final double result;
-  public final double error_bound;
+  public final double errorBound;
 
-  public Mad(double result, double error_bound) {
+  public Mad(double result, double errorBound) {
     this.result = result;
-    this.error_bound = error_bound;
+    this.errorBound = errorBound;
   }
 
   public String toString() {
-    return result + " - " + error_bound;
+    return result + " - " + errorBound;
   }
 }
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/MaxSelector.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/MaxSelector.java
index 9f2cdddda2a..b35f5447413 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/MaxSelector.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/MaxSelector.java
@@ -16,9 +16,10 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.dprofile.util;
 
-/** Util for Mode */
+/** Util for Mode. */
 public class MaxSelector {
   int times;
   int intValue;
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/Resampler.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/Resampler.java
index 3c347e38796..2942929abd2 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/Resampler.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/Resampler.java
@@ -42,8 +42,8 @@ public class Resampler {
   private final String aggregator; // method to aggregate
   private final String interpolator; // method to interpolate
   private long currentTime; // start time of the window, left close & right open
-  private long startTime,
-      endTime; // start time (contained) and end time (not contained) of resampling
+  private long startTime;
+  private long endTime; // start time (contained) and end time (not contained) of resampling
   private boolean outer = true; // if to use outer interpolate
 
   public Resampler(long newPeriod, String aggregator, String interpolator) {
@@ -60,7 +60,7 @@ public class Resampler {
     this.currentTime = this.startTime;
   }
 
-  /** 加入新的数据点 insert new datapoint */
+  /** 加入新的数据点 insert new datapoint. */
   public void insert(long time, double value) {
     if (Double.isNaN(value)
         || (startTime > 0 && time < startTime)
@@ -79,7 +79,7 @@ public class Resampler {
     valueWindow.add(value);
   }
 
-  /** process all data in buffer */
+  /** process all data in buffer. */
   public void flush() {
     do { // process data in the last window in first cycle
       downSample();
@@ -164,7 +164,6 @@ public class Resampler {
     double ret = Double.NaN;
     switch (interpolator) {
       case "nan":
-        ret = Double.NaN;
         break;
       case "ffill":
         if (t >= source.get(1).time) {
@@ -192,22 +191,22 @@ public class Resampler {
     return ret;
   }
 
-  /** judge if there is a next point in the buffer */
+  /** judge if there is a next point in the buffer. */
   public boolean hasNext() {
     return !timeBuffer.isEmpty();
   }
 
-  /** return the timestamp of the current point in buffer */
+  /** return the timestamp of the current point in buffer. */
   public long getOutTime() {
     return timeBuffer.getHead();
   }
 
-  /** return the value of the current point in buffer */
+  /** return the value of the current point in buffer. */
   public double getOutValue() {
     return valueBuffer.getHead();
   }
 
-  /** move to next data point in buffer */
+  /** move to next data point in buffer. */
   public void next() {
     timeBuffer.pop();
     valueBuffer.pop();
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/Segment.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/Segment.java
index 04220f31f09..d4e4c8bf495 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/Segment.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/Segment.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.dprofile.util;
 
 import org.apache.iotdb.library.util.LinearRegression;
@@ -25,10 +26,15 @@ import org.apache.commons.lang3.ArrayUtils;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.List;
 
 /** Util for segment. */
 public class Segment {
-  private static double calculate_error(double[] y1, double[] y2) throws Exception {
+  private Segment() {
+    throw new IllegalStateException("Utility class");
+  }
+
+  private static double calculateError(double[] y1, double[] y2) throws Exception {
     double[] y = ArrayUtils.addAll(y1, y2);
     int l = y.length;
     double[] x = new double[l];
@@ -39,123 +45,120 @@ public class Segment {
     return linearFit.getMAbsE();
   }
 
-  public static ArrayList<double[]> bottom_up(double[] value, double max_error) throws Exception {
-    ArrayList<double[]> seg_ts = new ArrayList<>();
+  public static List<double[]> bottomUp(double[] value, double maxError) throws Exception {
+    List<double[]> segTs = new ArrayList<>();
     if (value.length <= 3) {
-      ArrayList<double[]> ret = new ArrayList<>();
+      List<double[]> ret = new ArrayList<>();
       ret.add(value);
       return ret;
     }
     if (value.length % 2 == 0) {
       for (int i = 0; i < value.length; i += 2) {
-        seg_ts.add(Arrays.copyOfRange(value, i, i + 2));
+        segTs.add(Arrays.copyOfRange(value, i, i + 2));
       }
     } else {
       for (int i = 0; i < value.length - 3; i += 2) {
-        seg_ts.add(Arrays.copyOfRange(value, i, i + 2));
+        segTs.add(Arrays.copyOfRange(value, i, i + 2));
       }
-      seg_ts.add(Arrays.copyOfRange(value, value.length - 3, value.length));
+      segTs.add(Arrays.copyOfRange(value, value.length - 3, value.length));
     }
-    ArrayList<Double> merge_cost = new ArrayList<>();
-    for (int i = 0; i < seg_ts.size() - 1; i++) {
-      merge_cost.add(calculate_error(seg_ts.get(i), seg_ts.get(i + 1)));
+    ArrayList<Double> mergeCost = new ArrayList<>();
+    for (int i = 0; i < segTs.size() - 1; i++) {
+      mergeCost.add(calculateError(segTs.get(i), segTs.get(i + 1)));
     }
-    while (Collections.min(merge_cost) < max_error) {
-      int index = merge_cost.indexOf(Collections.min(merge_cost));
-      seg_ts.set(index, ArrayUtils.addAll(seg_ts.get(index), seg_ts.get(index + 1)));
-      seg_ts.remove(index + 1);
-      merge_cost.remove(index);
-      if (seg_ts.size() == 1) {
+    while (Collections.min(mergeCost) < maxError) {
+      int index = mergeCost.indexOf(Collections.min(mergeCost));
+      segTs.set(index, ArrayUtils.addAll(segTs.get(index), segTs.get(index + 1)));
+      segTs.remove(index + 1);
+      mergeCost.remove(index);
+      if (segTs.size() == 1) {
         break;
       }
-      if (index + 1 < seg_ts.size()) {
-        merge_cost.set(index, calculate_error(seg_ts.get(index), seg_ts.get(index + 1)));
+      if (index + 1 < segTs.size()) {
+        mergeCost.set(index, calculateError(segTs.get(index), segTs.get(index + 1)));
       }
       if (index > 0) {
-        merge_cost.set(index - 1, calculate_error(seg_ts.get(index - 1), seg_ts.get(index)));
+        mergeCost.set(index - 1, calculateError(segTs.get(index - 1), segTs.get(index)));
       }
     }
-    return seg_ts;
+    return segTs;
   }
 
-  private static double[] best_line(
-      double max_error, double[] input_df, double[] w, int start_idx, double upper_bound)
+  private static double[] bestLine(
+      double maxError, double[] inputDf, double[] w, int startIdx, double upperBound)
       throws Exception {
     double error = 0.0;
-    int idx = start_idx + w.length;
-    double[] S_prev = w.clone();
-    if (idx >= input_df.length) {
-      return S_prev;
+    int idx = startIdx + w.length;
+    double[] sPrev = w.clone();
+    if (idx >= inputDf.length) {
+      return sPrev;
     }
-    while (error <= max_error) {
-      double[] S = ArrayUtils.addAll(S_prev, input_df[idx]);
+    while (error <= maxError) {
+      double[] s = ArrayUtils.addAll(sPrev, inputDf[idx]);
       idx++;
-      double[] times = new double[S.length];
+      double[] times = new double[s.length];
       for (int i = 0; i < times.length; i++) {
         times[i] = i;
       }
-      error = new LinearRegression(times, S).getMAbsE();
-      if (error <= max_error) {
-        S_prev = S.clone();
+      error = new LinearRegression(times, s).getMAbsE();
+      if (error <= maxError) {
+        sPrev = s.clone();
       }
-      if (S_prev.length > upper_bound || idx >= input_df.length) {
+      if (sPrev.length > upperBound || idx >= inputDf.length) {
         break;
       }
     }
-    return S_prev;
+    return sPrev;
   }
 
-  public static double[] approximated_segment(double[] in_seq) throws Exception {
-    if (in_seq.length <= 2) {
-      return in_seq;
+  public static double[] approximatedSegment(double[] inSeq) throws Exception {
+    if (inSeq.length <= 2) {
+      return inSeq;
     }
-    double[] times = new double[in_seq.length];
+    double[] times = new double[inSeq.length];
     for (int i = 0; i < times.length; i++) {
       times[i] = i;
     }
-    return new LinearRegression(times, in_seq).getYhead();
+    return new LinearRegression(times, inSeq).getYhead();
   }
 
-  private static ArrayList<double[]> swab(
-      double[] input_df, double max_error, int seg_num, int in_window_size) throws Exception {
-    int cur_nr = 0;
-    int w_nr = cur_nr + in_window_size;
-    int tot_size = input_df.length;
-    double[] w = Arrays.copyOfRange(input_df, cur_nr, w_nr);
-    int lower_bound = w_nr / 2;
-    int upper_bound = 2 * w_nr;
-    ArrayList<double[]> seg_ts = new ArrayList<>();
-    boolean last_run = false;
+  private static List<double[]> swab(double[] inputDf, double maxError, int inWindowSize)
+      throws Exception {
+    int curNr = 0;
+    int wNr = curNr + inWindowSize;
+    int totSize = inputDf.length;
+    double[] w = Arrays.copyOfRange(inputDf, curNr, wNr);
+    int upperBound = 2 * wNr;
+    List<double[]> segTs = new ArrayList<>();
+    boolean lastRun = false;
     while (true) {
-      ArrayList<double[]> T = bottom_up(w, max_error);
-      seg_ts.add(T.get(0));
-      if (cur_nr >= tot_size || last_run) {
-        if (T.size() > 1) {
-          seg_ts.add(approximated_segment(T.get(1)));
+      List<double[]> t = bottomUp(w, maxError);
+      segTs.add(t.get(0));
+      if (curNr >= totSize || lastRun) {
+        if (t.size() > 1) {
+          segTs.add(approximatedSegment(t.get(1)));
         }
         break;
       }
-      cur_nr += T.get(0).length - 1;
-      w_nr = cur_nr + in_window_size;
-      if (input_df.length <= w_nr) {
-        w_nr = -1;
-        last_run = true;
-        w = Arrays.copyOfRange(input_df, cur_nr, input_df.length);
+      curNr += t.get(0).length - 1;
+      wNr = curNr + inWindowSize;
+      if (inputDf.length <= wNr) {
+        lastRun = true;
+        w = Arrays.copyOfRange(inputDf, curNr, inputDf.length);
       } else {
-        w = Arrays.copyOfRange(input_df, cur_nr, w_nr);
+        w = Arrays.copyOfRange(inputDf, curNr, wNr);
       }
       Arrays.sort(w);
-      w = best_line(max_error, input_df, w, cur_nr, upper_bound);
-      if (w.length > upper_bound) {
-        w = Arrays.copyOfRange(w, 0, upper_bound);
+      w = bestLine(maxError, inputDf, w, curNr, upperBound);
+      if (w.length > upperBound) {
+        w = Arrays.copyOfRange(w, 0, upperBound);
       }
     }
-    return seg_ts;
+    return segTs;
   }
 
-  public static ArrayList<double[]> swab_alg(
-      double[] df, long[] timestamp, double max_error, int windowsize) throws Exception {
-    ArrayList<double[]> res_df1 = swab(df, max_error, 10, windowsize);
-    return res_df1;
+  public static List<double[]> swabAlg(double[] df, double maxError, int windowsize)
+      throws Exception {
+    return swab(df, maxError, windowsize);
   }
 }
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/YuleWalker.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/YuleWalker.java
index 0289e450cb4..21ccf7cb661 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/YuleWalker.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/util/YuleWalker.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.dprofile.util;
 
 import org.apache.commons.math3.linear.Array2DRowRealMatrix;
@@ -31,7 +32,7 @@ import java.util.Arrays;
 /** Describe class here. */
 public class YuleWalker {
   public double yuleWalker(double[] x, int order, String method, int n) {
-    double adj_needed = method.equalsIgnoreCase("adjusted") ? 1 : 0;
+    double adjNeeded = method.equalsIgnoreCase("adjusted") ? 1 : 0;
     double[] r = new double[order + 1];
     double squaresumx = 0d;
     for (double v : x) {
@@ -45,16 +46,16 @@ public class YuleWalker {
       for (int i = 0; i < Math.min(t1.length, t2.length); i++) {
         crossmultiplysum += t1[i] * t2[i];
       }
-      r[k] = crossmultiplysum / (n - k * adj_needed);
+      r[k] = crossmultiplysum / (n - k * adjNeeded);
     }
     // R is a toeplitz matrix
-    double[][] R = new double[r.length - 1][r.length - 1];
+    double[][] r2d = new double[r.length - 1][r.length - 1];
     for (int i = 0; i < r.length - 1; i++) {
       for (int j = 0; j < r.length - 1; j++) {
-        R[i][j] = r[Math.abs(i - j)];
+        r2d[i][j] = r[Math.abs(i - j)];
       }
     }
-    RealMatrix a = new Array2DRowRealMatrix(R, true);
+    RealMatrix a = new Array2DRowRealMatrix(r2d, true);
     RealVector b = new ArrayRealVector(Arrays.copyOfRange(r, 1, r.length), true);
     DecompositionSolver solver = new LUDecomposition(a).getSolver();
     try {
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dquality/UDTFCompleteness.java b/library-udf/src/main/java/org/apache/iotdb/library/dquality/UDTFCompleteness.java
index 5d2f4436aaf..e5241062d6c 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dquality/UDTFCompleteness.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dquality/UDTFCompleteness.java
@@ -63,7 +63,7 @@ public class UDTFCompleteness implements UDTF {
   @Override
   public void transform(RowWindow rowWindow, PointCollector collector) throws Exception {
     try {
-      if (rowWindow.windowSize() > TimeSeriesQuality.windowSize) {
+      if (rowWindow.windowSize() > TimeSeriesQuality.WINDOW_SIZE) {
         TimeSeriesQuality tsq = new TimeSeriesQuality(rowWindow.getRowIterator());
         tsq.setDowntime(downtime);
         tsq.timeDetect();
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dquality/UDTFConsistency.java b/library-udf/src/main/java/org/apache/iotdb/library/dquality/UDTFConsistency.java
index af269be8bd0..52f27876468 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dquality/UDTFConsistency.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dquality/UDTFConsistency.java
@@ -62,7 +62,7 @@ public class UDTFConsistency implements UDTF {
   @Override
   public void transform(RowWindow rowWindow, PointCollector collector) throws Exception {
     try {
-      if (rowWindow.windowSize() > TimeSeriesQuality.windowSize) {
+      if (rowWindow.windowSize() > TimeSeriesQuality.WINDOW_SIZE) {
         TimeSeriesQuality tsq = new TimeSeriesQuality(rowWindow.getRowIterator());
         tsq.timeDetect();
         collector.putDouble(rowWindow.getRow(0).getTime(), tsq.getConsistency());
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dquality/UDTFTimeliness.java b/library-udf/src/main/java/org/apache/iotdb/library/dquality/UDTFTimeliness.java
index e1ea42dc095..8ac93e1bf54 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dquality/UDTFTimeliness.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dquality/UDTFTimeliness.java
@@ -61,7 +61,7 @@ public class UDTFTimeliness implements UDTF {
   @Override
   public void transform(RowWindow rowWindow, PointCollector collector) throws Exception {
     try {
-      if (rowWindow.windowSize() > TimeSeriesQuality.windowSize) {
+      if (rowWindow.windowSize() > TimeSeriesQuality.WINDOW_SIZE) {
         TimeSeriesQuality tsq = new TimeSeriesQuality(rowWindow.getRowIterator());
         tsq.timeDetect();
         collector.putDouble(rowWindow.getRow(0).getTime(), tsq.getTimeliness());
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dquality/UDTFValidity.java b/library-udf/src/main/java/org/apache/iotdb/library/dquality/UDTFValidity.java
index dc848fd24f2..7e7028d382f 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dquality/UDTFValidity.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dquality/UDTFValidity.java
@@ -61,7 +61,7 @@ public class UDTFValidity implements UDTF {
   @Override
   public void transform(RowWindow rowWindow, PointCollector collector) throws Exception {
     try {
-      if (rowWindow.windowSize() > TimeSeriesQuality.windowSize) {
+      if (rowWindow.windowSize() > TimeSeriesQuality.WINDOW_SIZE) {
         TimeSeriesQuality tsq = new TimeSeriesQuality(rowWindow.getRowIterator());
         tsq.valueDetect();
         collector.putDouble(rowWindow.getRow(0).getTime(), tsq.getValidity());
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dquality/util/TimeSeriesQuality.java b/library-udf/src/main/java/org/apache/iotdb/library/dquality/util/TimeSeriesQuality.java
index e3cf5a56c10..0c87ed69cf7 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/dquality/util/TimeSeriesQuality.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dquality/util/TimeSeriesQuality.java
@@ -22,6 +22,7 @@ package org.apache.iotdb.library.dquality.util;
 import org.apache.iotdb.library.util.Util;
 import org.apache.iotdb.udf.api.access.Row;
 import org.apache.iotdb.udf.api.access.RowIterator;
+import org.apache.iotdb.udf.api.exception.UDFException;
 
 import org.apache.commons.math3.stat.descriptive.rank.Median;
 
@@ -29,7 +30,7 @@ import java.util.ArrayList;
 
 /** Class for computing data quality index. */
 public class TimeSeriesQuality {
-  public static final int windowSize = 10;
+  public static final int WINDOW_SIZE = 10;
   private boolean downtime = true; // count for shutdown period
   private int cnt = 0; // total number of points
   private int missCnt = 0; // number of missing points
@@ -50,7 +51,7 @@ public class TimeSeriesQuality {
       Row row = dataIterator.next();
       cnt++;
       double v = Util.getValueAsDouble(row);
-      double t = (double) row.getTime();
+      double t = row.getTime();
       if (Double.isFinite(v)) {
         timeList.add(t);
         originList.add(v);
@@ -65,8 +66,8 @@ public class TimeSeriesQuality {
     processNaN();
   }
 
-  /** linear interpolation of NaN */
-  private void processNaN() throws Exception {
+  /** linear interpolation of NaN. */
+  private void processNaN() throws UDFException {
     int n = origin.length;
     int index1 = 0;
     int index2;
@@ -78,7 +79,7 @@ public class TimeSeriesQuality {
       index2++;
     }
     if (index2 >= n) {
-      throw new Exception("At least two non-NaN values are needed");
+      throw new UDFException("At least two non-NaN values are needed");
     }
     // interpolation at the beginning of the series
     for (int i = 0; i < index2; i++) {
@@ -112,7 +113,7 @@ public class TimeSeriesQuality {
     }
   }
 
-  /** Detect timestamp errors */
+  /** Detect timestamp errors. */
   public void timeDetect() {
     // compute interval properties
     double[] interval = Util.variation(time);
@@ -121,7 +122,7 @@ public class TimeSeriesQuality {
     // find timestamp anomalies
     ArrayList<Double> window = new ArrayList<>();
     int i;
-    for (i = 0; i < Math.min(time.length, windowSize); i++) { // fill initial data
+    for (i = 0; i < Math.min(time.length, WINDOW_SIZE); i++) { // fill initial data
       window.add(time[i]);
     }
     while (window.size() > 1) {
@@ -150,7 +151,7 @@ public class TimeSeriesQuality {
         missCnt += (Math.round(times - 1) - temp);
       }
       window.remove(0); // remove processed points
-      while (window.size() < windowSize && i < time.length) {
+      while (window.size() < WINDOW_SIZE && i < time.length) {
         // fill into the window
         window.add(time[i]);
         i++;
@@ -158,7 +159,7 @@ public class TimeSeriesQuality {
     }
   }
 
-  /** preparation for validity */
+  /** preparation for validity. */
   public void valueDetect() {
     int k = 3;
     valueCnt = findOutliers(origin, k);
@@ -173,7 +174,7 @@ public class TimeSeriesQuality {
     speedchangeCnt = findOutliers(speedchange, k);
   }
 
-  /** return number of points lie out of median +- k * MAD */
+  /** return number of points lie out of median +- k * MAD. */
   private int findOutliers(double[] value, double k) {
     Median median = new Median();
     double mid = median.evaluate(value);
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/drepair/UDTFTimestampRepair.java b/library-udf/src/main/java/org/apache/iotdb/library/drepair/UDTFTimestampRepair.java
index 4c244ebae3c..78c462e8ea5 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/drepair/UDTFTimestampRepair.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/drepair/UDTFTimestampRepair.java
@@ -27,6 +27,7 @@ import org.apache.iotdb.udf.api.customizer.config.UDTFConfigurations;
 import org.apache.iotdb.udf.api.customizer.parameter.UDFParameterValidator;
 import org.apache.iotdb.udf.api.customizer.parameter.UDFParameters;
 import org.apache.iotdb.udf.api.customizer.strategy.SlidingSizeWindowAccessStrategy;
+import org.apache.iotdb.udf.api.exception.UDFException;
 import org.apache.iotdb.udf.api.type.Type;
 
 /** This function is used for timestamp repair. */
@@ -63,7 +64,7 @@ public class UDTFTimestampRepair implements UDTF {
     } else if ("Cluster".equalsIgnoreCase(intervalMethod)) {
       intervalMode = -3;
     } else {
-      throw new Exception("Illegal method.");
+      throw new UDFException("Illegal method.");
     }
   }
 
@@ -95,7 +96,7 @@ public class UDTFTimestampRepair implements UDTF {
         }
         break;
       default:
-        throw new Exception();
+        throw new UDFException("");
     }
   }
 }
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/drepair/UDTFValueFill.java b/library-udf/src/main/java/org/apache/iotdb/library/drepair/UDTFValueFill.java
index e663cd9d4b5..ab539730acf 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/drepair/UDTFValueFill.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/drepair/UDTFValueFill.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.drepair;
 
 import org.apache.iotdb.library.drepair.util.ARFill;
@@ -32,6 +33,7 @@ import org.apache.iotdb.udf.api.customizer.config.UDTFConfigurations;
 import org.apache.iotdb.udf.api.customizer.parameter.UDFParameterValidator;
 import org.apache.iotdb.udf.api.customizer.parameter.UDFParameters;
 import org.apache.iotdb.udf.api.customizer.strategy.SlidingSizeWindowAccessStrategy;
+import org.apache.iotdb.udf.api.exception.UDFException;
 import org.apache.iotdb.udf.api.type.Type;
 
 /** This function is used to interpolate time series. */
@@ -70,7 +72,7 @@ public class UDTFValueFill implements UDTF {
     } else if ("likelihood".equalsIgnoreCase(method)) {
       vf = new LikelihoodFill(rowWindow.getRowIterator());
     } else {
-      throw new Exception("Illegal method");
+      throw new UDFException("Illegal method");
     }
     vf.fill();
     double[] repaired = vf.getFilled();
@@ -97,7 +99,7 @@ public class UDTFValueFill implements UDTF {
         }
         break;
       default:
-        throw new Exception();
+        throw new UDFException("");
     }
   }
 }
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/drepair/UDTFValueRepair.java b/library-udf/src/main/java/org/apache/iotdb/library/drepair/UDTFValueRepair.java
index 3b2b4988f98..bc73a04e4b1 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/drepair/UDTFValueRepair.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/drepair/UDTFValueRepair.java
@@ -29,6 +29,7 @@ import org.apache.iotdb.udf.api.customizer.config.UDTFConfigurations;
 import org.apache.iotdb.udf.api.customizer.parameter.UDFParameterValidator;
 import org.apache.iotdb.udf.api.customizer.parameter.UDFParameters;
 import org.apache.iotdb.udf.api.customizer.strategy.SlidingSizeWindowAccessStrategy;
+import org.apache.iotdb.udf.api.exception.UDFException;
 import org.apache.iotdb.udf.api.type.Type;
 
 /** This function is used to repair the value of the time series. */
@@ -88,7 +89,7 @@ public class UDTFValueRepair implements UDTF {
       lsGreedy.setCenter(center);
       vr = lsGreedy;
     } else {
-      throw new Exception("Illegal method.");
+      throw new UDFException("Illegal method.");
     }
     vr.repair();
     double[] repaired = vr.getRepaired();
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/ARFill.java b/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/ARFill.java
index a6e8d01ccff..838513d3349 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/ARFill.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/ARFill.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.drepair.util;
 
 import org.apache.iotdb.udf.api.access.RowIterator;
@@ -23,7 +24,6 @@ import org.apache.iotdb.udf.api.exception.UDFException;
 
 public class ARFill extends ValueFill {
   // TODO Higer order AR regression
-  private int order = 1;
   private double theta = 1e10;
 
   public ARFill(RowIterator dataIterator) throws Exception {
@@ -31,18 +31,14 @@ public class ARFill extends ValueFill {
     calMeanAndVar();
   }
 
-  public void setOrder(int order) {
-    this.order = order;
-  }
-
   @Override
   public void fill() throws UDFException {
-    // compute \sum x_t * x_{t-1}
+    // Compute \sum x_t * x_{t-1}.
     double acf = 0;
     double factor = 0;
-    int acf_cnt = 0;
     for (int i = 0; i < original.length - 1; i++) {
-      double left = original[i], right = original[i + 1];
+      double left = original[i];
+      double right = original[i + 1];
       if (Double.isNaN(left)) {
         left = 0;
       }
@@ -51,42 +47,38 @@ public class ARFill extends ValueFill {
       }
       acf += left * right;
       factor += left * left;
-      acf_cnt += 1;
     }
     if (factor == 0d || this.theta >= 1) {
       this.time = new long[] {0};
       this.repaired = new double[] {0D};
       throw new UDFException("Cannot fit AR(1) model. Please try another method.");
     }
-    // acf /= acf_cnt;
     this.theta = acf / factor;
-    double mean_epsilon = 0;
-    double var_epsilon = 0;
-    double cnt_epsilon = 0;
+    double meanEpsilon = 0;
+    double cntEpsilon = 0;
     for (int i = 0; i < original.length - 1; i++) {
-      double left = original[i], right = original[i + 1];
+      double left = original[i];
+      double right = original[i + 1];
       if (Double.isNaN(left) || Double.isNaN(right)) {
         continue;
       }
-      cnt_epsilon += 1;
+      cntEpsilon += 1;
       double epsilon = right - left * this.theta;
-      mean_epsilon += epsilon;
-      var_epsilon += epsilon * epsilon;
+      meanEpsilon += epsilon;
     }
-    if (cnt_epsilon == 0d) {
+    if (cntEpsilon == 0d) {
       this.time = new long[] {0};
       this.repaired = new double[] {0D};
       throw new UDFException("Cannot fit AR(1) model. Please try another method.");
     }
-    mean_epsilon /= cnt_epsilon;
-    var_epsilon /= cnt_epsilon;
+    meanEpsilon /= cntEpsilon;
     for (int i = 0; i < original.length; i++) {
       double yt = original[i];
       if (!Double.isNaN(yt)) {
         repaired[i] = yt;
       } else {
         if (i != 0) {
-          repaired[i] = this.theta * repaired[i - 1] + mean_epsilon;
+          repaired[i] = this.theta * repaired[i - 1] + meanEpsilon;
         } else {
           repaired[i] = this.mean;
         }
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/LikelihoodFill.java b/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/LikelihoodFill.java
index 4e32080d673..9b58ad5627c 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/LikelihoodFill.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/LikelihoodFill.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.drepair.util;
 
 import org.apache.iotdb.udf.api.access.RowIterator;
@@ -71,11 +72,12 @@ public class LikelihoodFill extends ValueFill {
             || Double.isNaN(repaired[currentIndex + 1])) {
           continue;
         }
-        double intervalPrev1 = (double) (time[currentIndex] - time[currentIndex - 1]);
-        double intervalPost1 = (double) (time[currentIndex + 1] - time[currentIndex]);
-        double squareAPrev = 0.0, squareBPrev = 0.0;
+        double intervalPrev1 = (time[currentIndex] - time[currentIndex - 1]);
+        double intervalPost1 = (time[currentIndex + 1] - time[currentIndex]);
+        double squareAPrev = 0.0;
+        double squareBPrev = 0.0;
         if (currentIndex >= 2 && !Double.isNaN(repaired[currentIndex - 2])) {
-          double intervalPrev2 = (double) (time[currentIndex - 2] - time[currentIndex - 1]);
+          double intervalPrev2 = (time[currentIndex - 2] - time[currentIndex - 1]);
           squareAPrev = 1.0 / (intervalPrev1 * intervalPrev1);
           squareBPrev =
               2.0 * repaired[currentIndex - 2] / (intervalPrev2 * intervalPrev1)
@@ -97,9 +99,10 @@ public class LikelihoodFill extends ValueFill {
                     * (intervalPrev1 + intervalPost1)
                     * repaired[currentIndex + 1]
                     / (intervalPrev1 * intervalPost1 * intervalPost1);
-        double squareAPost = 0.0, squareBPost = 0.0;
+        double squareAPost = 0.0;
+        double squareBPost = 0.0;
         if (currentIndex <= n - 3 && !Double.isNaN(repaired[currentIndex + 2])) {
-          double intervalPost2 = (double) (time[currentIndex + 2] - time[currentIndex + 1]);
+          double intervalPost2 = (time[currentIndex + 2] - time[currentIndex + 1]);
           squareAPost = 1.0 / (intervalPost1 * intervalPost1);
           squareBPost =
               2.0 * repaired[currentIndex + 2] / (intervalPost1 * intervalPost2)
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/LinearFill.java b/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/LinearFill.java
index 2698f2341f6..25ce7c2b23c 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/LinearFill.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/LinearFill.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.drepair.util;
 
 import org.apache.iotdb.udf.api.access.RowIterator;
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/LsGreedy.java b/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/LsGreedy.java
index 093c42c3991..92893f18056 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/LsGreedy.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/LsGreedy.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.drepair.util;
 
 import org.apache.iotdb.library.util.Util;
@@ -25,8 +26,9 @@ import java.util.PriorityQueue;
 
 public class LsGreedy extends ValueRepair {
 
-  private double center = 0, sigma;
-  private final double eps = 1e-12;
+  private double center = 0;
+  private double sigma;
+  private static final double EPSILON = 1e-12;
 
   public LsGreedy(RowIterator dataIterator) throws Exception {
     super(dataIterator);
@@ -53,7 +55,7 @@ public class LsGreedy extends ValueRepair {
     }
     while (true) {
       RepairNode top = heap.peek();
-      if (top == null || Math.abs(top.getU() - center) < Math.max(eps, 3 * sigma)) {
+      if (top == null || Math.abs(top.getU() - center) < Math.max(EPSILON, 3 * sigma)) {
         break;
       } // stop greedy algorithm when the heap is empty or all speed changes locate in center±3sigma
       top.modify();
@@ -84,11 +86,11 @@ public class LsGreedy extends ValueRepair {
 
     /**
      * modify values of repaired points, to make the difference of its speed variation and center is
-     * 1 sigma
+     * 1 sigma.
      */
     public void modify() {
       double temp;
-      if (sigma < eps) {
+      if (sigma < EPSILON) {
         temp = Math.abs(u - center);
       } else {
         temp = Math.max(sigma, Math.abs(u - center) / 3);
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/MAFill.java b/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/MAFill.java
index bb8316ca672..11a4e1e7b8f 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/MAFill.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/MAFill.java
@@ -16,16 +16,17 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.drepair.util;
 
 import org.apache.iotdb.udf.api.access.RowIterator;
 
 public class MAFill extends ValueFill {
-  int window_size = 5;
-  double window_sum = 0;
-  int window_cnt = 0;
+  int windowSize = 5;
+  double windowSum = 0;
+  int windowCnt = 0;
   int l = 0;
-  int r = window_size - 1;
+  int r = windowSize - 1;
 
   public MAFill(RowIterator dataIterator) throws Exception {
     super(dataIterator);
@@ -35,20 +36,20 @@ public class MAFill extends ValueFill {
   public void fill() {
     for (int i = l; i < r && i < original.length; i++) {
       if (!Double.isNaN(original[i])) {
-        window_sum += original[i];
-        window_cnt += 1;
+        windowSum += original[i];
+        windowCnt += 1;
       }
     }
     for (int i = 0; i < original.length; i++) {
       if (!Double.isNaN(original[i])) {
         repaired[i] = original[i];
       } else {
-        repaired[i] = window_sum / window_cnt;
+        repaired[i] = windowSum / windowCnt;
       }
-      if (i <= (window_size - 1) / 2 || i >= original.length - (window_size - 1) / 2 - 1) continue;
+      if (i <= (windowSize - 1) / 2 || i >= original.length - (windowSize - 1) / 2 - 1) continue;
       if (!Double.isNaN(original[r])) {
-        window_sum += original[r];
-        window_cnt += 1;
+        windowSum += original[r];
+        windowCnt += 1;
       }
       l += 1;
       r += 1;
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/MeanFill.java b/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/MeanFill.java
index a3ad5c0c342..8f96e87c2f4 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/MeanFill.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/MeanFill.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.drepair.util;
 
 import org.apache.iotdb.udf.api.access.RowIterator;
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/PreviousFill.java b/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/PreviousFill.java
index 5e985ed3376..eb38d217876 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/PreviousFill.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/PreviousFill.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.drepair.util;
 
 import org.apache.iotdb.udf.api.access.RowIterator;
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/Screen.java b/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/Screen.java
index e176646562c..f9105d0eed2 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/Screen.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/Screen.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.drepair.util;
 
 import org.apache.iotdb.library.util.Util;
@@ -29,7 +30,8 @@ import java.util.Arrays;
 
 public class Screen extends ValueRepair {
 
-  private double smin, smax;
+  private double smin;
+  private double smax;
   private double w;
 
   public Screen(RowIterator dataIterator) throws Exception {
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/ScreenFill.java b/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/ScreenFill.java
index e6a387a4b6e..b15ccf24a02 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/ScreenFill.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/ScreenFill.java
@@ -16,11 +16,11 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.drepair.util;
 
 import org.apache.iotdb.library.util.Util;
 import org.apache.iotdb.udf.api.access.RowIterator;
-import org.apache.iotdb.udf.api.exception.UDFException;
 
 import org.apache.commons.lang3.tuple.Pair;
 import org.apache.commons.math3.stat.descriptive.rank.Median;
@@ -31,7 +31,8 @@ import java.util.Arrays;
 // Reference to Screen.java
 public class ScreenFill extends ValueFill {
 
-  private double smin, smax;
+  private double smin;
+  private double smax;
   private double w;
 
   public ScreenFill(RowIterator dataIterator) throws Exception {
@@ -39,21 +40,6 @@ public class ScreenFill extends ValueFill {
     setParameters();
   }
 
-  @Override
-  public long[] getTime() {
-    return super.getTime();
-  }
-
-  @Override
-  public double[] getFilled() {
-    return super.getFilled();
-  }
-
-  @Override
-  public void calMeanAndVar() throws UDFException {
-    super.calMeanAndVar();
-  }
-
   @Override
   public void fill() {
     ArrayList<Pair<Long, Double>> ans = new ArrayList<>();
@@ -102,17 +88,17 @@ public class ScreenFill extends ValueFill {
         count++;
       }
     }
-    double x[] = new double[2 * count];
-    int temp_count = 0;
+    double[] x = new double[2 * count];
+    int tempCount = 0;
     for (int i = 1; i <= m; i++) {
       if (!Double.isNaN(list.get(index + i).getRight())) {
-        x[temp_count] =
+        x[tempCount] =
             list.get(index + i).getRight()
                 + smin * (list.get(index).getLeft() - list.get(index + i).getLeft());
-        x[temp_count + count] =
+        x[tempCount + count] =
             list.get(index + i).getRight()
                 + smax * (list.get(index).getLeft() - list.get(index + i).getLeft());
-        temp_count++;
+        tempCount++;
       }
     }
     Arrays.sort(x);
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/TimestampInterval.java b/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/TimestampInterval.java
index 626e6b51fe1..57feae84229 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/TimestampInterval.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/TimestampInterval.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.drepair.util;
 
 import java.util.ArrayList;
@@ -33,7 +34,7 @@ public class TimestampInterval {
   protected long deltaT;
   protected long start0;
 
-  public TimestampInterval(long[] time, double[] original) throws Exception {
+  public TimestampInterval(long[] time, double[] original) {
     // keep the time series
     this.time = time;
     this.original = original;
@@ -98,7 +99,6 @@ public class TimestampInterval {
   // cluster
   private long getIntervalByCluster() {
     // get array of timestamp intervals
-    HashMap<Object, Integer> map = new LinkedHashMap<>();
     long maxInterval = 0;
     long minInterval = 9999999;
     long[] intervals = new long[n];
@@ -172,17 +172,18 @@ public class TimestampInterval {
       case 2:
         this.start0 = getStart0ByMode();
         break;
+      default:
     }
     return this.start0;
   }
 
   private long getStart0ByLinear() {
-    long sum_ = 0;
+    long sum = 0;
     for (int i = 0; i < n; i++) {
-      sum_ += time[i];
-      sum_ -= this.deltaT * i;
+      sum += time[i];
+      sum -= this.deltaT * i;
     }
-    return sum_ / n;
+    return sum / n;
   }
 
   private long getStart0ByMode() {
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/TimestampRepair.java b/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/TimestampRepair.java
index 494f8936493..d1a856e56a9 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/TimestampRepair.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/TimestampRepair.java
@@ -16,15 +16,13 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.drepair.util;
 
 import org.apache.iotdb.library.util.Util;
 import org.apache.iotdb.udf.api.access.Row;
 import org.apache.iotdb.udf.api.access.RowIterator;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import java.util.ArrayList;
 
 public class TimestampRepair {
@@ -36,7 +34,6 @@ public class TimestampRepair {
   protected double[] repairedValue;
   protected long deltaT;
   protected long start0;
-  private static final Logger logger = LoggerFactory.getLogger(TimestampRepair.class);
 
   public TimestampRepair(RowIterator dataIterator, int intervalMode, int startPointMode)
       throws Exception {
@@ -72,25 +69,25 @@ public class TimestampRepair {
       noRepair();
       return;
     }
-    int n_ = (int) Math.ceil((time[n - 1] - start0) / (double) deltaT + 1.0);
-    repaired = new long[n_];
-    repairedValue = new double[n_];
-    int m_ = this.n;
-    long[][] f = new long[n_ + 1][m_ + 1];
-    int[][] steps = new int[n_ + 1][m_ + 1];
+    int n0 = (int) Math.ceil((time[n - 1] - start0) / (double) deltaT + 1.0);
+    repaired = new long[n0];
+    repairedValue = new double[n0];
+    int m0 = this.n;
+    long[][] f = new long[n0 + 1][m0 + 1];
+    int[][] steps = new int[n0 + 1][m0 + 1];
     // dynamic programming
     int addCostRatio = 100000;
-    for (int i = 0; i < n_ + 1; i++) {
+    for (int i = 0; i < n0 + 1; i++) {
       f[i][0] = (long) addCostRatio * i;
       steps[i][0] = 1;
     }
-    for (int i = 0; i < m_ + 1; i++) {
+    for (int i = 0; i < m0 + 1; i++) {
       f[0][i] = (long) addCostRatio * i;
       steps[0][i] = 2;
     }
 
-    for (int i = 1; i < n_ + 1; i++) {
-      for (int j = 1; j < m_ + 1; j++) {
+    for (int i = 1; i < n0 + 1; i++) {
+      for (int j = 1; j < m0 + 1; j++) {
 
         if (time[j - 1] == start0 + (i - 1) * deltaT) {
           // if timestamps are equal, then temporary minimum operation time equals to matched
@@ -116,53 +113,26 @@ public class TimestampRepair {
       }
     }
 
-    int i = n_;
-    int j = m_;
-    double unionSet = 0;
-    double joinSet = 0;
+    int i = n0;
+    int j = m0;
 
     while (i >= 1 && j >= 1) {
       long ps = start0 + (i - 1) * deltaT;
       if (steps[i][j] == 0) {
         repaired[i - 1] = ps;
         repairedValue[i - 1] = original[j - 1];
-        /*
-        if(logger.isDebugEnabled()){
-          logger.debug(time[j - 1] + "," + ps + "," + original[j - 1]);
-        }
-        */
-        unionSet += 1;
-        joinSet += 1;
         i--;
         j--;
       } else if (steps[i][j] == 1) {
         // add points
         repaired[i - 1] = ps;
         repairedValue[i - 1] = Double.NaN;
-        unionSet += 1;
-        /*
-        if(logger.isDebugEnabled()){
-          logger.debug("add, " + ps + "," + original[j - 1]);
-        }
-        */
         i--;
       } else {
         // delete points
-        unionSet += 1;
-        /*
-        if(logger.isDebugEnabled()){
-          logger.debug(time[j - 1] + ",delete" + "," + original[j - 1]);
-        }
-        */
         j--;
       }
     }
-    /*
-    if(logger.isDebugEnabled()) {
-      logger.debug(joinSet / unionSet);
-      logger.debug(f[n_][m_] / n_);
-    }
-     */
   }
 
   public double[] getRepairedValue() {
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/ValueFill.java b/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/ValueFill.java
index 90b81e81dd2..f21d13fd9f0 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/ValueFill.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/ValueFill.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.drepair.util;
 
 import org.apache.iotdb.library.util.Util;
@@ -31,15 +32,15 @@ public abstract class ValueFill {
   protected double[] original;
   protected double[] repaired;
   protected double mean = 0;
-  protected double var = 0;
-  protected int not_nan_number = 0;
+  protected double variance = 0;
+  protected int notNanNumber = 0;
 
-  public ValueFill(RowIterator dataIterator) throws Exception {
+  protected ValueFill(RowIterator dataIterator) throws Exception {
     ArrayList<Long> timeList = new ArrayList<>();
     ArrayList<Double> originList = new ArrayList<>();
     while (dataIterator.hasNextRow()) {
       Row row = dataIterator.next();
-      Double v = Util.getValueAsDouble(row);
+      double v = Util.getValueAsDouble(row);
       timeList.add(row.getTime());
       if (!Double.isFinite(v)) {
         originList.add(Double.NaN);
@@ -61,24 +62,24 @@ public abstract class ValueFill {
 
   public double[] getFilled() {
     return repaired;
-  };
+  }
 
   public void calMeanAndVar() throws UDFException {
     for (double v : original) {
       if (!Double.isNaN(v)) {
         mean += v;
-        not_nan_number += 1;
+        notNanNumber += 1;
       }
     }
-    if (not_nan_number == 0) {
+    if (notNanNumber == 0) {
       throw new UDFException("All values are NaN");
     }
-    mean /= not_nan_number;
+    mean /= notNanNumber;
     for (double v : original) {
       if (!Double.isNaN(v)) {
-        var += (v - mean) * (v - mean);
+        variance += (v - mean) * (v - mean);
       }
     }
-    var /= not_nan_number;
+    variance /= notNanNumber;
   }
 }
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/ValueRepair.java b/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/ValueRepair.java
index 73a11fb0061..297d87a52e0 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/ValueRepair.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/drepair/util/ValueRepair.java
@@ -16,11 +16,13 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.drepair.util;
 
 import org.apache.iotdb.library.util.Util;
 import org.apache.iotdb.udf.api.access.Row;
 import org.apache.iotdb.udf.api.access.RowIterator;
+import org.apache.iotdb.udf.api.exception.UDFException;
 
 import java.util.ArrayList;
 
@@ -31,7 +33,7 @@ public abstract class ValueRepair {
   protected double[] original;
   protected double[] repaired;
 
-  public ValueRepair(RowIterator dataIterator) throws Exception {
+  protected ValueRepair(RowIterator dataIterator) throws Exception {
     ArrayList<Long> timeList = new ArrayList<>();
     ArrayList<Double> originList = new ArrayList<>();
     while (dataIterator.hasNextRow()) {
@@ -53,8 +55,9 @@ public abstract class ValueRepair {
 
   public abstract void repair();
 
-  private void processNaN() throws Exception {
-    int index1 = 0, index2;
+  private void processNaN() throws UDFException {
+    int index1 = 0;
+    int index2;
     while (index1 < n && Double.isNaN(original[index1])) {
       index1++;
     }
@@ -63,7 +66,7 @@ public abstract class ValueRepair {
       index2++;
     }
     if (index2 >= n) {
-      throw new Exception("At least two non-NaN values are needed");
+      throw new UDFException("At least two non-NaN values are needed");
     }
     for (int i = 0; i < index2; i++) {
       original[i] =
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFDWT.java b/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFDWT.java
index 23f4ab73ecd..c30877a126b 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFDWT.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFDWT.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.frequency;
 
 import org.apache.iotdb.library.frequency.util.DWTUtil;
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFDeconv.java b/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFDeconv.java
index d1db57d890b..b467e2b6be6 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFDeconv.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFDeconv.java
@@ -36,6 +36,8 @@ public class UDTFDeconv implements UDTF {
 
   private final ArrayList<Double> list1 = new ArrayList<>();
   private final ArrayList<Double> list2 = new ArrayList<>();
+  private static final String QUOTINENT_RESULT = "quotinent";
+  private static final String REMAINDER_RESULT = "remainder";
   private String result;
 
   @Override
@@ -46,10 +48,10 @@ public class UDTFDeconv implements UDTF {
         .validateInputSeriesDataType(1, Type.DOUBLE, Type.FLOAT, Type.INT32, Type.INT64)
         .validate(
             x ->
-                ((String) x).equalsIgnoreCase("quotient")
-                    || ((String) x).equalsIgnoreCase("remainder"),
+                ((String) x).equalsIgnoreCase(QUOTINENT_RESULT)
+                    || ((String) x).equalsIgnoreCase(REMAINDER_RESULT),
             "Result should be 'quotient' or 'remainder'.",
-            validator.getParameters().getStringOrDefault("result", "quotient"));
+            validator.getParameters().getStringOrDefault("result", QUOTINENT_RESULT));
   }
 
   @Override
@@ -58,7 +60,7 @@ public class UDTFDeconv implements UDTF {
     configurations.setAccessStrategy(new RowByRowAccessStrategy()).setOutputDataType(Type.DOUBLE);
     list1.clear();
     list2.clear();
-    this.result = parameters.getStringOrDefault("result", "quotient");
+    this.result = parameters.getStringOrDefault("result", QUOTINENT_RESULT);
   }
 
   @Override
@@ -73,10 +75,10 @@ public class UDTFDeconv implements UDTF {
 
   @Override
   public void terminate(PointCollector collector) throws Exception {
-    if (list2.size() == 0) { // Exception: divided by zero
-      throw new Exception("Divided by zero.");
+    if (list2.isEmpty()) { // Exception: divided by zero
+      throw new ArithmeticException("Divided by zero.");
     } else if (list2.size() > list1.size()) { // order of divisor is larger than dividend
-      if (result.equalsIgnoreCase("quotient")) { // quotient
+      if (result.equalsIgnoreCase(QUOTINENT_RESULT)) { // quotient
         collector.putDouble(0, 0);
       } else { // residue
         for (int i = 0; i < list1.size(); i++) {
@@ -94,7 +96,7 @@ public class UDTFDeconv implements UDTF {
           r[i + j] -= q[i] * list2.get(j);
         }
       }
-      if (result.equalsIgnoreCase("quotient")) { // quotient
+      if (result.equalsIgnoreCase(QUOTINENT_RESULT)) { // quotient
         for (int i = 0; i < q.length; i++) {
           collector.putDouble(i, q[i]);
         }
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFFFT.java b/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFFFT.java
index 5ef46a1efab..0e69d0c5042 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFFFT.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFFFT.java
@@ -36,6 +36,7 @@ import org.jtransforms.fft.DoubleFFT_1D;
 /** This function does Fast Fourier Transform for input series. */
 public class UDTFFFT implements UDTF {
 
+  private static final String COMPRESS_PARAM = "compress";
   private boolean compressed;
   private FFTUtil fftutil;
   private final DoubleArrayList list = new DoubleArrayList();
@@ -62,7 +63,7 @@ public class UDTFFFT implements UDTF {
         .validate(
             x -> (double) x > 0 && (double) x <= 1,
             "Compress should be within (0,1].",
-            validator.getParameters().getDoubleOrDefault("compress", 1));
+            validator.getParameters().getDoubleOrDefault(COMPRESS_PARAM, 1));
   }
 
   @Override
@@ -70,8 +71,8 @@ public class UDTFFFT implements UDTF {
       throws Exception {
     configurations.setAccessStrategy(new RowByRowAccessStrategy()).setOutputDataType(Type.DOUBLE);
     String result = parameters.getStringOrDefault("result", "abs");
-    this.compressed = parameters.hasAttribute("compress");
-    double compressRate = parameters.getDoubleOrDefault("compress", 1);
+    this.compressed = parameters.hasAttribute(COMPRESS_PARAM);
+    double compressRate = parameters.getDoubleOrDefault(COMPRESS_PARAM, 1);
     this.fftutil = new FFTUtil(result, compressRate);
   }
 
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFHighPass.java b/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFHighPass.java
index c2af7d6d038..34b509f9f21 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFHighPass.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFHighPass.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.frequency;
 
 import org.apache.iotdb.library.util.Util;
@@ -35,6 +36,7 @@ import org.jtransforms.fft.DoubleFFT_1D;
 /** This function filters high frequency components. */
 public class UDTFHighPass implements UDTF {
 
+  private static final String WPASS_PARAM = "wpass";
   private double wpass;
   private final DoubleArrayList valueList = new DoubleArrayList();
   private final LongArrayList timeList = new LongArrayList();
@@ -44,18 +46,18 @@ public class UDTFHighPass implements UDTF {
     validator
         .validateInputSeriesNumber(1)
         .validateInputSeriesDataType(0, Type.DOUBLE, Type.FLOAT, Type.INT32, Type.INT64)
-        .validateRequiredAttribute("wpass")
+        .validateRequiredAttribute(WPASS_PARAM)
         .validate(
             x -> (double) x > 0 && (double) x < 1,
             "Wpass should be within (0,1).",
-            validator.getParameters().getDouble("wpass"));
+            validator.getParameters().getDouble(WPASS_PARAM));
   }
 
   @Override
   public void beforeStart(UDFParameters parameters, UDTFConfigurations configurations)
       throws Exception {
     configurations.setAccessStrategy(new RowByRowAccessStrategy()).setOutputDataType(Type.DOUBLE);
-    this.wpass = parameters.getDouble("wpass");
+    this.wpass = parameters.getDouble(WPASS_PARAM);
   }
 
   @Override
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFIDWT.java b/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFIDWT.java
index f7f987dcda9..4b6feb7199c 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFIDWT.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFIDWT.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.frequency;
 
 import org.apache.iotdb.library.frequency.util.DWTUtil;
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFIFFT.java b/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFIFFT.java
index d90108af251..38a655f7b2c 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFIFFT.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFIFFT.java
@@ -38,6 +38,7 @@ import java.text.SimpleDateFormat;
 /** This function does Inverse Fast Fourier Transform for input series. */
 public class UDTFIFFT implements UDTF {
 
+  private static final String START_PARAM = "start";
   private final DoubleArrayList real = new DoubleArrayList();
   private final DoubleArrayList imag = new DoubleArrayList();
   private final IntArrayList time = new IntArrayList();
@@ -54,11 +55,11 @@ public class UDTFIFFT implements UDTF {
             "interval should be a time period whose unit is ms, s, m, h, d.",
             Util.parseTime(validator.getParameters().getStringOrDefault("interval", "1s")));
     SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-    if (validator.getParameters().hasAttribute("start")) {
+    if (validator.getParameters().hasAttribute(START_PARAM)) {
       validator.validate(
           x -> (long) x > 0,
           "start should conform to the format yyyy-MM-dd HH:mm:ss.",
-          format.parse(validator.getParameters().getString("start")).getTime());
+          format.parse(validator.getParameters().getString(START_PARAM)).getTime());
     }
   }
 
@@ -69,8 +70,8 @@ public class UDTFIFFT implements UDTF {
     this.interval = Util.parseTime(parameters.getStringOrDefault("interval", "1s"));
     SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
     this.start = 0;
-    if (parameters.hasAttribute("start")) {
-      this.start = format.parse(parameters.getString("start")).getTime();
+    if (parameters.hasAttribute(START_PARAM)) {
+      this.start = format.parse(parameters.getString(START_PARAM)).getTime();
     }
   }
 
@@ -89,7 +90,7 @@ public class UDTFIFFT implements UDTF {
   @Override
   public void terminate(PointCollector collector) throws Exception {
     int n = time.get(time.size() - 1) + 1;
-    double a[] = new double[n * 2];
+    double[] a = new double[n * 2];
     for (int i = 0; i < time.size(); i++) {
       int k = time.get(i);
       a[k * 2] = real.get(i);
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFLowPass.java b/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFLowPass.java
index b5d6c7ad863..b5d77cab4cb 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFLowPass.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFLowPass.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.frequency;
 
 import org.apache.iotdb.library.util.Util;
@@ -35,6 +36,7 @@ import org.jtransforms.fft.DoubleFFT_1D;
 /** This function filters high frequency components. */
 public class UDTFLowPass implements UDTF {
 
+  private static final String WPASS_PARAM = "wpass";
   private double wpass;
   private final DoubleArrayList valueList = new DoubleArrayList();
   private final LongArrayList timeList = new LongArrayList();
@@ -44,18 +46,18 @@ public class UDTFLowPass implements UDTF {
     validator
         .validateInputSeriesNumber(1)
         .validateInputSeriesDataType(0, Type.DOUBLE, Type.FLOAT, Type.INT32, Type.INT64)
-        .validateRequiredAttribute("wpass")
+        .validateRequiredAttribute(WPASS_PARAM)
         .validate(
             x -> (double) x > 0 && (double) x < 1,
             "Wpass should be within (0,1).",
-            validator.getParameters().getDouble("wpass"));
+            validator.getParameters().getDouble(WPASS_PARAM));
   }
 
   @Override
   public void beforeStart(UDFParameters parameters, UDTFConfigurations configurations)
       throws Exception {
     configurations.setAccessStrategy(new RowByRowAccessStrategy()).setOutputDataType(Type.DOUBLE);
-    this.wpass = parameters.getDouble("wpass");
+    this.wpass = parameters.getDouble(WPASS_PARAM);
   }
 
   @Override
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/frequency/util/DWTUtil.java b/library-udf/src/main/java/org/apache/iotdb/library/frequency/util/DWTUtil.java
index ef72e6a48ad..35d2863592d 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/frequency/util/DWTUtil.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/frequency/util/DWTUtil.java
@@ -16,16 +16,17 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.frequency.util;
 
-import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.List;
 
-/** Util for UDTFDWT and UDTFIDWT */
+/** Util for UDTFDWT and UDTFIDWT. */
 public class DWTUtil {
   /** The number of coefficients. */
   private int ncof;
-  /** layers to decompose,When transforming, point numbers should be no less than ncof */
+  /** layers to decompose,When transforming, point numbers should be no less than ncof. */
   private int layer;
   /** Centering. */
   private int ioff;
@@ -37,13 +38,13 @@ public class DWTUtil {
 
   private double[] cr;
 
-  /** Data storage */
+  /** Data storage. */
   private double[] data;
 
   /** Workspace. */
   private double[] workspace = new double[1024];
 
-  public DWTUtil(String method, String coef, int layer, ArrayList<Double> data) {
+  public DWTUtil(String method, String coef, int layer, List<Double> data) {
     this.data = data.stream().mapToDouble(Double::valueOf).toArray();
     this.layer = layer;
     if (method.equalsIgnoreCase("Haar") || method.equalsIgnoreCase("DB2")) {
@@ -96,6 +97,7 @@ public class DWTUtil {
   public static boolean isPower2(int x) {
     return x > 0 && (x & (x - 1)) == 0;
   }
+
   /**
    * Log of base 2.
    *
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/frequency/util/FFTUtil.java b/library-udf/src/main/java/org/apache/iotdb/library/frequency/util/FFTUtil.java
index 2ea041afa4e..1fbaeeefceb 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/frequency/util/FFTUtil.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/frequency/util/FFTUtil.java
@@ -16,14 +16,16 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.frequency.util;
 
 import org.apache.iotdb.udf.api.collector.PointCollector;
+import org.apache.iotdb.udf.api.exception.UDFException;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-/** Util for UDFFFT */
+/** Util for UDFFFT. */
 public class FFTUtil {
   private final String result;
   private final double compressRate;
@@ -34,7 +36,7 @@ public class FFTUtil {
     this.compressRate = cmprate;
   }
 
-  public void outputCompressed(PointCollector collector, double a[]) throws Exception {
+  public void outputCompressed(PointCollector collector, double[] a) throws Exception {
     int n = a.length / 2;
     // calculate total energy
     double sum = 0;
@@ -58,7 +60,7 @@ public class FFTUtil {
     add(collector, a, n - 1);
   }
 
-  public void add(PointCollector collector, double a[], int i) throws Exception {
+  public void add(PointCollector collector, double[] a, int i) throws Exception {
     double ans = 0;
     switch (result) {
       case "real":
@@ -74,12 +76,12 @@ public class FFTUtil {
         ans = Math.atan2(a[2 * i + 1], a[2 * i]);
         break;
       default:
-        throw new Exception("It's impossible");
+        throw new UDFException("It's impossible");
     }
     collector.putDouble(i, ans);
   }
 
-  public void outputUncompressed(PointCollector collector, double a[]) throws Exception {
+  public void outputUncompressed(PointCollector collector, double[] a) throws Exception {
     int n = a.length / 2;
     for (int i = 0; i < n; i++) {
       add(collector, a, i);
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/series/UDTFConsecutiveWindows.java b/library-udf/src/main/java/org/apache/iotdb/library/series/UDTFConsecutiveWindows.java
index 60ada1f0e35..ac02c35c4c7 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/series/UDTFConsecutiveWindows.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/series/UDTFConsecutiveWindows.java
@@ -32,7 +32,7 @@ import org.apache.commons.lang3.tuple.Pair;
 /** This function searches for consecutive subsequences of given length of input sereis. */
 public class UDTFConsecutiveWindows implements UDTF {
   private ConsecutiveUtil consUtil;
-  private static final int maxLen = 128;
+  private static final int MAX_LEN = 128;
   private long len;
 
   @Override
@@ -62,7 +62,7 @@ public class UDTFConsecutiveWindows implements UDTF {
   @Override
   public void transform(Row row, PointCollector collector) throws Exception {
     if (consUtil.getGap() == 0) {
-      if (consUtil.getWindow().size() < maxLen) { // window is not full
+      if (consUtil.getWindow().size() < MAX_LEN) { // window is not full
         consUtil.getWindow().add(Pair.of(row.getTime(), consUtil.check(row)));
       } else {
         consUtil.calculateGap();
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/series/util/ConsecutiveUtil.java b/library-udf/src/main/java/org/apache/iotdb/library/series/util/ConsecutiveUtil.java
index e31b0827240..d2d24a83171 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/series/util/ConsecutiveUtil.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/series/util/ConsecutiveUtil.java
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.apache.iotdb.library.series.util;
 
 import org.apache.iotdb.library.util.Util;
@@ -23,15 +24,16 @@ import org.apache.commons.lang3.tuple.Pair;
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.List;
 
-/** Util for ConsecutiveSequences and ConsecutiveWindows */
+/** Util for ConsecutiveSequences and ConsecutiveWindows. */
 public class ConsecutiveUtil {
-  private static final int maxLen = 128;
+  private static final int MAX_LEN = 128;
   private long first;
   private long last;
   private long gap;
   private int count = 0;
-  private final ArrayList<Pair<Long, Boolean>> window = new ArrayList<>(maxLen);
+  private final List<Pair<Long, Boolean>> window = new ArrayList<>(MAX_LEN);
 
   public ConsecutiveUtil(long first, long last, long gap) {
     this.first = first;
@@ -39,7 +41,7 @@ public class ConsecutiveUtil {
     this.gap = gap;
   }
 
-  public ArrayList<Pair<Long, Boolean>> getWindow() {
+  public List<Pair<Long, Boolean>> getWindow() {
     return window;
   }
 
@@ -52,7 +54,7 @@ public class ConsecutiveUtil {
   }
 
   public int getMaxLen() {
-    return maxLen;
+    return MAX_LEN;
   }
 
   public int getCount() {
@@ -75,7 +77,7 @@ public class ConsecutiveUtil {
     return last;
   }
 
-  /** check Null values */
+  /** check Null values. */
   public boolean check(Row row) {
     for (int i = 0; i < row.size(); i++) {
       if (row.isNull(i)) {
@@ -94,7 +96,7 @@ public class ConsecutiveUtil {
     gap = Util.mode(time);
   }
 
-  /** clear data points in the window */
+  /** clear data points in the window. */
   public void cleanWindow(PointCollector collector) throws IOException {
     if (window.isEmpty()) {
       return;
@@ -105,7 +107,7 @@ public class ConsecutiveUtil {
     }
   }
 
-  /** process one row */
+  /** process one row. */
   public void process(long time, boolean nullExist, PointCollector collector) throws IOException {
     if (nullExist) { // consecutive subsequence ends with null
       if (count > 1) {
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/util/BooleanCircularQueue.java b/library-udf/src/main/java/org/apache/iotdb/library/util/BooleanCircularQueue.java
index 078e4cc6169..6222acb0b46 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/util/BooleanCircularQueue.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/util/BooleanCircularQueue.java
@@ -16,14 +16,18 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.util;
 
-/** Circular queue for boolean */
+/** Circular queue for boolean. */
 public class BooleanCircularQueue {
 
-  private static int INITCAP = 64;
+  private static final int INITCAP = 64;
 
-  private int head, tail, size, minLen;
+  private int head;
+  private int tail;
+  private int size;
+  private int minLen;
   private boolean[] data;
 
   public BooleanCircularQueue(int capacity) {
@@ -37,7 +41,7 @@ public class BooleanCircularQueue {
   }
 
   /**
-   * push value into the back of queue
+   * push value into the back of queue.
    *
    * @param value value to push
    */
@@ -51,7 +55,7 @@ public class BooleanCircularQueue {
   }
 
   /**
-   * pop value from the front of queue
+   * pop value from the front of queue.
    *
    * @return value in the front
    */
@@ -59,7 +63,7 @@ public class BooleanCircularQueue {
     if (isEmpty()) {
       throw new IllegalArgumentException("Error: Queue is Empty!");
     }
-    boolean ret = data[head];
+    final boolean ret = data[head];
     head = (head + 1) % data.length;
     size--;
     if (size < data.length / 4 && data.length / 2 >= minLen) {
@@ -69,7 +73,7 @@ public class BooleanCircularQueue {
   }
 
   /**
-   * get the value in the front
+   * get the value in the front.
    *
    * @return value in the front
    */
@@ -77,12 +81,11 @@ public class BooleanCircularQueue {
     if (isEmpty()) {
       throw new IllegalArgumentException("Error: Queue is Empty!");
     }
-    boolean ret = data[head];
-    return ret;
+    return data[head];
   }
 
   /**
-   * judge if circular queue is empty
+   * judge if circular queue is empty.
    *
    * @return if empty, return true; else return false
    */
@@ -91,7 +94,7 @@ public class BooleanCircularQueue {
   }
 
   /**
-   * judge if circular queue is full
+   * judge if circular queue is full.
    *
    * @return if full, return true; else return false
    */
@@ -100,7 +103,7 @@ public class BooleanCircularQueue {
   }
 
   /**
-   * change size of queue
+   * change size of queue.
    *
    * @param newLength new length of queue
    */
@@ -115,7 +118,7 @@ public class BooleanCircularQueue {
   }
 
   /**
-   * get value of given index
+   * get value of given index.
    *
    * @param index index
    * @return value to queue
@@ -128,7 +131,7 @@ public class BooleanCircularQueue {
   }
 
   /**
-   * get number of values in queue
+   * get number of values in queue.
    *
    * @return number of values
    */
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/util/CircularQueue.java b/library-udf/src/main/java/org/apache/iotdb/library/util/CircularQueue.java
index 2fd663e6c59..0eba8f7ae04 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/util/CircularQueue.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/util/CircularQueue.java
@@ -16,14 +16,18 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.util;
 
 /** This is a circular queue class. */
 public class CircularQueue<E> {
 
-  private static int INITCAP = 64;
+  private static final int INITCAP = 64;
 
-  private int head, tail, size, minLen;
+  private int head;
+  private int tail;
+  private int size;
+  private int minLen;
   private E[] data;
 
   public CircularQueue(int capacity) {
@@ -37,7 +41,7 @@ public class CircularQueue<E> {
   }
 
   /**
-   * push value into the back of queue
+   * push value into the back of queue.
    *
    * @param value value to push
    */
@@ -51,7 +55,7 @@ public class CircularQueue<E> {
   }
 
   /**
-   * pop value from the front of queue
+   * pop value from the front of queue.
    *
    * @return value in the front
    */
@@ -59,7 +63,7 @@ public class CircularQueue<E> {
     if (isEmpty()) {
       throw new IllegalArgumentException("Error: Queue is Empty!");
     }
-    E ret = data[head];
+    final E ret = data[head];
     head = (head + 1) % data.length;
     size--;
     if (size < data.length / 4 && data.length / 2 >= minLen) {
@@ -69,7 +73,7 @@ public class CircularQueue<E> {
   }
 
   /**
-   * get the value in the front
+   * get the value in the front.
    *
    * @return value in the front
    */
@@ -77,12 +81,11 @@ public class CircularQueue<E> {
     if (isEmpty()) {
       throw new IllegalArgumentException("Error: Queue is Empty!");
     }
-    E ret = data[head];
-    return ret;
+    return data[head];
   }
 
   /**
-   * judge if circular queue is empty
+   * judge if circular queue is empty.
    *
    * @return if empty, return true; else return false
    */
@@ -91,7 +94,7 @@ public class CircularQueue<E> {
   }
 
   /**
-   * judge if circular queue is full
+   * judge if circular queue is full.
    *
    * @return if full, return true; else return false
    */
@@ -100,7 +103,7 @@ public class CircularQueue<E> {
   }
 
   /**
-   * change size of queue
+   * change size of queue.
    *
    * @param newLength new length of queue
    */
@@ -115,7 +118,7 @@ public class CircularQueue<E> {
   }
 
   /**
-   * get value of given index
+   * get value of given index.
    *
    * @param index index
    * @return value to queue
@@ -128,7 +131,7 @@ public class CircularQueue<E> {
   }
 
   /**
-   * get number of values in queue
+   * get number of values in queue.
    *
    * @return number of values
    */
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/util/DoubleCircularQueue.java b/library-udf/src/main/java/org/apache/iotdb/library/util/DoubleCircularQueue.java
index 1118688754e..9495039b950 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/util/DoubleCircularQueue.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/util/DoubleCircularQueue.java
@@ -16,14 +16,18 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.util;
 
-/** Circular queue for double */
+/** Circular queue for double. */
 public class DoubleCircularQueue {
 
-  private static int INITCAP = 64;
+  private static final int INITCAP = 64;
 
-  private int head, tail, size, minLen;
+  private int head;
+  private int tail;
+  private int size;
+  private int minLen;
   private double[] data;
 
   public DoubleCircularQueue(int capacity) {
@@ -37,7 +41,7 @@ public class DoubleCircularQueue {
   }
 
   /**
-   * push value into the back of queue
+   * push value into the back of queue.
    *
    * @param value value to push
    */
@@ -51,7 +55,7 @@ public class DoubleCircularQueue {
   }
 
   /**
-   * pop value from the front of queue
+   * pop value from the front of queue.
    *
    * @return value in the front
    */
@@ -59,7 +63,7 @@ public class DoubleCircularQueue {
     if (isEmpty()) {
       throw new IllegalArgumentException("Error: Queue is Empty!");
     }
-    double ret = data[head];
+    final double ret = data[head];
     head = (head + 1) % data.length;
     size--;
     if (size < data.length / 4 && data.length / 2 >= minLen) {
@@ -69,7 +73,7 @@ public class DoubleCircularQueue {
   }
 
   /**
-   * get the value in the front
+   * get the value in the front.
    *
    * @return value in the front
    */
@@ -77,12 +81,11 @@ public class DoubleCircularQueue {
     if (isEmpty()) {
       throw new IllegalArgumentException("Error: Queue is Empty!");
     }
-    double ret = data[head];
-    return ret;
+    return data[head];
   }
 
   /**
-   * judge if circular queue is empty
+   * judge if circular queue is empty.
    *
    * @return if empty, return true; else return false
    */
@@ -91,7 +94,7 @@ public class DoubleCircularQueue {
   }
 
   /**
-   * judge if circular queue is full
+   * judge if circular queue is full.
    *
    * @return if full, return true; else return false
    */
@@ -100,7 +103,7 @@ public class DoubleCircularQueue {
   }
 
   /**
-   * change size of queue
+   * change size of queue.
    *
    * @param newLength new length of queue
    */
@@ -115,7 +118,7 @@ public class DoubleCircularQueue {
   }
 
   /**
-   * get value of given index
+   * get value of given index.
    *
    * @param index index
    * @return value to queue
@@ -128,7 +131,7 @@ public class DoubleCircularQueue {
   }
 
   /**
-   * get number of values in queue
+   * get number of values in queue.
    *
    * @return number of values
    */
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/util/LinearRegression.java b/library-udf/src/main/java/org/apache/iotdb/library/util/LinearRegression.java
index 828d6fc4466..dc697bfe4b2 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/util/LinearRegression.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/util/LinearRegression.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.util;
 
 import org.apache.iotdb.udf.api.exception.UDFException;
@@ -30,20 +31,20 @@ public class LinearRegression {
   double[] x, y, e, yhead;
   int n;
   double sumx, sumy, xbar, ybar, xxbar, yybar, xybar;
-  double beta1, beta0, rss, ssr, R2, svar, svar1, svar0;
+  double beta1, beta0, rss, ssr, r2, svar, svar1, svar0;
 
-  public LinearRegression(double[] a, double[] b) throws Exception {
+  public LinearRegression(double[] a, double[] b) throws UDFException {
     x = a.clone();
     y = b.clone();
     n = x.length;
     if (x.length == 0 || y.length == 0) {
-      throw new Exception("Empty input array(s).");
+      throw new UDFException("Empty input array(s).");
     }
     if (x.length != y.length) {
-      throw new Exception("Different input array length.");
+      throw new UDFException("Different input array length.");
     }
     if (x.length == 1) { // cannot do regression
-      throw new Exception("Input series should be longer than 1.");
+      throw new UDFException("Input series should be longer than 1.");
     }
     e = new double[n];
     yhead = new double[n];
@@ -66,7 +67,7 @@ public class LinearRegression {
     beta1 = xybar / xxbar;
     beta0 = ybar - beta1 * xbar;
     // analyze results
-    int df = n - 2;
+    final int df = n - 2;
     rss = 0.0; // residual sum of squares
     ssr = 0.0; // regression sum of squares
     for (int i = 0; i < n; i++) {
@@ -75,7 +76,7 @@ public class LinearRegression {
       rss += (yhead[i] - y[i]) * (yhead[i] - y[i]);
       ssr += (yhead[i] - ybar) * (yhead[i] - ybar);
     }
-    R2 = ssr / yybar;
+    r2 = ssr / yybar;
     svar = rss / df;
     svar1 = svar / xxbar;
     svar0 = svar / n + xbar * xbar * svar1;
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/util/LongCircularQueue.java b/library-udf/src/main/java/org/apache/iotdb/library/util/LongCircularQueue.java
index 93542d57a92..966e9259c56 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/util/LongCircularQueue.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/util/LongCircularQueue.java
@@ -16,28 +16,32 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.util;
 
-/** Circular queue for long */
+/** Circular queue for long. */
 public class LongCircularQueue {
 
-  private static int INITCAP = 64;
+  private static final int INIT_CAP = 64;
 
-  private int head, tail, size, minLen;
+  private int head;
+  private int tail;
+  private int size;
+  private int minLen;
   private long[] data;
 
   public LongCircularQueue(int capacity) {
     head = tail = size = 0;
     data = new long[capacity];
-    minLen = Math.max(INITCAP, capacity);
+    minLen = Math.max(INIT_CAP, capacity);
   }
 
   public LongCircularQueue() {
-    this(INITCAP);
+    this(INIT_CAP);
   }
 
   /**
-   * push value into the back of queue
+   * push value into the back of queue.
    *
    * @param value value to push
    */
@@ -51,7 +55,7 @@ public class LongCircularQueue {
   }
 
   /**
-   * pop value from the front of queue
+   * pop value from the front of queue.
    *
    * @return value in the front
    */
@@ -59,7 +63,7 @@ public class LongCircularQueue {
     if (isEmpty()) {
       throw new IllegalArgumentException("Error: Queue is Empty!");
     }
-    long ret = data[head];
+    final long ret = data[head];
     head = (head + 1) % data.length;
     size--;
     if (size < data.length / 4 && data.length / 2 >= minLen) {
@@ -69,7 +73,7 @@ public class LongCircularQueue {
   }
 
   /**
-   * judge if circular queue is empty
+   * judge if circular queue is empty.
    *
    * @return if empty, return true; else return false
    */
@@ -77,12 +81,11 @@ public class LongCircularQueue {
     if (isEmpty()) {
       throw new IllegalArgumentException("Error: Queue is Empty!");
     }
-    long ret = data[head];
-    return ret;
+    return data[head];
   }
 
   /**
-   * judge if circular queue is empty
+   * judge if circular queue is empty.
    *
    * @return if empty, return true; else return false
    */
@@ -91,7 +94,7 @@ public class LongCircularQueue {
   }
 
   /**
-   * judge if circular queue is full
+   * judge if circular queue is full.
    *
    * @return if full, return true; else return false
    */
@@ -100,7 +103,7 @@ public class LongCircularQueue {
   }
 
   /**
-   * change size of queue
+   * change size of queue.
    *
    * @param newLength new length of queue
    */
@@ -115,7 +118,7 @@ public class LongCircularQueue {
   }
 
   /**
-   * get value of given index
+   * get value of given index.
    *
    * @param index index
    * @return value to queue
@@ -128,7 +131,7 @@ public class LongCircularQueue {
   }
 
   /**
-   * get number of values in queue
+   * get number of values in queue.
    *
    * @return number of values
    */
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/util/NoNumberException.java b/library-udf/src/main/java/org/apache/iotdb/library/util/NoNumberException.java
index 530d7040277..007de8369ae 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/util/NoNumberException.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/util/NoNumberException.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.util;
 
 /** throw when the value got is not numeric. */
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/util/Util.java b/library-udf/src/main/java/org/apache/iotdb/library/util/Util.java
index 2cdb10acebe..d7060de7692 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/util/Util.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/util/Util.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.library.util;
 
 import org.apache.iotdb.udf.api.access.Row;
@@ -27,10 +28,13 @@ import org.eclipse.collections.api.tuple.primitive.LongIntPair;
 import org.eclipse.collections.impl.map.mutable.primitive.LongIntHashMap;
 
 import java.io.IOException;
-import java.util.ArrayList;
+import java.util.List;
 
 /** This class offers functions of getting and putting values from iotdb interface. */
 public class Util {
+  private Util() {
+    throw new IllegalStateException("Utility class");
+  }
 
   /**
    * Get value from specific column from Row, and cast to double. Make sure never get null from Row.
@@ -40,7 +44,7 @@ public class Util {
    * @return value of specific column from Row
    * @throws NoNumberException when getting a no number datatype
    */
-  public static double getValueAsDouble(Row row, int index) throws Exception {
+  public static double getValueAsDouble(Row row, int index) throws IOException, NoNumberException {
     double ans = 0;
     try {
       switch (row.getDataType(index)) {
@@ -60,7 +64,7 @@ public class Util {
           throw new NoNumberException();
       }
     } catch (IOException e) {
-      throw new Exception("Fail to get data type in row " + row.getTime(), e);
+      throw new IOException("Fail to get data type in row " + row.getTime(), e);
     }
     return ans;
   }
@@ -72,7 +76,7 @@ public class Util {
    * @return value from 0th column from Row
    * @throws NoNumberException when getting a no number datatype
    */
-  public static double getValueAsDouble(Row row) throws Exception {
+  public static double getValueAsDouble(Row row) throws IOException, NoNumberException {
     return getValueAsDouble(row, 0);
   }
 
@@ -103,19 +107,21 @@ public class Util {
       case TEXT:
         ans = row.getString(0);
         break;
+      default:
+        break;
     }
     return ans;
   }
 
   /**
-   * Add new data point to PointCollector
+   * Add new data point to PointCollector.
    *
    * @param pc PointCollector
    * @param type datatype
    * @param t timestamp
    * @param o value in Object type
    */
-  public static void putValue(PointCollector pc, Type type, long t, Object o) throws Exception {
+  public static void putValue(PointCollector pc, Type type, long t, Object o) throws IOException {
     switch (type) {
       case INT32:
         pc.putInt(t, (Integer) o);
@@ -131,26 +137,29 @@ public class Util {
         break;
       case BOOLEAN:
         pc.putBoolean(t, (Boolean) o);
+        break;
+      default:
+        break;
     }
   }
 
   /**
-   * cast {@code ArrayList<Double>} to {@code double[]}
+   * cast {@code ArrayList<Double>} to {@code double[]}.
    *
    * @param list ArrayList to cast
    * @return cast result
    */
-  public static double[] toDoubleArray(ArrayList<Double> list) {
+  public static double[] toDoubleArray(List<Double> list) {
     return list.stream().mapToDouble(Double::valueOf).toArray();
   }
 
   /**
-   * cast {@code ArrayList<Long>} to {@code long[]}
+   * cast {@code ArrayList<Long>} to {@code long[]}.
    *
    * @param list ArrayList to cast
    * @return cast result
    */
-  public static long[] toLongArray(ArrayList<Long> list) {
+  public static long[] toLongArray(List<Long> list) {
     return list.stream().mapToLong(Long::valueOf).toArray();
   }
 
@@ -172,52 +181,52 @@ public class Util {
   }
 
   /**
-   * calculate 1-order difference of input series
+   * calculate 1-order difference of input series.
    *
    * @param origin original series
    * @return 1-order difference
    */
   public static double[] variation(double[] origin) {
     int n = origin.length;
-    double[] var = new double[n - 1];
+    double[] variance = new double[n - 1];
     for (int i = 0; i < n - 1; i++) {
-      var[i] = origin[i + 1] - origin[i];
+      variance[i] = origin[i + 1] - origin[i];
     }
-    return var;
+    return variance;
   }
 
   /**
-   * calculate 1-order difference of input series
+   * calculate 1-order difference of input series.
    *
    * @param origin original series
    * @return 1-order difference
    */
   public static double[] variation(long[] origin) {
     int n = origin.length;
-    double[] var = new double[n - 1];
+    double[] variance = new double[n - 1];
     for (int i = 0; i < n - 1; i++) {
-      var[i] = (double) (origin[i + 1] - origin[i]);
+      variance[i] = (origin[i + 1] - origin[i]);
     }
-    return var;
+    return variance;
   }
 
   /**
-   * calculate 1-order difference of input series
+   * calculate 1-order difference of input series.
    *
    * @param origin original series
    * @return 1-order difference
    */
   public static int[] variation(int[] origin) {
     int n = origin.length;
-    int[] var = new int[n - 1];
+    int[] variance = new int[n - 1];
     for (int i = 0; i < n - 1; i++) {
-      var[i] = origin[i + 1] - origin[i];
+      variance[i] = origin[i + 1] - origin[i];
     }
-    return var;
+    return variance;
   }
 
   /**
-   * calculate speed (1-order derivative with backward difference)
+   * calculate speed (1-order derivative with backward difference).
    *
    * @param origin value series
    * @param time timestamp series
@@ -233,7 +242,7 @@ public class Util {
   }
 
   /**
-   * calculate speed (1-order derivative with backward difference)
+   * calculate speed (1-order derivative with backward difference).
    *
    * @param origin value series
    * @param time timestamp series
@@ -249,7 +258,7 @@ public class Util {
   }
 
   /**
-   * computes mode
+   * computes mode.
    *
    * @param values input series
    * @return mode
@@ -271,7 +280,7 @@ public class Util {
   }
 
   /**
-   * cast String to timestamp
+   * cast String to timestamp.
    *
    * @param s input string
    * @return timestamp
@@ -279,7 +288,7 @@ public class Util {
   public static long parseTime(String s) {
     long unit = 0;
     s = s.toLowerCase();
-    s = s.replaceAll(" ", "");
+    s = s.replace(" ", "");
     if (s.endsWith("ms")) {
       unit = 1;
       s = s.substring(0, s.length() - 2);