You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/01/14 16:23:02 UTC

[GitHub] [iotdb] FrankHWD opened a new pull request #4835: [IOTDB-2303]Library dmatch

FrankHWD opened a new pull request #4835:
URL: https://github.com/apache/iotdb/pull/4835


   ## Description
   Add Data Matching of UDF functions through Library-dmatch.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] FrankHWD commented on a change in pull request #4835: [IOTDB-2303]Library dmatch

Posted by GitBox <gi...@apache.org>.
FrankHWD commented on a change in pull request #4835:
URL: https://github.com/apache/iotdb/pull/4835#discussion_r812903728



##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);

Review comment:
       Done.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);

Review comment:
       Done.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);

Review comment:
       Done.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d2.s1,d2.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);

Review comment:
       Done.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d2.s1,d2.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("8.0", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d2.s2,d2.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s3,d2.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s4,d2.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPthSym1() {
+    String sqlStr = "select ptnsym(d1.s1, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("0.0", result2);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym2() {
+    String sqlStr = "select ptnsym(d1.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("0.0", result2);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym3() {
+    String sqlStr = "select ptnsym(d2.s1, 'window'='3', 'threshold'='0') from";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("0.0", result2);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym4() {
+    String sqlStr = "select ptnsym(d2.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("0.0", result2);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr1() {
+    String sqlStr = "select xcorr(d4.s1,d4.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      resultSet.next();
+      String result3 = resultSet.getString(1);
+      resultSet.next();
+      String result4 = resultSet.getString(1);
+      resultSet.next();
+      String result5 = resultSet.getString(1);
+      resultSet.next();
+      String result6 = resultSet.getString(1);
+      resultSet.next();
+      String result7 = resultSet.getString(1);
+      resultSet.next();
+      String result8 = resultSet.getString(1);
+      resultSet.next();
+      String result9 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("4.0", result2);
+      Assert.assertEquals("9.6", result3);
+      Assert.assertEquals("13.4", result4);
+      Assert.assertEquals("20.0", result5);
+      Assert.assertEquals("15.6", result6);
+      Assert.assertEquals("9.2", result7);
+      Assert.assertEquals("11.8", result8);
+      Assert.assertEquals("6.0", result9);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr2() {
+    String sqlStr = "select xcorr(d4.s2, d4.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      resultSet.next();
+      String result3 = resultSet.getString(1);
+      resultSet.next();
+      String result4 = resultSet.getString(1);
+      resultSet.next();
+      String result5 = resultSet.getString(1);
+      resultSet.next();
+      String result6 = resultSet.getString(1);
+      resultSet.next();
+      String result7 = resultSet.getString(1);
+      resultSet.next();
+      String result8 = resultSet.getString(1);
+      resultSet.next();
+      String result9 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("4.0", result2);
+      Assert.assertEquals("9.6", result3);
+      Assert.assertEquals("13.4", result4);
+      Assert.assertEquals("20.0", result5);
+      Assert.assertEquals("15.6", result6);
+      Assert.assertEquals("9.2", result7);
+      Assert.assertEquals("11.8", result8);
+      Assert.assertEquals("6.0", result9);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr3() {
+    String sqlStr = "select xcorr(d4.s3, d4.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      resultSet.next();
+      String result3 = resultSet.getString(1);
+      resultSet.next();
+      String result4 = resultSet.getString(1);
+      resultSet.next();
+      String result5 = resultSet.getString(1);
+      resultSet.next();
+      String result6 = resultSet.getString(1);
+      resultSet.next();
+      String result7 = resultSet.getString(1);
+      resultSet.next();
+      String result8 = resultSet.getString(1);
+      resultSet.next();
+      String result9 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("4.0", result2);
+      Assert.assertEquals("9.6", result3);
+      Assert.assertEquals("13.4", result4);
+      Assert.assertEquals("20.0", result5);
+      Assert.assertEquals("15.6", result6);
+      Assert.assertEquals("9.2", result7);
+      Assert.assertEquals("11.8", result8);
+      Assert.assertEquals("6.0", result9);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr4() {
+    String sqlStr = "select xcorr(d4.s4,d4.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);

Review comment:
       Done.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);

Review comment:
       Done.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(

Review comment:
       Done.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");

Review comment:
       Done.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");

Review comment:
       Done.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] coveralls edited a comment on pull request #4835: [IOTDB-2303]Library dmatch

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #4835:
URL: https://github.com/apache/iotdb/pull/4835#issuecomment-1013333654


   
   [![Coverage Status](https://coveralls.io/builds/46702149/badge)](https://coveralls.io/builds/46702149)
   
   Coverage decreased (-0.3%) to 67.794% when pulling **7f5cc667dc933583030ef606c23f54625eca4ea9 on trin1t:library-dmatch** into **001490bbd734eab37ee4dcc5530b0dac33603870 on apache:master**.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] ericpai commented on a change in pull request #4835: [IOTDB-2303]Library dmatch

Posted by GitBox <gi...@apache.org>.
ericpai commented on a change in pull request #4835:
URL: https://github.com/apache/iotdb/pull/4835#discussion_r815537347



##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");

Review comment:
       Sorry it's my mistake




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] ericpai commented on a change in pull request #4835: [IOTDB-2303]Library dmatch

Posted by GitBox <gi...@apache.org>.
ericpai commented on a change in pull request #4835:
URL: https://github.com/apache/iotdb/pull/4835#discussion_r815304234



##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");

Review comment:
       This has not been changed yet.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");

Review comment:
       This has not been changed yet.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] FrankHWD commented on a change in pull request #4835: [IOTDB-2303]Library dmatch

Posted by GitBox <gi...@apache.org>.
FrankHWD commented on a change in pull request #4835:
URL: https://github.com/apache/iotdb/pull/4835#discussion_r815649203



##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");

Review comment:
       Thank you!




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] ericpai commented on a change in pull request #4835: [IOTDB-2303]Library dmatch

Posted by GitBox <gi...@apache.org>.
ericpai commented on a change in pull request #4835:
URL: https://github.com/apache/iotdb/pull/4835#discussion_r815537439



##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPthSym1() {
+    String sqlStr = "select ptnsym(d1.s1, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym2() {
+    String sqlStr = "select ptnsym(d1.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym3() {
+    String sqlStr = "select ptnsym(d2.s1, 'window'='3', 'threshold'='0') from";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym4() {
+    String sqlStr = "select ptnsym(d2.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr1() {
+    String sqlStr = "select xcorr(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr2() {
+    String sqlStr = "select xcorr(d1.s2, d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr3() {
+    String sqlStr = "select xcorr(d2.s1, d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr4() {
+    String sqlStr = "select xcorr(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);

Review comment:
       Sorry it's my mistake




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] FrankHWD commented on a change in pull request #4835: [IOTDB-2303]Library dmatch

Posted by GitBox <gi...@apache.org>.
FrankHWD commented on a change in pull request #4835:
URL: https://github.com/apache/iotdb/pull/4835#discussion_r810421578



##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;

Review comment:
       Done.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPthSym1() {
+    String sqlStr = "select ptnsym(d1.s1, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);

Review comment:
       Done.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPthSym1() {
+    String sqlStr = "select ptnsym(d1.s1, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym2() {
+    String sqlStr = "select ptnsym(d1.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);

Review comment:
       Done.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPthSym1() {
+    String sqlStr = "select ptnsym(d1.s1, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym2() {
+    String sqlStr = "select ptnsym(d1.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym3() {
+    String sqlStr = "select ptnsym(d2.s1, 'window'='3', 'threshold'='0') from";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);

Review comment:
       Done.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPthSym1() {
+    String sqlStr = "select ptnsym(d1.s1, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym2() {
+    String sqlStr = "select ptnsym(d1.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym3() {
+    String sqlStr = "select ptnsym(d2.s1, 'window'='3', 'threshold'='0') from";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym4() {
+    String sqlStr = "select ptnsym(d2.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);

Review comment:
       Done.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPthSym1() {
+    String sqlStr = "select ptnsym(d1.s1, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym2() {
+    String sqlStr = "select ptnsym(d1.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym3() {
+    String sqlStr = "select ptnsym(d2.s1, 'window'='3', 'threshold'='0') from";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym4() {
+    String sqlStr = "select ptnsym(d2.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr1() {
+    String sqlStr = "select xcorr(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);

Review comment:
       Done.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPthSym1() {
+    String sqlStr = "select ptnsym(d1.s1, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym2() {
+    String sqlStr = "select ptnsym(d1.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym3() {
+    String sqlStr = "select ptnsym(d2.s1, 'window'='3', 'threshold'='0') from";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym4() {
+    String sqlStr = "select ptnsym(d2.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr1() {
+    String sqlStr = "select xcorr(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr2() {
+    String sqlStr = "select xcorr(d1.s2, d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);

Review comment:
       Done.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPthSym1() {
+    String sqlStr = "select ptnsym(d1.s1, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym2() {
+    String sqlStr = "select ptnsym(d1.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym3() {
+    String sqlStr = "select ptnsym(d2.s1, 'window'='3', 'threshold'='0') from";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym4() {
+    String sqlStr = "select ptnsym(d2.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr1() {
+    String sqlStr = "select xcorr(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr2() {
+    String sqlStr = "select xcorr(d1.s2, d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr3() {
+    String sqlStr = "select xcorr(d2.s1, d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);

Review comment:
       Done.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPthSym1() {
+    String sqlStr = "select ptnsym(d1.s1, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym2() {
+    String sqlStr = "select ptnsym(d1.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym3() {
+    String sqlStr = "select ptnsym(d2.s1, 'window'='3', 'threshold'='0') from";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym4() {
+    String sqlStr = "select ptnsym(d2.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr1() {
+    String sqlStr = "select xcorr(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr2() {
+    String sqlStr = "select xcorr(d1.s2, d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr3() {
+    String sqlStr = "select xcorr(d2.s1, d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr4() {
+    String sqlStr = "select xcorr(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);

Review comment:
       Done.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] ericpai commented on a change in pull request #4835: [IOTDB-2303]Library dmatch

Posted by GitBox <gi...@apache.org>.
ericpai commented on a change in pull request #4835:
URL: https://github.com/apache/iotdb/pull/4835#discussion_r810588253



##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");

Review comment:
       Use `Connection connection = EnvFactory.getEnv().getConnection();` instead.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d2.s1,d2.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("8.0", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d2.s2,d2.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s3,d2.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s4,d2.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPthSym1() {
+    String sqlStr = "select ptnsym(d1.s1, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("0.0", result2);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym2() {
+    String sqlStr = "select ptnsym(d1.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("0.0", result2);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym3() {
+    String sqlStr = "select ptnsym(d2.s1, 'window'='3', 'threshold'='0') from";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("0.0", result2);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym4() {
+    String sqlStr = "select ptnsym(d2.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("0.0", result2);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr1() {
+    String sqlStr = "select xcorr(d4.s1,d4.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      resultSet.next();
+      String result3 = resultSet.getString(1);
+      resultSet.next();
+      String result4 = resultSet.getString(1);
+      resultSet.next();
+      String result5 = resultSet.getString(1);
+      resultSet.next();
+      String result6 = resultSet.getString(1);
+      resultSet.next();
+      String result7 = resultSet.getString(1);
+      resultSet.next();
+      String result8 = resultSet.getString(1);
+      resultSet.next();
+      String result9 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("4.0", result2);
+      Assert.assertEquals("9.6", result3);
+      Assert.assertEquals("13.4", result4);
+      Assert.assertEquals("20.0", result5);
+      Assert.assertEquals("15.6", result6);
+      Assert.assertEquals("9.2", result7);
+      Assert.assertEquals("11.8", result8);
+      Assert.assertEquals("6.0", result9);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr2() {
+    String sqlStr = "select xcorr(d4.s2, d4.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);

Review comment:
       Missing `resultSet.next()` before this line?

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");

Review comment:
       Validity has already been registered.Is this a mistake?

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d2.s1,d2.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("8.0", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d2.s2,d2.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s3,d2.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);

Review comment:
       Missing `resultSet.next()` before this line?

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(

Review comment:
       The following insertions are amount. Maybe we can use `statement.addBatch()` and `statement.executeBatch()` to accelerate a little.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d2.s1,d2.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("8.0", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d2.s2,d2.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s3,d2.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s4,d2.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPthSym1() {
+    String sqlStr = "select ptnsym(d1.s1, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("0.0", result2);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym2() {
+    String sqlStr = "select ptnsym(d1.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("0.0", result2);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym3() {
+    String sqlStr = "select ptnsym(d2.s1, 'window'='3', 'threshold'='0') from";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("0.0", result2);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym4() {
+    String sqlStr = "select ptnsym(d2.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);

Review comment:
       Missing `resultSet.next()` before this line?

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d2.s1,d2.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("8.0", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d2.s2,d2.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s3,d2.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s4,d2.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPthSym1() {
+    String sqlStr = "select ptnsym(d1.s1, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("0.0", result2);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym2() {
+    String sqlStr = "select ptnsym(d1.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("0.0", result2);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym3() {
+    String sqlStr = "select ptnsym(d2.s1, 'window'='3', 'threshold'='0') from";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("0.0", result2);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym4() {
+    String sqlStr = "select ptnsym(d2.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("0.0", result2);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr1() {
+    String sqlStr = "select xcorr(d4.s1,d4.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);

Review comment:
       Missing `resultSet.next()` before this line?

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d2.s1,d2.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("8.0", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d2.s2,d2.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s3,d2.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s4,d2.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPthSym1() {
+    String sqlStr = "select ptnsym(d1.s1, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("0.0", result2);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym2() {
+    String sqlStr = "select ptnsym(d1.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("0.0", result2);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym3() {
+    String sqlStr = "select ptnsym(d2.s1, 'window'='3', 'threshold'='0') from";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);

Review comment:
       Missing `resultSet.next()` before this line?

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d2.s1,d2.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("8.0", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d2.s2,d2.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s3,d2.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s4,d2.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPthSym1() {
+    String sqlStr = "select ptnsym(d1.s1, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("0.0", result2);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym2() {
+    String sqlStr = "select ptnsym(d1.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("0.0", result2);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym3() {
+    String sqlStr = "select ptnsym(d2.s1, 'window'='3', 'threshold'='0') from";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("0.0", result2);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym4() {
+    String sqlStr = "select ptnsym(d2.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("0.0", result2);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr1() {
+    String sqlStr = "select xcorr(d4.s1,d4.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      resultSet.next();
+      String result3 = resultSet.getString(1);
+      resultSet.next();
+      String result4 = resultSet.getString(1);
+      resultSet.next();
+      String result5 = resultSet.getString(1);
+      resultSet.next();
+      String result6 = resultSet.getString(1);
+      resultSet.next();
+      String result7 = resultSet.getString(1);
+      resultSet.next();
+      String result8 = resultSet.getString(1);
+      resultSet.next();
+      String result9 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("4.0", result2);
+      Assert.assertEquals("9.6", result3);
+      Assert.assertEquals("13.4", result4);
+      Assert.assertEquals("20.0", result5);
+      Assert.assertEquals("15.6", result6);
+      Assert.assertEquals("9.2", result7);
+      Assert.assertEquals("11.8", result8);
+      Assert.assertEquals("6.0", result9);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr2() {
+    String sqlStr = "select xcorr(d4.s2, d4.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      resultSet.next();
+      String result3 = resultSet.getString(1);
+      resultSet.next();
+      String result4 = resultSet.getString(1);
+      resultSet.next();
+      String result5 = resultSet.getString(1);
+      resultSet.next();
+      String result6 = resultSet.getString(1);
+      resultSet.next();
+      String result7 = resultSet.getString(1);
+      resultSet.next();
+      String result8 = resultSet.getString(1);
+      resultSet.next();
+      String result9 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("4.0", result2);
+      Assert.assertEquals("9.6", result3);
+      Assert.assertEquals("13.4", result4);
+      Assert.assertEquals("20.0", result5);
+      Assert.assertEquals("15.6", result6);
+      Assert.assertEquals("9.2", result7);
+      Assert.assertEquals("11.8", result8);
+      Assert.assertEquals("6.0", result9);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr3() {
+    String sqlStr = "select xcorr(d4.s3, d4.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);

Review comment:
       Missing `resultSet.next()` before this line?

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d2.s1,d2.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("8.0", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d2.s2,d2.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s3,d2.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s4,d2.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPthSym1() {
+    String sqlStr = "select ptnsym(d1.s1, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("0.0", result2);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym2() {
+    String sqlStr = "select ptnsym(d1.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("0.0", result2);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym3() {
+    String sqlStr = "select ptnsym(d2.s1, 'window'='3', 'threshold'='0') from";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("0.0", result2);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym4() {
+    String sqlStr = "select ptnsym(d2.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("0.0", result2);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr1() {
+    String sqlStr = "select xcorr(d4.s1,d4.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      resultSet.next();
+      String result3 = resultSet.getString(1);
+      resultSet.next();
+      String result4 = resultSet.getString(1);
+      resultSet.next();
+      String result5 = resultSet.getString(1);
+      resultSet.next();
+      String result6 = resultSet.getString(1);
+      resultSet.next();
+      String result7 = resultSet.getString(1);
+      resultSet.next();
+      String result8 = resultSet.getString(1);
+      resultSet.next();
+      String result9 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("4.0", result2);
+      Assert.assertEquals("9.6", result3);
+      Assert.assertEquals("13.4", result4);
+      Assert.assertEquals("20.0", result5);
+      Assert.assertEquals("15.6", result6);
+      Assert.assertEquals("9.2", result7);
+      Assert.assertEquals("11.8", result8);
+      Assert.assertEquals("6.0", result9);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr2() {
+    String sqlStr = "select xcorr(d4.s2, d4.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      resultSet.next();
+      String result3 = resultSet.getString(1);
+      resultSet.next();
+      String result4 = resultSet.getString(1);
+      resultSet.next();
+      String result5 = resultSet.getString(1);
+      resultSet.next();
+      String result6 = resultSet.getString(1);
+      resultSet.next();
+      String result7 = resultSet.getString(1);
+      resultSet.next();
+      String result8 = resultSet.getString(1);
+      resultSet.next();
+      String result9 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("4.0", result2);
+      Assert.assertEquals("9.6", result3);
+      Assert.assertEquals("13.4", result4);
+      Assert.assertEquals("20.0", result5);
+      Assert.assertEquals("15.6", result6);
+      Assert.assertEquals("9.2", result7);
+      Assert.assertEquals("11.8", result8);
+      Assert.assertEquals("6.0", result9);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr3() {
+    String sqlStr = "select xcorr(d4.s3, d4.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      resultSet.next();
+      String result3 = resultSet.getString(1);
+      resultSet.next();
+      String result4 = resultSet.getString(1);
+      resultSet.next();
+      String result5 = resultSet.getString(1);
+      resultSet.next();
+      String result6 = resultSet.getString(1);
+      resultSet.next();
+      String result7 = resultSet.getString(1);
+      resultSet.next();
+      String result8 = resultSet.getString(1);
+      resultSet.next();
+      String result9 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("4.0", result2);
+      Assert.assertEquals("9.6", result3);
+      Assert.assertEquals("13.4", result4);
+      Assert.assertEquals("20.0", result5);
+      Assert.assertEquals("15.6", result6);
+      Assert.assertEquals("9.2", result7);
+      Assert.assertEquals("11.8", result8);
+      Assert.assertEquals("6.0", result9);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr4() {
+    String sqlStr = "select xcorr(d4.s4,d4.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);

Review comment:
       Missing `resultSet.next()` before this line?

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d2.s1,d2.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("8.0", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d2.s2,d2.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s3,d2.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s4,d2.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);

Review comment:
       Missing `resultSet.next()` before this line?

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d2.s1,d2.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("8.0", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d2.s2,d2.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s3,d2.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s4,d2.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);

Review comment:
       Missing `resultSet.next()` before this line?

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d2.s1,d2.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("8.0", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d2.s2,d2.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s3,d2.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s4,d2.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);

Review comment:
       Missing `resultSet.next()` before this line?

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d2.s1,d2.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("8.0", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d2.s2,d2.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s3,d2.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s4,d2.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPthSym1() {
+    String sqlStr = "select ptnsym(d1.s1, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);

Review comment:
       Missing `resultSet.next()` before this line?

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d2.s1,d2.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("8.0", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d2.s2,d2.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s3,d2.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s4,d2.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);

Review comment:
       Missing `resultSet.next()` before this line?

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d2.s1,d2.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("8.0", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d2.s2,d2.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s3,d2.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s4,d2.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);

Review comment:
       Missing `resultSet.next()` before this line?

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);

Review comment:
       Missing `resultSet.next()` before this line?

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);

Review comment:
       Missing `resultSet.next()` before this line?

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);

Review comment:
       I‘m a little consused that why the `resultSet.next()` is not called before getting the column data. Is this case passed?

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d2.s1,d2.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);

Review comment:
       Missing `resultSet.next()` before this line?

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);

Review comment:
       Missing `resultSet.next()` before this line?

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d2.s1,d2.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("8.0", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d2.s2,d2.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s3,d2.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s4,d2.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("0.5630881927754872", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPthSym1() {
+    String sqlStr = "select ptnsym(d1.s1, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      resultSet.next();
+      String result2 = resultSet.getString(1);
+      Assert.assertEquals("0.0", result1);
+      Assert.assertEquals("0.0", result2);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym2() {
+    String sqlStr = "select ptnsym(d1.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);

Review comment:
       Missing `resultSet.next()` before this line?

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);

Review comment:
       For dataSet test and assertion. We need to call `Assert.assertFalse(resultSet.next())` in the end as we should make the data returned is exactly as we expected.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d1.s3,d1.s7) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d1.s4,d1.s8) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d2.s1,d2.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("8.0", result1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d2.s2,d2.s6) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);

Review comment:
       Missing `resultSet.next()` before this line?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] ericpai commented on a change in pull request #4835: [IOTDB-2303]Library dmatch

Posted by GitBox <gi...@apache.org>.
ericpai commented on a change in pull request #4835:
URL: https://github.com/apache/iotdb/pull/4835#discussion_r794979939



##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);

Review comment:
       As we have discussed previously, please check the equalivent between expected and acutal data returned, not only row counts.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";

Review comment:
       As we have discussed previously, please check the equalivent between expected and acutal data returned, not only row counts.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;

Review comment:
       Please use `Assert.assertEqual()` instead of `assert` keyword.
   Is this result not deterministic? If the result is consistent of in every test running, please check the equalivent instead of a range condition check.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;

Review comment:
       Please use `Assert.assertEqual()` instead of `assert` keyword.
   Is this result not deterministic? If the result is consistent of in every test running, please check the equalivent instead of a range condition check.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPthSym1() {
+    String sqlStr = "select ptnsym(d1.s1, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym2() {
+    String sqlStr = "select ptnsym(d1.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym3() {
+    String sqlStr = "select ptnsym(d2.s1, 'window'='3', 'threshold'='0') from";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym4() {
+    String sqlStr = "select ptnsym(d2.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr1() {
+    String sqlStr = "select xcorr(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr2() {
+    String sqlStr = "select xcorr(d1.s2, d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr3() {
+    String sqlStr = "select xcorr(d2.s1, d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr4() {
+    String sqlStr = "select xcorr(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);

Review comment:
       As we have discussed previously, please check the equalivent between expected and acutal data returned, not only row counts.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;

Review comment:
       Please use `Assert.assertEqual()` instead of `assert` keyword.
   Is this result not deterministic? If the result is consistent of in every test running, please check the equalivent instead of a range condition check.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);

Review comment:
       As we have discussed previously, please check the equalivent between expected and acutal data returned, not only row counts.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();

Review comment:
       As we have discussed previously, please check the equalivent between expected and acutal data returned, not only row counts.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;

Review comment:
       Please use `Assert.assertEqual()` instead of `assert` keyword.
   Is this result not deterministic? If the result is consistent of in every test running, please check the equalivent instead of a range condition check.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;

Review comment:
       Please use `Assert.assertEqual()` instead of `assert` keyword.
   Is this result not deterministic? If the result is consistent of in every test running, please check the equalivent instead of a range condition check.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;

Review comment:
       Please use `Assert.assertEqual()` instead of `assert` keyword.
   Is this result not deterministic? If the result is consistent of in every test running, please check the equalivent instead of a range condition check.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;

Review comment:
       Please use `Assert.assertEqual()` instead of `assert` keyword.
   Is this result not deterministic? If the result is consistent of in every test running, please check the equalivent instead of a range condition check.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;

Review comment:
       Please use `Assert.assertEqual()` instead of `assert` keyword.
   Is this result not deterministic? If the result is consistent of in every test running, please check the equalivent instead of a range condition check.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPthSym1() {
+    String sqlStr = "select ptnsym(d1.s1, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym2() {
+    String sqlStr = "select ptnsym(d1.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym3() {
+    String sqlStr = "select ptnsym(d2.s1, 'window'='3', 'threshold'='0') from";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym4() {
+    String sqlStr = "select ptnsym(d2.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr1() {
+    String sqlStr = "select xcorr(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr2() {
+    String sqlStr = "select xcorr(d1.s2, d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);

Review comment:
       As we have discussed previously, please check the equalivent between expected and acutal data returned, not only row counts.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPthSym1() {
+    String sqlStr = "select ptnsym(d1.s1, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym2() {
+    String sqlStr = "select ptnsym(d1.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym3() {
+    String sqlStr = "select ptnsym(d2.s1, 'window'='3', 'threshold'='0') from";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym4() {
+    String sqlStr = "select ptnsym(d2.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);

Review comment:
       As we have discussed previously, please check the equalivent between expected and acutal data returned, not only row counts.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPthSym1() {
+    String sqlStr = "select ptnsym(d1.s1, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym2() {
+    String sqlStr = "select ptnsym(d1.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);

Review comment:
       As we have discussed previously, please check the equalivent between expected and acutal data returned, not only row counts.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPthSym1() {
+    String sqlStr = "select ptnsym(d1.s1, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);

Review comment:
       As we have discussed previously, please check the equalivent between expected and acutal data returned, not only row counts.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPthSym1() {
+    String sqlStr = "select ptnsym(d1.s1, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym2() {
+    String sqlStr = "select ptnsym(d1.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym3() {
+    String sqlStr = "select ptnsym(d2.s1, 'window'='3', 'threshold'='0') from";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym4() {
+    String sqlStr = "select ptnsym(d2.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr1() {
+    String sqlStr = "select xcorr(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);

Review comment:
       As we have discussed previously, please check the equalivent between expected and acutal data returned, not only row counts.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPthSym1() {
+    String sqlStr = "select ptnsym(d1.s1, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym2() {
+    String sqlStr = "select ptnsym(d1.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym3() {
+    String sqlStr = "select ptnsym(d2.s1, 'window'='3', 'threshold'='0') from";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);

Review comment:
       As we have discussed previously, please check the equalivent between expected and acutal data returned, not only row counts.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPthSym1() {
+    String sqlStr = "select ptnsym(d1.s1, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym2() {
+    String sqlStr = "select ptnsym(d1.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym3() {
+    String sqlStr = "select ptnsym(d2.s1, 'window'='3', 'threshold'='0') from";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym4() {
+    String sqlStr = "select ptnsym(d2.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr1() {
+    String sqlStr = "select xcorr(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr2() {
+    String sqlStr = "select xcorr(d1.s2, d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr3() {
+    String sqlStr = "select xcorr(d2.s1, d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);

Review comment:
       As we have discussed previously, please check the equalivent between expected and acutal data returned, not only row counts.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] FrankHWD commented on a change in pull request #4835: [IOTDB-2303]Library dmatch

Posted by GitBox <gi...@apache.org>.
FrankHWD commented on a change in pull request #4835:
URL: https://github.com/apache/iotdb/pull/4835#discussion_r815532533



##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");

Review comment:
       In my perspective, it seems that this problem has already been solved, as shown in line230-233 in the link of https://github.com/apache/iotdb/pull/4835/commits/9fd5d42e5852d07df8f17947c1437b53aa263d69. Actually there are two commits last week, one is [9fd5d42] proposed on last Wednesday, the other is [ac0e695] proposed on last Friday, and the pull-request is proposed on last Friday.
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] wangchao316 commented on a change in pull request #4835: [IOTDB-2303]Library dmatch

Posted by GitBox <gi...@apache.org>.
wangchao316 commented on a change in pull request #4835:
URL: https://github.com/apache/iotdb/pull/4835#discussion_r787605094



##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,586 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;

Review comment:
       the same above

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,586 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;

Review comment:
       please use assertEquals




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] coveralls edited a comment on pull request #4835: [IOTDB-2303]Library dmatch

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #4835:
URL: https://github.com/apache/iotdb/pull/4835#issuecomment-1013333654


   
   [![Coverage Status](https://coveralls.io/builds/45653066/badge)](https://coveralls.io/builds/45653066)
   
   Coverage decreased (-0.008%) to 68.083% when pulling **b1aeee89482cb7942157610a3aa3cc83e4862300 on trin1t:library-dmatch** into **001490bbd734eab37ee4dcc5530b0dac33603870 on apache:master**.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] coveralls commented on pull request #4835: [IOTDB-2303]Library dmatch

Posted by GitBox <gi...@apache.org>.
coveralls commented on pull request #4835:
URL: https://github.com/apache/iotdb/pull/4835#issuecomment-1013333654


   
   [![Coverage Status](https://coveralls.io/builds/45640979/badge)](https://coveralls.io/builds/45640979)
   
   Coverage decreased (-0.03%) to 68.063% when pulling **44eeac22999e79af546d7efd2f267e313e22cff9 on trin1t:library-dmatch** into **001490bbd734eab37ee4dcc5530b0dac33603870 on apache:master**.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] FrankHWD commented on a change in pull request #4835: [IOTDB-2303]Library dmatch

Posted by GitBox <gi...@apache.org>.
FrankHWD commented on a change in pull request #4835:
URL: https://github.com/apache/iotdb/pull/4835#discussion_r812903555



##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);

Review comment:
       Done.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] coveralls edited a comment on pull request #4835: [IOTDB-2303]Library dmatch

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #4835:
URL: https://github.com/apache/iotdb/pull/4835#issuecomment-1013333654


   
   [![Coverage Status](https://coveralls.io/builds/46811172/badge)](https://coveralls.io/builds/46811172)
   
   Coverage decreased (-0.3%) to 67.785% when pulling **9fd5d42e5852d07df8f17947c1437b53aa263d69 on trin1t:library-dmatch** into **001490bbd734eab37ee4dcc5530b0dac33603870 on apache:master**.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] FrankHWD commented on a change in pull request #4835: [IOTDB-2303]Library dmatch

Posted by GitBox <gi...@apache.org>.
FrankHWD commented on a change in pull request #4835:
URL: https://github.com/apache/iotdb/pull/4835#discussion_r815648628



##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson4() {
+    String sqlStr = "select pearson(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPthSym1() {
+    String sqlStr = "select ptnsym(d1.s1, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym2() {
+    String sqlStr = "select ptnsym(d1.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym3() {
+    String sqlStr = "select ptnsym(d2.s1, 'window'='3', 'threshold'='0') from";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPtnSym4() {
+    String sqlStr = "select ptnsym(d2.s2, 'window'='3', 'threshold'='0') from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr1() {
+    String sqlStr = "select xcorr(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr2() {
+    String sqlStr = "select xcorr(d1.s2, d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr3() {
+    String sqlStr = "select xcorr(d2.s1, d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testXCorr4() {
+    String sqlStr = "select xcorr(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 19);

Review comment:
       Thank you!




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] FrankHWD commented on a change in pull request #4835: [IOTDB-2303]Library dmatch

Posted by GitBox <gi...@apache.org>.
FrankHWD commented on a change in pull request #4835:
URL: https://github.com/apache/iotdb/pull/4835#discussion_r787835647



##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,586 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;

Review comment:
       Done.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,586 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;

Review comment:
       Done.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] FrankHWD commented on a change in pull request #4835: [IOTDB-2303]Library dmatch

Posted by GitBox <gi...@apache.org>.
FrankHWD commented on a change in pull request #4835:
URL: https://github.com/apache/iotdb/pull/4835#discussion_r810421400



##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";

Review comment:
       Done.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();

Review comment:
       Done.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);

Review comment:
       Done.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);

Review comment:
       Done.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;

Review comment:
       Done.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;

Review comment:
       Done.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;

Review comment:
       Done.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;

Review comment:
       Done.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;

Review comment:
       Done.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;

Review comment:
       Done.

##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s3) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 100, 100, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 200, 102, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 300, 104, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 400, 126, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 500, 108, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 600, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 700, 114, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 800, 112, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 900, 118, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s2,s4) values(%d,%d,%d)", 1000, 100, 106));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov2() {
+    String sqlStr = "select cov(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov3() {
+    String sqlStr = "select cov(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testCov4() {
+    String sqlStr = "select cov(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      Assert.assertEquals(resultSetLength, 1);
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw1() {
+    String sqlStr = "select dtw(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw2() {
+    String sqlStr = "select dtw(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw3() {
+    String sqlStr = "select dtw(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testDtw4() {
+    String sqlStr = "select dtw(d2.s2,d2.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      resultSet.last();
+      int resultSetLength = resultSet.getRow();
+      assert resultSetLength == 1;
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= 0.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson1() {
+    String sqlStr = "select pearson(d1.s1,d1.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson2() {
+    String sqlStr = "select pearson(d1.s2,d1.s4) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @Test
+  public void testPearson3() {
+    String sqlStr = "select pearson(d2.s1,d2.s3) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      Double result = Double.parseDouble(resultSet.getString(1));
+      assert result >= -0.0D && result <= 1.0D;

Review comment:
       Done.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] coveralls edited a comment on pull request #4835: [IOTDB-2303]Library dmatch

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #4835:
URL: https://github.com/apache/iotdb/pull/4835#issuecomment-1013333654


   
   [![Coverage Status](https://coveralls.io/builds/46879217/badge)](https://coveralls.io/builds/46879217)
   
   Coverage decreased (-0.3%) to 67.792% when pulling **ac0e6956ab526458fb4a0e18d9e8ccb65daf4e62 on trin1t:library-dmatch** into **001490bbd734eab37ee4dcc5530b0dac33603870 on apache:master**.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] ericpai commented on a change in pull request #4835: [IOTDB-2303]Library dmatch

Posted by GitBox <gi...@apache.org>.
ericpai commented on a change in pull request #4835:
URL: https://github.com/apache/iotdb/pull/4835#discussion_r815304589



##########
File path: library-udf/src/test/java/org/apache/iotdb/library/dmatch/DMatchTests.java
##########
@@ -0,0 +1,782 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dmatch;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.integration.env.ConfigFactory;
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+public class DMatchTests {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(5)
+        .setUdfTransformerMemoryBudgetInMB(5)
+        .setUdfReaderMemoryBudgetInMB(5);
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() throws MetadataException {
+    IoTDB.metaManager.setStorageGroup(new PartialPath("root.vehicle"));
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d1.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d2.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d3.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s1"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s2"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s3"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s4"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s5"),
+        TSDataType.INT32,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s6"),
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s7"),
+        TSDataType.FLOAT,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+    IoTDB.metaManager.createTimeseries(
+        new PartialPath("root.vehicle.d4.s8"),
+        TSDataType.DOUBLE,
+        TSEncoding.PLAIN,
+        CompressionType.UNCOMPRESSED,
+        null);
+  }
+
+  private static void generateData() {
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 100, 100, 100, 100, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 102, 102, 102, 102, 101, 101, 101, 101));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 104, 104, 104, 104, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 126, 126, 126, 126, 102, 102, 102, 102));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 108, 108, 108, 108, 103, 103, 103, 103));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 112, 112, 112, 112, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 114, 114, 114, 114, 104, 104, 104, 104));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 116, 116, 116, 116, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              900, 118, 118, 118, 118, 105, 105, 105, 105));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1000, 100, 100, 100, 100, 106, 106, 106, 106));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1100, 124, 124, 124, 124, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1200, 126, 126, 126, 126, 108, 108, 108, 108));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              1300, 116, 116, 116, 116, 105, 105, 105, 105));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              600, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              700, 1, 1, 1, 1, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              800, 1, 1, 1, 1, 2, 2, 2, 2));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              100, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              200, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              300, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              400, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              500, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              600, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              700, 1, 1, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              800, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              900, 3, 3, 3, 3));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1000, 2, 2, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d3(timestamp,s1,s2,s3,s4) values(%d,%d,%d,%d,%d)",
+              1100, 1, 1, 1, 1));
+
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              100, 0, 0, 0, 0, 6, 6, 6, 6));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              200, 2, 2, 2, 2, 7, 7, 7, 7));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              300, 3, 3, 3, 3, 0, 0, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              400, 4, 4, 4, 4, 9, 9, 9, 9));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d4(timestamp,s1,s2,s3,s4,s5,s6,s7,s8) values(%d,%d,%d,%d,%d,%d,%d,%d,%d))",
+              500, 5, 5, 5, 5, 10, 10, 10, 10));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function completeness as 'org.apache.iotdb.library.dmatch.UDAFCov'");
+      statement.execute("create function timeliness as 'org.apache.iotdb.library.dmatch.UDAFDtw'");
+      statement.execute(
+          "create function consistency as 'org.apache.iotdb.library.dmatch.UDAFPearson'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFPtnSym'");
+      statement.execute("create function validity as 'org.apache.iotdb.library.dmatch.UDTFXcorr'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+    ConfigFactory.getConfig()
+        .setUdfCollectorMemoryBudgetInMB(100)
+        .setUdfTransformerMemoryBudgetInMB(100)
+        .setUdfReaderMemoryBudgetInMB(100);
+  }
+
+  @Test
+  public void testCov1() {
+    String sqlStr = "select cov(d1.s1,d1.s5) from root.vehicle";
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery(sqlStr);
+      String result1 = resultSet.getString(1);
+      Assert.assertEquals("12.291666666666666", result1);

Review comment:
       The UDF returns values as DOUBLE, could you use `Assert.assertEquals(double expected , double actual, double error)` and `resultSet.getDouble(1)` instead of string comparation? Once a double is missing some precision in some environment, the tests will fail.
   This test case class has may string comparations, need to fix them all :(




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] coveralls edited a comment on pull request #4835: [IOTDB-2303]Library dmatch

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #4835:
URL: https://github.com/apache/iotdb/pull/4835#issuecomment-1013333654


   
   [![Coverage Status](https://coveralls.io/builds/45654025/badge)](https://coveralls.io/builds/45654025)
   
   Coverage decreased (-0.02%) to 68.075% when pulling **58d8546d35ff00b7b3094bd12c8833d1ff747ee3 on trin1t:library-dmatch** into **001490bbd734eab37ee4dcc5530b0dac33603870 on apache:master**.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org