You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ro...@apache.org on 2022/05/21 17:54:13 UTC

[iotdb] branch iotdb-3250 created (now 5282f4ee43)

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

rong pushed a change to branch iotdb-3250
in repository https://gitbox.apache.org/repos/asf/iotdb.git


      at 5282f4ee43 simplify PlanExecutor

This branch includes the following new commits:

     new 5c21e9a200 conf: udf dir
     new cc6d8b2868 Merge branch 'master' of github.com:apache/iotdb into iotdb-3250
     new f40c95f942 mv service package
     new 5282f4ee43 simplify PlanExecutor

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[iotdb] 01/04: conf: udf dir

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 5c21e9a200b67b286b1fb4894c4dd9f820d0c2e1
Author: Steve Yurong Su <ro...@apache.org>
AuthorDate: Sat May 21 22:11:00 2022 +0800

    conf: udf dir
---
 .../resources/conf/iotdb-confignode.properties      | 21 +++++++++++++++++++++
 .../iotdb/confignode/conf/ConfigNodeConf.java       | 12 ++++++++++++
 .../iotdb/confignode/conf/ConfigNodeConstant.java   |  1 +
 .../iotdb/confignode/conf/ConfigNodeDescriptor.java |  2 ++
 4 files changed, 36 insertions(+)

diff --git a/confignode/src/assembly/resources/conf/iotdb-confignode.properties b/confignode/src/assembly/resources/conf/iotdb-confignode.properties
index 86ec5c1cf8..b16a399ec3 100644
--- a/confignode/src/assembly/resources/conf/iotdb-confignode.properties
+++ b/confignode/src/assembly/resources/conf/iotdb-confignode.properties
@@ -211,6 +211,27 @@ target_confignode=0.0.0.0:22277
 # If its prefix is "/", then the path is absolute. Otherwise, it is relative.
 # proc_wal_dir=data/proc
 
+
+# UDF dir
+# If this property is unset, system will save the data in the default relative path directory under
+# the UDF folder(i.e., %CONFIGNODE_HOME%/data/udf).
+#
+# If it is absolute, system will save the data in exact location it points to.
+# If it is relative, system will save the data in the relative path directory it indicates under the
+# UDF folder.
+# Note: If data_dir is assigned an empty string(i.e.,zero-size), it will be handled as a relative
+# path.
+#
+# For Window platform
+# If its prefix is a drive specifier followed by "\\", or if its prefix is "\\\\", then the path is
+# absolute. Otherwise, it is relative.
+# udf_dir=data\\udf
+#
+# For Linux platform
+# If its prefix is "/", then the path is absolute. Otherwise, it is relative.
+# udf_dir=data/udf
+
+
 ####################
 ### Procedure Configuration
 ####################
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeConf.java b/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeConf.java
index 48e830d3e5..5362f9f95b 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeConf.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeConf.java
@@ -103,6 +103,10 @@ public class ConfigNodeConf {
   private String consensusDir =
       ConfigNodeConstant.DATA_DIR + File.separator + ConfigNodeConstant.CONSENSUS_FOLDER;
 
+  /** UDF directory, storage udf metadata and jars */
+  private String udfDir =
+      ConfigNodeConstant.DATA_DIR + File.separator + ConfigNodeConstant.UDF_FOLDER;
+
   /** Time partition interval in seconds */
   private long timePartitionInterval = 604800;
 
@@ -332,6 +336,14 @@ public class ConfigNodeConf {
     this.systemDir = systemDir;
   }
 
+  public String getUdfDir() {
+    return udfDir;
+  }
+
+  public void setUdfDir(String udfDir) {
+    this.udfDir = udfDir;
+  }
+
   public int getSchemaReplicationFactor() {
     return schemaReplicationFactor;
   }
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeConstant.java b/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeConstant.java
index 6725351fd4..da179fc8a7 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeConstant.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeConstant.java
@@ -42,6 +42,7 @@ public class ConfigNodeConstant {
   public static final String DATA_DIR = "data";
   public static final String CONF_DIR = "conf";
   public static final String CONSENSUS_FOLDER = "consensus";
+  public static final String UDF_FOLDER = "udf";
 
   public static final int MIN_SUPPORTED_JDK_VERSION = 8;
 
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeDescriptor.java b/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeDescriptor.java
index 94c0848516..b5c58efd92 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeDescriptor.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeDescriptor.java
@@ -175,6 +175,8 @@ public class ConfigNodeDescriptor {
 
       conf.setConsensusDir(properties.getProperty("consensus_dir", conf.getConsensusDir()));
 
+      conf.setUdfDir(properties.getProperty("udf_dir", conf.getUdfDir()));
+
       conf.setTimePartitionInterval(
           Long.parseLong(
               properties.getProperty(


[iotdb] 03/04: mv service package

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit f40c95f9422893de9873f38a398c70e4d03ed6f0
Author: Steve Yurong Su <ro...@apache.org>
AuthorDate: Sun May 22 01:29:39 2022 +0800

    mv service package
---
 .../IoTDBSyntaxConventionStringLiteralIT.java      |  4 +-
 .../iotdb/db/integration/IoTDBUDFManagementIT.java | 12 +--
 .../commons/udf/api/exception/UDFException.java    |  2 +-
 .../api}/exception/UDFRegistrationException.java   |  6 +-
 .../udf/builtin/BuiltinAggregationFunction.java    | 59 ++++++++++++++
 ...va => BuiltinTimeSeriesGeneratingFunction.java} |  4 +-
 .../iotdb/commons}/udf/service/UDFClassLoader.java |  4 +-
 .../udf/service/UDFClassLoaderManager.java         | 30 +++----
 .../iotdb/commons}/udf/service/UDFLogWriter.java   |  2 +-
 .../udf/service/UDFRegistrationInformation.java    |  2 +-
 .../udf/service/UDFRegistrationService.java        | 91 +++++++++++-----------
 .../operator/process/TransformOperator.java        |  4 +-
 .../plan/expression/multi/FunctionExpression.java  |  8 +-
 .../db/mpp/transformation/dag/udf/UDTFContext.java |  2 +-
 .../mpp/transformation/dag/udf/UDTFExecutor.java   |  2 +-
 .../transformation/dag/udf/UDTFTypeInferrer.java   |  2 +-
 .../apache/iotdb/db/qp/constant/SQLConstant.java   | 31 +-------
 .../apache/iotdb/db/qp/executor/PlanExecutor.java  | 17 ++--
 .../apache/iotdb/db/query/dataset/UDTFDataSet.java |  4 +-
 .../java/org/apache/iotdb/db/service/DataNode.java | 16 +++-
 .../java/org/apache/iotdb/db/service/IoTDB.java    | 16 +++-
 .../iotdb/db/qp/physical/PhysicalPlanTest.java     |  2 +-
 .../apache/iotdb/db/utils/EnvironmentUtils.java    |  4 +-
 23 files changed, 188 insertions(+), 136 deletions(-)

diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBSyntaxConventionStringLiteralIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBSyntaxConventionStringLiteralIT.java
index 957c967453..06e7390c94 100644
--- a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBSyntaxConventionStringLiteralIT.java
+++ b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBSyntaxConventionStringLiteralIT.java
@@ -18,7 +18,7 @@
  */
 package org.apache.iotdb.db.integration;
 
-import org.apache.iotdb.commons.udf.builtin.BuiltinFunction;
+import org.apache.iotdb.commons.udf.builtin.BuiltinTimeSeriesGeneratingFunction;
 import org.apache.iotdb.integration.env.EnvFactory;
 import org.apache.iotdb.itbase.category.ClusterTest;
 import org.apache.iotdb.itbase.category.LocalStandaloneTest;
@@ -448,7 +448,7 @@ public class IoTDBSyntaxConventionStringLiteralIT {
         }
         ++count;
       }
-      Assert.assertEquals(1 + BuiltinFunction.values().length, count);
+      Assert.assertEquals(1 + BuiltinTimeSeriesGeneratingFunction.values().length, count);
       resultSet.close();
       statement.execute("drop function udf");
 
diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBUDFManagementIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBUDFManagementIT.java
index 84c1920805..8957bb4a8a 100644
--- a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBUDFManagementIT.java
+++ b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBUDFManagementIT.java
@@ -20,9 +20,9 @@
 package org.apache.iotdb.db.integration;
 
 import org.apache.iotdb.commons.path.PartialPath;
-import org.apache.iotdb.commons.udf.builtin.BuiltinFunction;
-import org.apache.iotdb.db.qp.constant.SQLConstant;
-import org.apache.iotdb.db.query.udf.service.UDFRegistrationService;
+import org.apache.iotdb.commons.udf.builtin.BuiltinAggregationFunction;
+import org.apache.iotdb.commons.udf.builtin.BuiltinTimeSeriesGeneratingFunction;
+import org.apache.iotdb.commons.udf.service.UDFRegistrationService;
 import org.apache.iotdb.db.service.IoTDB;
 import org.apache.iotdb.db.utils.EnvironmentUtils;
 import org.apache.iotdb.itbase.category.LocalStandaloneTest;
@@ -53,8 +53,10 @@ import static org.junit.Assert.fail;
 @Category({LocalStandaloneTest.class})
 public class IoTDBUDFManagementIT {
 
-  private static final int NATIVE_FUNCTIONS_COUNT = SQLConstant.getNativeFunctionNames().size();
-  private static final int BUILTIN_FUNCTIONS_COUNT = BuiltinFunction.values().length;
+  private static final int NATIVE_FUNCTIONS_COUNT =
+      BuiltinAggregationFunction.getNativeFunctionNames().size();
+  private static final int BUILTIN_FUNCTIONS_COUNT =
+      BuiltinTimeSeriesGeneratingFunction.values().length;
 
   @Before
   public void setUp() throws Exception {
diff --git a/node-commons/src/main/java/org/apache/iotdb/commons/udf/api/exception/UDFException.java b/node-commons/src/main/java/org/apache/iotdb/commons/udf/api/exception/UDFException.java
index c4a974cd34..8c21d7f51d 100644
--- a/node-commons/src/main/java/org/apache/iotdb/commons/udf/api/exception/UDFException.java
+++ b/node-commons/src/main/java/org/apache/iotdb/commons/udf/api/exception/UDFException.java
@@ -19,7 +19,7 @@
 
 package org.apache.iotdb.commons.udf.api.exception;
 
-public class UDFException extends Exception {
+public class UDFException extends RuntimeException {
 
   public UDFException(String message) {
     super(message);
diff --git a/server/src/main/java/org/apache/iotdb/db/exception/UDFRegistrationException.java b/node-commons/src/main/java/org/apache/iotdb/commons/udf/api/exception/UDFRegistrationException.java
similarity index 85%
rename from server/src/main/java/org/apache/iotdb/db/exception/UDFRegistrationException.java
rename to node-commons/src/main/java/org/apache/iotdb/commons/udf/api/exception/UDFRegistrationException.java
index 82527e989d..d02d1851d9 100644
--- a/server/src/main/java/org/apache/iotdb/db/exception/UDFRegistrationException.java
+++ b/node-commons/src/main/java/org/apache/iotdb/commons/udf/api/exception/UDFRegistrationException.java
@@ -17,11 +17,9 @@
  * under the License.
  */
 
-package org.apache.iotdb.db.exception;
+package org.apache.iotdb.commons.udf.api.exception;
 
-import org.apache.iotdb.db.exception.query.QueryProcessException;
-
-public class UDFRegistrationException extends QueryProcessException {
+public class UDFRegistrationException extends UDFException {
 
   public UDFRegistrationException(String message, Throwable cause) {
     super(message);
diff --git a/node-commons/src/main/java/org/apache/iotdb/commons/udf/builtin/BuiltinAggregationFunction.java b/node-commons/src/main/java/org/apache/iotdb/commons/udf/builtin/BuiltinAggregationFunction.java
new file mode 100644
index 0000000000..5f855c60fd
--- /dev/null
+++ b/node-commons/src/main/java/org/apache/iotdb/commons/udf/builtin/BuiltinAggregationFunction.java
@@ -0,0 +1,59 @@
+/*
+ * 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.commons.udf.builtin;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+public enum BuiltinAggregationFunction {
+  MIN_TIME("min_time"),
+  MAX_TIME("max_value"),
+  MAX_VALUE("max_value"),
+  MIN_VALUE("min_value"),
+  EXTREME("extreme"),
+  FIRST_VALUE("first_value"),
+  LAST_VALUE("last_value"),
+  COUNT("count"),
+  AVG("avg"),
+  SUM("sum"),
+  ;
+
+  private final String functionName;
+
+  BuiltinAggregationFunction(String functionName) {
+    this.functionName = functionName;
+  }
+
+  public String getFunctionName() {
+    return functionName;
+  }
+
+  private static final Set<String> NATIVE_FUNCTION_NAMES =
+      new HashSet<>(
+          Arrays.stream(BuiltinAggregationFunction.values())
+              .map(BuiltinAggregationFunction::getFunctionName)
+              .collect(Collectors.toList()));
+
+  public static Set<String> getNativeFunctionNames() {
+    return NATIVE_FUNCTION_NAMES;
+  }
+}
diff --git a/node-commons/src/main/java/org/apache/iotdb/commons/udf/builtin/BuiltinFunction.java b/node-commons/src/main/java/org/apache/iotdb/commons/udf/builtin/BuiltinTimeSeriesGeneratingFunction.java
similarity index 96%
rename from node-commons/src/main/java/org/apache/iotdb/commons/udf/builtin/BuiltinFunction.java
rename to node-commons/src/main/java/org/apache/iotdb/commons/udf/builtin/BuiltinTimeSeriesGeneratingFunction.java
index ed8bc85d33..4208735bcb 100644
--- a/node-commons/src/main/java/org/apache/iotdb/commons/udf/builtin/BuiltinFunction.java
+++ b/node-commons/src/main/java/org/apache/iotdb/commons/udf/builtin/BuiltinTimeSeriesGeneratingFunction.java
@@ -20,7 +20,7 @@
 package org.apache.iotdb.commons.udf.builtin;
 
 /** All built-in UDFs need to register their function names and classes here. */
-public enum BuiltinFunction {
+public enum BuiltinTimeSeriesGeneratingFunction {
   CONST("CONST", UDTFConst.class),
   E("E", UDTFConstE.class),
   PI("PI", UDTFConstPi.class),
@@ -72,7 +72,7 @@ public enum BuiltinFunction {
   private final Class<?> functionClass;
   private final String className;
 
-  BuiltinFunction(String functionName, Class<?> functionClass) {
+  BuiltinTimeSeriesGeneratingFunction(String functionName, Class<?> functionClass) {
     this.functionName = functionName;
     this.functionClass = functionClass;
     this.className = functionClass.getName();
diff --git a/server/src/main/java/org/apache/iotdb/db/query/udf/service/UDFClassLoader.java b/node-commons/src/main/java/org/apache/iotdb/commons/udf/service/UDFClassLoader.java
similarity index 95%
rename from server/src/main/java/org/apache/iotdb/db/query/udf/service/UDFClassLoader.java
rename to node-commons/src/main/java/org/apache/iotdb/commons/udf/service/UDFClassLoader.java
index d877713a53..ebbe4d65b8 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/udf/service/UDFClassLoader.java
+++ b/node-commons/src/main/java/org/apache/iotdb/commons/udf/service/UDFClassLoader.java
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.iotdb.db.query.udf.service;
+package org.apache.iotdb.commons.udf.service;
 
 import org.apache.iotdb.commons.file.SystemFileFactory;
 
@@ -46,7 +46,7 @@ public class UDFClassLoader extends URLClassLoader {
    */
   private volatile boolean deprecated;
 
-  UDFClassLoader(String libRoot) throws IOException {
+  public UDFClassLoader(String libRoot) throws IOException {
     super(new URL[0]);
     this.libRoot = libRoot;
     activeQueriesCount = new AtomicLong(0);
diff --git a/server/src/main/java/org/apache/iotdb/db/query/udf/service/UDFClassLoaderManager.java b/node-commons/src/main/java/org/apache/iotdb/commons/udf/service/UDFClassLoaderManager.java
similarity index 85%
rename from server/src/main/java/org/apache/iotdb/db/query/udf/service/UDFClassLoaderManager.java
rename to node-commons/src/main/java/org/apache/iotdb/commons/udf/service/UDFClassLoaderManager.java
index 99cf877d3e..230f3c222c 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/udf/service/UDFClassLoaderManager.java
+++ b/node-commons/src/main/java/org/apache/iotdb/commons/udf/service/UDFClassLoaderManager.java
@@ -17,13 +17,12 @@
  * under the License.
  */
 
-package org.apache.iotdb.db.query.udf.service;
+package org.apache.iotdb.commons.udf.service;
 
 import org.apache.iotdb.commons.exception.StartupException;
 import org.apache.iotdb.commons.file.SystemFileFactory;
 import org.apache.iotdb.commons.service.IService;
 import org.apache.iotdb.commons.service.ServiceType;
-import org.apache.iotdb.db.conf.IoTDBDescriptor;
 
 import org.apache.commons.io.FileUtils;
 import org.slf4j.Logger;
@@ -36,7 +35,7 @@ import java.util.concurrent.ConcurrentHashMap;
 
 public class UDFClassLoaderManager implements IService {
 
-  private static final Logger logger = LoggerFactory.getLogger(UDFClassLoaderManager.class);
+  private static final Logger LOGGER = LoggerFactory.getLogger(UDFClassLoaderManager.class);
 
   private final String libRoot;
 
@@ -50,9 +49,9 @@ public class UDFClassLoaderManager implements IService {
    */
   private volatile UDFClassLoader activeClassLoader;
 
-  UDFClassLoaderManager() {
-    libRoot = IoTDBDescriptor.getInstance().getConfig().getUdfDir();
-    logger.info("UDF lib root: {}", libRoot);
+  private UDFClassLoaderManager(String libRoot) {
+    this.libRoot = libRoot;
+    LOGGER.info("UDF lib root: {}", libRoot);
     queryIdToUDFClassLoaderMap = new ConcurrentHashMap<>();
     activeClassLoader = null;
   }
@@ -67,7 +66,7 @@ public class UDFClassLoaderManager implements IService {
     try {
       classLoader.release();
     } catch (IOException e) {
-      logger.warn(
+      LOGGER.warn(
           "Failed to close UDFClassLoader (queryId: {}), because {}", queryId, e.toString());
     }
   }
@@ -111,14 +110,17 @@ public class UDFClassLoaderManager implements IService {
     return ServiceType.UDF_CLASSLOADER_MANAGER_SERVICE;
   }
 
-  public static UDFClassLoaderManager getInstance() {
-    return UDFClassLoaderManager.UDFClassLoaderManagerHelper.INSTANCE;
-  }
-
-  private static class UDFClassLoaderManagerHelper {
+  private static UDFClassLoaderManager INSTANCE = null;
 
-    private static final UDFClassLoaderManager INSTANCE = new UDFClassLoaderManager();
+  public static synchronized UDFClassLoaderManager setupAndGetInstance(String libRoot) {
+    if (INSTANCE == null) {
+      INSTANCE = new UDFClassLoaderManager(libRoot);
+      return INSTANCE;
+    }
+    throw new UnsupportedOperationException();
+  }
 
-    private UDFClassLoaderManagerHelper() {}
+  public static UDFClassLoaderManager getInstance() {
+    return UDFClassLoaderManager.INSTANCE;
   }
 }
diff --git a/server/src/main/java/org/apache/iotdb/db/query/udf/service/UDFLogWriter.java b/node-commons/src/main/java/org/apache/iotdb/commons/udf/service/UDFLogWriter.java
similarity index 97%
rename from server/src/main/java/org/apache/iotdb/db/query/udf/service/UDFLogWriter.java
rename to node-commons/src/main/java/org/apache/iotdb/commons/udf/service/UDFLogWriter.java
index 03d2fa70df..51068cf99b 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/udf/service/UDFLogWriter.java
+++ b/node-commons/src/main/java/org/apache/iotdb/commons/udf/service/UDFLogWriter.java
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.iotdb.db.query.udf.service;
+package org.apache.iotdb.commons.udf.service;
 
 import org.apache.iotdb.commons.file.SystemFileFactory;
 
diff --git a/server/src/main/java/org/apache/iotdb/db/query/udf/service/UDFRegistrationInformation.java b/node-commons/src/main/java/org/apache/iotdb/commons/udf/service/UDFRegistrationInformation.java
similarity index 97%
rename from server/src/main/java/org/apache/iotdb/db/query/udf/service/UDFRegistrationInformation.java
rename to node-commons/src/main/java/org/apache/iotdb/commons/udf/service/UDFRegistrationInformation.java
index 729629c0b2..a4997ead0b 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/udf/service/UDFRegistrationInformation.java
+++ b/node-commons/src/main/java/org/apache/iotdb/commons/udf/service/UDFRegistrationInformation.java
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.iotdb.db.query.udf.service;
+package org.apache.iotdb.commons.udf.service;
 
 import org.apache.iotdb.commons.udf.api.UDTF;
 
diff --git a/server/src/main/java/org/apache/iotdb/db/query/udf/service/UDFRegistrationService.java b/node-commons/src/main/java/org/apache/iotdb/commons/udf/service/UDFRegistrationService.java
similarity index 84%
rename from server/src/main/java/org/apache/iotdb/db/query/udf/service/UDFRegistrationService.java
rename to node-commons/src/main/java/org/apache/iotdb/commons/udf/service/UDFRegistrationService.java
index 6c890da7f2..0133f227d8 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/udf/service/UDFRegistrationService.java
+++ b/node-commons/src/main/java/org/apache/iotdb/commons/udf/service/UDFRegistrationService.java
@@ -17,18 +17,17 @@
  * under the License.
  */
 
-package org.apache.iotdb.db.query.udf.service;
+package org.apache.iotdb.commons.udf.service;
 
 import org.apache.iotdb.commons.exception.StartupException;
 import org.apache.iotdb.commons.file.SystemFileFactory;
 import org.apache.iotdb.commons.service.IService;
 import org.apache.iotdb.commons.service.ServiceType;
 import org.apache.iotdb.commons.udf.api.UDF;
-import org.apache.iotdb.commons.udf.builtin.BuiltinFunction;
+import org.apache.iotdb.commons.udf.api.exception.UDFRegistrationException;
+import org.apache.iotdb.commons.udf.builtin.BuiltinAggregationFunction;
+import org.apache.iotdb.commons.udf.builtin.BuiltinTimeSeriesGeneratingFunction;
 import org.apache.iotdb.commons.utils.TestOnly;
-import org.apache.iotdb.db.conf.IoTDBDescriptor;
-import org.apache.iotdb.db.exception.UDFRegistrationException;
-import org.apache.iotdb.db.qp.constant.SQLConstant;
 import org.apache.iotdb.tsfile.fileSystem.FSFactoryProducer;
 
 import org.apache.commons.io.FileUtils;
@@ -48,15 +47,11 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 public class UDFRegistrationService implements IService {
 
-  private static final Logger logger = LoggerFactory.getLogger(UDFRegistrationService.class);
+  private static final Logger LOGGER = LoggerFactory.getLogger(UDFRegistrationService.class);
 
-  private static final String ULOG_FILE_DIR =
-      IoTDBDescriptor.getInstance().getConfig().getSystemDir()
-          + File.separator
-          + "udf"
-          + File.separator;
-  private static final String LOG_FILE_NAME = ULOG_FILE_DIR + "ulog.txt";
-  private static final String TEMPORARY_LOG_FILE_NAME = LOG_FILE_NAME + ".tmp";
+  private final String ulogFileDir;
+  private final String logFileName;
+  private final String temporaryLogFileName;
 
   private final ReentrantLock registrationLock;
   private final ConcurrentHashMap<String, UDFRegistrationInformation> registrationInformation;
@@ -64,7 +59,11 @@ public class UDFRegistrationService implements IService {
   private final ReentrantReadWriteLock logWriterLock;
   private UDFLogWriter logWriter;
 
-  private UDFRegistrationService() {
+  private UDFRegistrationService(String ulogFileDir) {
+    this.ulogFileDir = ulogFileDir;
+    logFileName = ulogFileDir + "ulog.txt";
+    temporaryLogFileName = logFileName + ".tmp";
+
     registrationLock = new ReentrantLock();
     registrationInformation = new ConcurrentHashMap<>();
     logWriterLock = new ReentrantReadWriteLock();
@@ -89,7 +88,7 @@ public class UDFRegistrationService implements IService {
 
   private static void validateFunctionName(String functionName, String className)
       throws UDFRegistrationException {
-    if (!SQLConstant.getNativeFunctionNames().contains(functionName.toLowerCase())) {
+    if (!BuiltinAggregationFunction.getNativeFunctionNames().contains(functionName.toLowerCase())) {
       return;
     }
 
@@ -98,7 +97,7 @@ public class UDFRegistrationService implements IService {
             "Failed to register UDF %s(%s), because the given function name conflicts with the built-in function name",
             functionName, className);
 
-    logger.warn(errorMessage);
+    LOGGER.warn(errorMessage);
     throw new UDFRegistrationException(errorMessage);
   }
 
@@ -129,7 +128,7 @@ public class UDFRegistrationService implements IService {
       }
     }
 
-    logger.warn(errorMessage);
+    LOGGER.warn(errorMessage);
     throw new UDFRegistrationException(errorMessage);
   }
 
@@ -155,7 +154,7 @@ public class UDFRegistrationService implements IService {
           String.format(
               "Failed to register UDF %s(%s), because its instance can not be constructed successfully. Exception: %s",
               functionName, className, e);
-      logger.warn(errorMessage);
+      LOGGER.warn(errorMessage);
       throw new UDFRegistrationException(errorMessage);
     } finally {
       releaseRegistrationLock();
@@ -177,7 +176,7 @@ public class UDFRegistrationService implements IService {
           String.format(
               "Failed to append UDF log when registering UDF %s(%s), because %s",
               functionName, className, e);
-      logger.error(errorMessage);
+      LOGGER.error(errorMessage);
       throw new UDFRegistrationException(errorMessage, e);
     }
   }
@@ -196,14 +195,14 @@ public class UDFRegistrationService implements IService {
     UDFRegistrationInformation information = registrationInformation.get(functionName);
     if (information == null) {
       String errorMessage = String.format("UDF %s does not exist.", functionName);
-      logger.warn(errorMessage);
+      LOGGER.warn(errorMessage);
       throw new UDFRegistrationException(errorMessage);
     }
 
     if (information.isBuiltin()) {
       String errorMessage =
           String.format("Built-in function %s can not be deregistered.", functionName);
-      logger.error(errorMessage);
+      LOGGER.error(errorMessage);
       throw new UDFRegistrationException(errorMessage);
     }
 
@@ -214,7 +213,7 @@ public class UDFRegistrationService implements IService {
       String errorMessage =
           String.format(
               "Failed to append UDF log when deregistering UDF %s, because %s", functionName, e);
-      logger.error(errorMessage);
+      LOGGER.error(errorMessage);
       throw new UDFRegistrationException(errorMessage, e);
     }
   }
@@ -245,7 +244,7 @@ public class UDFRegistrationService implements IService {
           String.format(
               "Failed to reflect UDF instance, because UDF %s has not been registered.",
               functionName);
-      logger.warn(errorMessage);
+      LOGGER.warn(errorMessage);
       throw new RuntimeException(errorMessage);
     }
 
@@ -264,7 +263,7 @@ public class UDFRegistrationService implements IService {
           String.format(
               "Failed to reflect UDF %s(%s) instance, because %s",
               functionName, information.getClassName(), e);
-      logger.warn(errorMessage);
+      LOGGER.warn(errorMessage);
       throw new RuntimeException(errorMessage);
     }
   }
@@ -276,30 +275,31 @@ public class UDFRegistrationService implements IService {
   @Override
   public void start() throws StartupException {
     try {
-      registerBuiltinFunctions();
+      registerBuiltinTimeSeriesGeneratingFunctions();
       makeDirIfNecessary();
       doRecovery();
-      logWriter = new UDFLogWriter(LOG_FILE_NAME);
+      logWriter = new UDFLogWriter(logFileName);
     } catch (Exception e) {
       throw new StartupException(e);
     }
   }
 
-  private void registerBuiltinFunctions() {
-    for (BuiltinFunction builtinFunction : BuiltinFunction.values()) {
-      String functionName = builtinFunction.getFunctionName();
+  private void registerBuiltinTimeSeriesGeneratingFunctions() {
+    for (BuiltinTimeSeriesGeneratingFunction builtinTimeSeriesGeneratingFunction :
+        BuiltinTimeSeriesGeneratingFunction.values()) {
+      String functionName = builtinTimeSeriesGeneratingFunction.getFunctionName();
       registrationInformation.put(
           functionName,
           new UDFRegistrationInformation(
               functionName,
-              builtinFunction.getClassName(),
+              builtinTimeSeriesGeneratingFunction.getClassName(),
               true,
-              builtinFunction.getFunctionClass()));
+              builtinTimeSeriesGeneratingFunction.getFunctionClass()));
     }
   }
 
   private void makeDirIfNecessary() throws IOException {
-    File file = SystemFileFactory.INSTANCE.getFile(ULOG_FILE_DIR);
+    File file = SystemFileFactory.INSTANCE.getFile(ulogFileDir);
     if (file.exists() && file.isDirectory()) {
       return;
     }
@@ -307,8 +307,8 @@ public class UDFRegistrationService implements IService {
   }
 
   private void doRecovery() throws IOException {
-    File temporaryLogFile = SystemFileFactory.INSTANCE.getFile(TEMPORARY_LOG_FILE_NAME);
-    File logFile = SystemFileFactory.INSTANCE.getFile(LOG_FILE_NAME);
+    File temporaryLogFile = SystemFileFactory.INSTANCE.getFile(temporaryLogFileName);
+    File logFile = SystemFileFactory.INSTANCE.getFile(logFileName);
 
     if (temporaryLogFile.exists()) {
       if (logFile.exists()) {
@@ -356,8 +356,8 @@ public class UDFRegistrationService implements IService {
       logWriter.close();
       logWriter.deleteLogFile();
 
-      File temporaryLogFile = SystemFileFactory.INSTANCE.getFile(TEMPORARY_LOG_FILE_NAME);
-      File logFile = SystemFileFactory.INSTANCE.getFile(LOG_FILE_NAME);
+      File temporaryLogFile = SystemFileFactory.INSTANCE.getFile(temporaryLogFileName);
+      File logFile = SystemFileFactory.INSTANCE.getFile(logFileName);
       FSFactoryProducer.getFSFactory().moveFile(temporaryLogFile, logFile);
     } catch (IOException ignored) {
       // ignored
@@ -365,7 +365,7 @@ public class UDFRegistrationService implements IService {
   }
 
   private void writeTemporaryLogFile() throws IOException {
-    UDFLogWriter temporaryLogFile = new UDFLogWriter(TEMPORARY_LOG_FILE_NAME);
+    UDFLogWriter temporaryLogFile = new UDFLogWriter(temporaryLogFileName);
     for (UDFRegistrationInformation information : registrationInformation.values()) {
       if (information.isBuiltin()) {
         continue;
@@ -404,14 +404,17 @@ public class UDFRegistrationService implements IService {
     return ServiceType.UDF_REGISTRATION_SERVICE;
   }
 
-  public static UDFRegistrationService getInstance() {
-    return UDFRegistrationService.UDFRegistrationServiceHelper.INSTANCE;
-  }
-
-  private static class UDFRegistrationServiceHelper {
+  private static UDFRegistrationService INSTANCE = null;
 
-    private static final UDFRegistrationService INSTANCE = new UDFRegistrationService();
+  public static synchronized UDFRegistrationService setupAndGetInstance(String ulogFileDir) {
+    if (INSTANCE == null) {
+      INSTANCE = new UDFRegistrationService(ulogFileDir);
+      return INSTANCE;
+    }
+    throw new UnsupportedOperationException();
+  }
 
-    private UDFRegistrationServiceHelper() {}
+  public static UDFRegistrationService getInstance() {
+    return UDFRegistrationService.INSTANCE;
   }
 }
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/TransformOperator.java b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/TransformOperator.java
index ed0dbb0f86..c66d3d3c98 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/TransformOperator.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/TransformOperator.java
@@ -19,6 +19,8 @@
 
 package org.apache.iotdb.db.mpp.execution.operator.process;
 
+import org.apache.iotdb.commons.udf.service.UDFClassLoaderManager;
+import org.apache.iotdb.commons.udf.service.UDFRegistrationService;
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
 import org.apache.iotdb.db.exception.query.QueryProcessException;
 import org.apache.iotdb.db.mpp.execution.operator.Operator;
@@ -31,8 +33,6 @@ import org.apache.iotdb.db.mpp.transformation.dag.builder.EvaluationDAGBuilder;
 import org.apache.iotdb.db.mpp.transformation.dag.input.QueryDataSetInputLayer;
 import org.apache.iotdb.db.mpp.transformation.dag.input.TsBlockInputDataSet;
 import org.apache.iotdb.db.mpp.transformation.dag.udf.UDTFContext;
-import org.apache.iotdb.db.query.udf.service.UDFClassLoaderManager;
-import org.apache.iotdb.db.query.udf.service.UDFRegistrationService;
 import org.apache.iotdb.db.utils.datastructure.TimeSelector;
 import org.apache.iotdb.tsfile.exception.write.UnSupportedDataTypeException;
 import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/expression/multi/FunctionExpression.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/expression/multi/FunctionExpression.java
index 8dbe67c10d..61a2b45dbf 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/expression/multi/FunctionExpression.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/expression/multi/FunctionExpression.java
@@ -22,6 +22,7 @@ package org.apache.iotdb.db.mpp.plan.expression.multi;
 import org.apache.iotdb.commons.conf.IoTDBConstant;
 import org.apache.iotdb.commons.path.PartialPath;
 import org.apache.iotdb.commons.udf.api.customizer.strategy.AccessStrategy;
+import org.apache.iotdb.commons.udf.builtin.BuiltinAggregationFunction;
 import org.apache.iotdb.db.exception.query.LogicalOptimizeException;
 import org.apache.iotdb.db.exception.query.QueryProcessException;
 import org.apache.iotdb.db.exception.sql.SemanticException;
@@ -44,7 +45,6 @@ import org.apache.iotdb.db.mpp.transformation.dag.transformer.unary.TransparentT
 import org.apache.iotdb.db.mpp.transformation.dag.udf.UDTFContext;
 import org.apache.iotdb.db.mpp.transformation.dag.udf.UDTFExecutor;
 import org.apache.iotdb.db.mpp.transformation.dag.udf.UDTFTypeInferrer;
-import org.apache.iotdb.db.qp.constant.SQLConstant;
 import org.apache.iotdb.db.qp.physical.crud.UDTFPlan;
 import org.apache.iotdb.db.qp.strategy.optimizer.ConcatPathOptimizer;
 import org.apache.iotdb.db.utils.TypeInferenceUtils;
@@ -93,7 +93,7 @@ public class FunctionExpression extends Expression {
     expressions = new ArrayList<>();
 
     isBuiltInAggregationFunctionExpression =
-        SQLConstant.getNativeFunctionNames().contains(functionName.toLowerCase());
+        BuiltinAggregationFunction.getNativeFunctionNames().contains(functionName.toLowerCase());
     isConstantOperandCache = true;
   }
 
@@ -104,7 +104,7 @@ public class FunctionExpression extends Expression {
     this.expressions = expressions;
 
     isBuiltInAggregationFunctionExpression =
-        SQLConstant.getNativeFunctionNames().contains(functionName.toLowerCase());
+        BuiltinAggregationFunction.getNativeFunctionNames().contains(functionName.toLowerCase());
     isConstantOperandCache = expressions.stream().anyMatch(Expression::isConstantOperand);
     isUserDefinedAggregationFunctionExpression =
         expressions.stream()
@@ -124,7 +124,7 @@ public class FunctionExpression extends Expression {
     }
 
     isBuiltInAggregationFunctionExpression =
-        SQLConstant.getNativeFunctionNames().contains(functionName);
+        BuiltinAggregationFunction.getNativeFunctionNames().contains(functionName);
     isConstantOperandCache = expressions.stream().anyMatch(Expression::isConstantOperand);
     isUserDefinedAggregationFunctionExpression =
         expressions.stream()
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/udf/UDTFContext.java b/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/udf/UDTFContext.java
index 1876756d85..e1ea0ced1f 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/udf/UDTFContext.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/udf/UDTFContext.java
@@ -19,10 +19,10 @@
 
 package org.apache.iotdb.db.mpp.transformation.dag.udf;
 
+import org.apache.iotdb.commons.udf.service.UDFClassLoaderManager;
 import org.apache.iotdb.db.mpp.plan.expression.Expression;
 import org.apache.iotdb.db.mpp.plan.expression.ResultColumn;
 import org.apache.iotdb.db.mpp.plan.expression.multi.FunctionExpression;
-import org.apache.iotdb.db.query.udf.service.UDFClassLoaderManager;
 
 import java.time.ZoneId;
 import java.util.HashMap;
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/udf/UDTFExecutor.java b/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/udf/UDTFExecutor.java
index dd03c7e06c..3b58b5a386 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/udf/UDTFExecutor.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/udf/UDTFExecutor.java
@@ -26,8 +26,8 @@ import org.apache.iotdb.commons.udf.api.access.RowWindow;
 import org.apache.iotdb.commons.udf.api.customizer.config.UDTFConfigurations;
 import org.apache.iotdb.commons.udf.api.customizer.parameter.UDFParameterValidator;
 import org.apache.iotdb.commons.udf.api.customizer.parameter.UDFParameters;
+import org.apache.iotdb.commons.udf.service.UDFRegistrationService;
 import org.apache.iotdb.db.mpp.transformation.datastructure.tv.ElasticSerializableTVList;
-import org.apache.iotdb.db.query.udf.service.UDFRegistrationService;
 import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
 
 import org.slf4j.Logger;
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/udf/UDTFTypeInferrer.java b/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/udf/UDTFTypeInferrer.java
index 4e3342c202..70818c6a2e 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/udf/UDTFTypeInferrer.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/udf/UDTFTypeInferrer.java
@@ -24,8 +24,8 @@ import org.apache.iotdb.commons.udf.api.UDTF;
 import org.apache.iotdb.commons.udf.api.customizer.config.UDTFConfigurations;
 import org.apache.iotdb.commons.udf.api.customizer.parameter.UDFParameterValidator;
 import org.apache.iotdb.commons.udf.api.customizer.parameter.UDFParameters;
+import org.apache.iotdb.commons.udf.service.UDFRegistrationService;
 import org.apache.iotdb.db.exception.sql.SemanticException;
-import org.apache.iotdb.db.query.udf.service.UDFRegistrationService;
 import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
 
 import org.slf4j.Logger;
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/constant/SQLConstant.java b/server/src/main/java/org/apache/iotdb/db/qp/constant/SQLConstant.java
index d731bfee89..5551f4d817 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/constant/SQLConstant.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/constant/SQLConstant.java
@@ -20,14 +20,11 @@ package org.apache.iotdb.db.qp.constant;
 
 import org.apache.iotdb.commons.path.PartialPath;
 
-import java.util.Arrays;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Map;
-import java.util.Set;
 
 /** this class contains several constants used in SQL. */
-@SuppressWarnings("unused") // some fields are for future features
+// some fields are for future features
 public class SQLConstant {
 
   public SQLConstant() throws InstantiationException {
@@ -57,36 +54,16 @@ public class SQLConstant {
   // names of aggregations
   public static final String MIN_TIME = "min_time";
   public static final String MAX_TIME = "max_time";
-
   public static final String MAX_VALUE = "max_value";
   public static final String MIN_VALUE = "min_value";
-
   public static final String EXTREME = "extreme";
-
   public static final String FIRST_VALUE = "first_value";
   public static final String LAST_VALUE = "last_value";
-
-  public static final String LAST = "last";
-
   public static final String COUNT = "count";
   public static final String AVG = "avg";
   public static final String SUM = "sum";
 
-  public static final String ALL = "all";
-
-  private static final Set<String> NATIVE_FUNCTION_NAMES =
-      new HashSet<>(
-          Arrays.asList(
-              MIN_TIME,
-              MAX_TIME,
-              MIN_VALUE,
-              MAX_VALUE,
-              EXTREME,
-              FIRST_VALUE,
-              LAST_VALUE,
-              COUNT,
-              SUM,
-              AVG));
+  public static final String LAST = "last";
 
   public static final int TOK_WHERE = 23;
   public static final int TOK_INSERT = 24;
@@ -321,8 +298,4 @@ public class SQLConstant {
   public static boolean isNotReservedPath(PartialPath pathStr) {
     return !pathStr.equals(TIME_PATH);
   }
-
-  public static Set<String> getNativeFunctionNames() {
-    return NATIVE_FUNCTION_NAMES;
-  }
 }
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java b/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
index 9df6492e14..491b0f6d74 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
@@ -31,6 +31,10 @@ import org.apache.iotdb.commons.conf.IoTDBConstant;
 import org.apache.iotdb.commons.exception.IllegalPathException;
 import org.apache.iotdb.commons.exception.MetadataException;
 import org.apache.iotdb.commons.path.PartialPath;
+import org.apache.iotdb.commons.udf.api.exception.UDFRegistrationException;
+import org.apache.iotdb.commons.udf.builtin.BuiltinAggregationFunction;
+import org.apache.iotdb.commons.udf.service.UDFRegistrationInformation;
+import org.apache.iotdb.commons.udf.service.UDFRegistrationService;
 import org.apache.iotdb.commons.utils.AuthUtils;
 import org.apache.iotdb.db.auth.AuthorityChecker;
 import org.apache.iotdb.db.auth.AuthorizerManager;
@@ -51,7 +55,6 @@ import org.apache.iotdb.db.exception.QueryIdNotExsitException;
 import org.apache.iotdb.db.exception.StorageEngineException;
 import org.apache.iotdb.db.exception.TriggerExecutionException;
 import org.apache.iotdb.db.exception.TriggerManagementException;
-import org.apache.iotdb.db.exception.UDFRegistrationException;
 import org.apache.iotdb.db.exception.WriteProcessException;
 import org.apache.iotdb.db.exception.metadata.PathNotExistException;
 import org.apache.iotdb.db.exception.metadata.StorageGroupAlreadySetException;
@@ -64,7 +67,6 @@ import org.apache.iotdb.db.metadata.mnode.IMeasurementMNode;
 import org.apache.iotdb.db.metadata.mnode.IStorageGroupMNode;
 import org.apache.iotdb.db.metadata.path.MeasurementPath;
 import org.apache.iotdb.db.metadata.utils.MetaUtils;
-import org.apache.iotdb.db.qp.constant.SQLConstant;
 import org.apache.iotdb.db.qp.logical.Operator;
 import org.apache.iotdb.db.qp.logical.sys.AuthorOperator;
 import org.apache.iotdb.db.qp.logical.sys.AuthorOperator.AuthorType;
@@ -152,8 +154,6 @@ import org.apache.iotdb.db.query.dataset.ShowTimeseriesDataSet;
 import org.apache.iotdb.db.query.dataset.SingleDataSet;
 import org.apache.iotdb.db.query.executor.IQueryRouter;
 import org.apache.iotdb.db.query.executor.QueryRouter;
-import org.apache.iotdb.db.query.udf.service.UDFRegistrationInformation;
-import org.apache.iotdb.db.query.udf.service.UDFRegistrationService;
 import org.apache.iotdb.db.service.IoTDB;
 import org.apache.iotdb.db.service.SettleService;
 import org.apache.iotdb.db.sync.receiver.ReceiverService;
@@ -1090,7 +1090,6 @@ public class PlanExecutor implements IPlanExecutor {
     return listDataSet;
   }
 
-  @SuppressWarnings("squid:S3776")
   private void appendUDFs(ListDataSet listDataSet, ShowFunctionsPlan showPlan)
       throws QueryProcessException {
     for (UDFRegistrationInformation info :
@@ -1245,7 +1244,7 @@ public class PlanExecutor implements IPlanExecutor {
   private void appendNativeFunctions(ListDataSet listDataSet, ShowFunctionsPlan showPlan) {
     final Binary functionType = Binary.valueOf(FUNCTION_TYPE_NATIVE);
     final Binary className = Binary.valueOf("");
-    for (String functionName : SQLConstant.getNativeFunctionNames()) {
+    for (String functionName : BuiltinAggregationFunction.getNativeFunctionNames()) {
       RowRecord rowRecord = new RowRecord(0); // ignore timestamp
       rowRecord.addField(Binary.valueOf(functionName.toUpperCase()), TSDataType.TEXT);
       rowRecord.addField(functionType, TSDataType.TEXT);
@@ -1520,7 +1519,7 @@ public class PlanExecutor implements IPlanExecutor {
     }
   }
 
-  @SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity warning
+  // Suppress high Cognitive Complexity warning
   private void createSchemaAutomatically(
       List<ChunkGroupMetadata> chunkGroupMetadataList,
       Map<Path, IMeasurementSchema> knownSchemas,
@@ -2012,7 +2011,7 @@ public class PlanExecutor implements IPlanExecutor {
     return true;
   }
 
-  @SuppressWarnings("squid:S3776") // high Cognitive Complexity
+  // high Cognitive Complexity
   private boolean createMultiTimeSeries(CreateMultiTimeSeriesPlan multiPlan)
       throws BatchProcessException {
     int dataTypeIdx = 0;
@@ -2385,7 +2384,7 @@ public class PlanExecutor implements IPlanExecutor {
     }
   }
 
-  @SuppressWarnings("unused") // for the distributed version
+  // for the distributed version
   protected void loadConfiguration(LoadConfigurationPlan plan) throws QueryProcessException {
     IoTDBDescriptor.getInstance().loadHotModifiedProps();
   }
diff --git a/server/src/main/java/org/apache/iotdb/db/query/dataset/UDTFDataSet.java b/server/src/main/java/org/apache/iotdb/db/query/dataset/UDTFDataSet.java
index 1f816f1a2a..fdefb63b26 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/dataset/UDTFDataSet.java
+++ b/server/src/main/java/org/apache/iotdb/db/query/dataset/UDTFDataSet.java
@@ -20,6 +20,8 @@
 package org.apache.iotdb.db.query.dataset;
 
 import org.apache.iotdb.commons.path.PartialPath;
+import org.apache.iotdb.commons.udf.service.UDFClassLoaderManager;
+import org.apache.iotdb.commons.udf.service.UDFRegistrationService;
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
 import org.apache.iotdb.db.exception.query.QueryProcessException;
 import org.apache.iotdb.db.mpp.transformation.api.LayerPointReader;
@@ -29,8 +31,6 @@ import org.apache.iotdb.db.qp.physical.crud.UDTFPlan;
 import org.apache.iotdb.db.query.context.QueryContext;
 import org.apache.iotdb.db.query.reader.series.IReaderByTimestamp;
 import org.apache.iotdb.db.query.reader.series.ManagedSeriesReader;
-import org.apache.iotdb.db.query.udf.service.UDFClassLoaderManager;
-import org.apache.iotdb.db.query.udf.service.UDFRegistrationService;
 import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
 import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
 import org.apache.iotdb.tsfile.read.query.timegenerator.TimeGenerator;
diff --git a/server/src/main/java/org/apache/iotdb/db/service/DataNode.java b/server/src/main/java/org/apache/iotdb/db/service/DataNode.java
index d2333c674b..05ad28efcf 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/DataNode.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/DataNode.java
@@ -29,6 +29,8 @@ import org.apache.iotdb.commons.exception.StartupException;
 import org.apache.iotdb.commons.service.JMXService;
 import org.apache.iotdb.commons.service.RegisterManager;
 import org.apache.iotdb.commons.service.StartupChecks;
+import org.apache.iotdb.commons.udf.service.UDFClassLoaderManager;
+import org.apache.iotdb.commons.udf.service.UDFRegistrationService;
 import org.apache.iotdb.confignode.rpc.thrift.TDataNodeRegisterReq;
 import org.apache.iotdb.confignode.rpc.thrift.TDataNodeRegisterResp;
 import org.apache.iotdb.db.client.ConfigNodeClient;
@@ -49,8 +51,6 @@ import org.apache.iotdb.db.mpp.execution.datatransfer.DataBlockService;
 import org.apache.iotdb.db.mpp.execution.schedule.DriverScheduler;
 import org.apache.iotdb.db.protocol.influxdb.meta.InfluxDBMetaManager;
 import org.apache.iotdb.db.protocol.rest.RestService;
-import org.apache.iotdb.db.query.udf.service.UDFClassLoaderManager;
-import org.apache.iotdb.db.query.udf.service.UDFRegistrationService;
 import org.apache.iotdb.db.service.basic.ServiceProvider;
 import org.apache.iotdb.db.service.basic.StandaloneServiceProvider;
 import org.apache.iotdb.db.service.metrics.MetricsService;
@@ -64,6 +64,7 @@ import org.apache.thrift.TException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
@@ -277,8 +278,15 @@ public class DataNode implements DataNodeMBean {
         .setRpcImplClassName(DataNodeTSIServiceImpl.class.getName());
 
     registerManager.register(TemporaryQueryDataFileService.getInstance());
-    registerManager.register(UDFClassLoaderManager.getInstance());
-    registerManager.register(UDFRegistrationService.getInstance());
+    registerManager.register(
+        UDFClassLoaderManager.setupAndGetInstance(
+            IoTDBDescriptor.getInstance().getConfig().getUdfDir()));
+    registerManager.register(
+        UDFRegistrationService.setupAndGetInstance(
+            IoTDBDescriptor.getInstance().getConfig().getSystemDir()
+                + File.separator
+                + "udf"
+                + File.separator));
     registerManager.register(ReceiverService.getInstance());
     registerManager.register(MetricsService.getInstance());
 
diff --git a/server/src/main/java/org/apache/iotdb/db/service/IoTDB.java b/server/src/main/java/org/apache/iotdb/db/service/IoTDB.java
index ced6730c57..5ec6baf6a6 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/IoTDB.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/IoTDB.java
@@ -25,6 +25,8 @@ import org.apache.iotdb.commons.exception.StartupException;
 import org.apache.iotdb.commons.service.JMXService;
 import org.apache.iotdb.commons.service.RegisterManager;
 import org.apache.iotdb.commons.service.StartupChecks;
+import org.apache.iotdb.commons.udf.service.UDFClassLoaderManager;
+import org.apache.iotdb.commons.udf.service.UDFRegistrationService;
 import org.apache.iotdb.db.conf.IoTDBConfig;
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
 import org.apache.iotdb.db.conf.IoTDBStartCheck;
@@ -44,8 +46,6 @@ import org.apache.iotdb.db.mpp.execution.datatransfer.DataBlockService;
 import org.apache.iotdb.db.mpp.execution.schedule.DriverScheduler;
 import org.apache.iotdb.db.protocol.influxdb.meta.InfluxDBMetaManager;
 import org.apache.iotdb.db.protocol.rest.RestService;
-import org.apache.iotdb.db.query.udf.service.UDFClassLoaderManager;
-import org.apache.iotdb.db.query.udf.service.UDFRegistrationService;
 import org.apache.iotdb.db.rescon.PrimitiveArrayManager;
 import org.apache.iotdb.db.rescon.SystemInfo;
 import org.apache.iotdb.db.service.basic.ServiceProvider;
@@ -59,6 +59,7 @@ import org.apache.iotdb.db.wal.WALManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.File;
 import java.io.IOException;
 
 public class IoTDB implements IoTDBMBean {
@@ -169,8 +170,15 @@ public class IoTDB implements IoTDBMBean {
     }
 
     registerManager.register(TemporaryQueryDataFileService.getInstance());
-    registerManager.register(UDFClassLoaderManager.getInstance());
-    registerManager.register(UDFRegistrationService.getInstance());
+    registerManager.register(
+        UDFClassLoaderManager.setupAndGetInstance(
+            IoTDBDescriptor.getInstance().getConfig().getUdfDir()));
+    registerManager.register(
+        UDFRegistrationService.setupAndGetInstance(
+            IoTDBDescriptor.getInstance().getConfig().getSystemDir()
+                + File.separator
+                + "udf"
+                + File.separator));
     registerManager.register(ReceiverService.getInstance());
     registerManager.register(MetricsService.getInstance());
 
diff --git a/server/src/test/java/org/apache/iotdb/db/qp/physical/PhysicalPlanTest.java b/server/src/test/java/org/apache/iotdb/db/qp/physical/PhysicalPlanTest.java
index f23086ba8b..bc25d7b75b 100644
--- a/server/src/test/java/org/apache/iotdb/db/qp/physical/PhysicalPlanTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/qp/physical/PhysicalPlanTest.java
@@ -21,6 +21,7 @@ package org.apache.iotdb.db.qp.physical;
 import org.apache.iotdb.commons.exception.IllegalPathException;
 import org.apache.iotdb.commons.exception.MetadataException;
 import org.apache.iotdb.commons.path.PartialPath;
+import org.apache.iotdb.commons.udf.service.UDFRegistrationService;
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
 import org.apache.iotdb.db.engine.trigger.executor.TriggerEvent;
 import org.apache.iotdb.db.exception.StorageEngineException;
@@ -62,7 +63,6 @@ import org.apache.iotdb.db.qp.physical.sys.StartTriggerPlan;
 import org.apache.iotdb.db.qp.physical.sys.StopPipeServerPlan;
 import org.apache.iotdb.db.qp.physical.sys.StopTriggerPlan;
 import org.apache.iotdb.db.query.executor.fill.PreviousFill;
-import org.apache.iotdb.db.query.udf.service.UDFRegistrationService;
 import org.apache.iotdb.db.service.IoTDB;
 import org.apache.iotdb.db.utils.EnvironmentUtils;
 import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
diff --git a/server/src/test/java/org/apache/iotdb/db/utils/EnvironmentUtils.java b/server/src/test/java/org/apache/iotdb/db/utils/EnvironmentUtils.java
index d012c9c65e..ffcef8d826 100644
--- a/server/src/test/java/org/apache/iotdb/db/utils/EnvironmentUtils.java
+++ b/server/src/test/java/org/apache/iotdb/db/utils/EnvironmentUtils.java
@@ -19,6 +19,8 @@
 package org.apache.iotdb.db.utils;
 
 import org.apache.iotdb.commons.auth.AuthException;
+import org.apache.iotdb.commons.udf.api.exception.UDFRegistrationException;
+import org.apache.iotdb.commons.udf.service.UDFRegistrationService;
 import org.apache.iotdb.db.auth.AuthorizerManager;
 import org.apache.iotdb.db.conf.IoTDBConfig;
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
@@ -34,7 +36,6 @@ import org.apache.iotdb.db.engine.trigger.service.TriggerRegistrationService;
 import org.apache.iotdb.db.exception.ContinuousQueryException;
 import org.apache.iotdb.db.exception.StorageEngineException;
 import org.apache.iotdb.db.exception.TriggerManagementException;
-import org.apache.iotdb.db.exception.UDFRegistrationException;
 import org.apache.iotdb.db.metadata.idtable.IDTableManager;
 import org.apache.iotdb.db.metadata.idtable.entry.DeviceIDFactory;
 import org.apache.iotdb.db.query.context.QueryContext;
@@ -42,7 +43,6 @@ import org.apache.iotdb.db.query.control.FileReaderManager;
 import org.apache.iotdb.db.query.control.QueryResourceManager;
 import org.apache.iotdb.db.query.control.QueryTimeManager;
 import org.apache.iotdb.db.query.executor.LastQueryExecutor;
-import org.apache.iotdb.db.query.udf.service.UDFRegistrationService;
 import org.apache.iotdb.db.rescon.MemTableManager;
 import org.apache.iotdb.db.rescon.PrimitiveArrayManager;
 import org.apache.iotdb.db.rescon.SystemInfo;


[iotdb] 02/04: Merge branch 'master' of github.com:apache/iotdb into iotdb-3250

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit cc6d8b2868ec65e46e77b732d0149190b6fd2b8d
Merge: 5c21e9a200 8f81a4334d
Author: Steve Yurong Su <ro...@apache.org>
AuthorDate: Sat May 21 22:21:14 2022 +0800

    Merge branch 'master' of github.com:apache/iotdb into iotdb-3250



[iotdb] 04/04: simplify PlanExecutor

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 5282f4ee43f258c9e16c514ea0d4fb8693875a5d
Author: Steve Yurong Su <ro...@apache.org>
AuthorDate: Sun May 22 01:32:47 2022 +0800

    simplify PlanExecutor
---
 .../org/apache/iotdb/db/qp/executor/PlanExecutor.java     | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java b/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
index 491b0f6d74..37fc2a6a21 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
@@ -126,7 +126,6 @@ import org.apache.iotdb.db.qp.physical.sys.SettlePlan;
 import org.apache.iotdb.db.qp.physical.sys.ShowChildNodesPlan;
 import org.apache.iotdb.db.qp.physical.sys.ShowChildPathsPlan;
 import org.apache.iotdb.db.qp.physical.sys.ShowDevicesPlan;
-import org.apache.iotdb.db.qp.physical.sys.ShowFunctionsPlan;
 import org.apache.iotdb.db.qp.physical.sys.ShowLockInfoPlan;
 import org.apache.iotdb.db.qp.physical.sys.ShowNodesInTemplatePlan;
 import org.apache.iotdb.db.qp.physical.sys.ShowPathsSetTemplatePlan;
@@ -742,7 +741,7 @@ public class PlanExecutor implements IPlanExecutor {
       case QUERY_PROCESSLIST:
         return processShowQueryProcesslist();
       case FUNCTIONS:
-        return processShowFunctions((ShowFunctionsPlan) showPlan);
+        return processShowFunctions();
       case TRIGGERS:
         return processShowTriggers();
       case CONTINUOUS_QUERY:
@@ -1070,8 +1069,7 @@ public class PlanExecutor implements IPlanExecutor {
     return listDataSet;
   }
 
-  private QueryDataSet processShowFunctions(ShowFunctionsPlan showPlan)
-      throws QueryProcessException {
+  private QueryDataSet processShowFunctions() throws QueryProcessException {
     ListDataSet listDataSet =
         new ListDataSet(
             Arrays.asList(
@@ -1080,8 +1078,8 @@ public class PlanExecutor implements IPlanExecutor {
                 new PartialPath(COLUMN_FUNCTION_CLASS, false)),
             Arrays.asList(TSDataType.TEXT, TSDataType.TEXT, TSDataType.TEXT));
 
-    appendUDFs(listDataSet, showPlan);
-    appendNativeFunctions(listDataSet, showPlan);
+    appendUDFs(listDataSet);
+    appendNativeFunctions(listDataSet);
 
     listDataSet.sort(
         (r1, r2) ->
@@ -1090,8 +1088,7 @@ public class PlanExecutor implements IPlanExecutor {
     return listDataSet;
   }
 
-  private void appendUDFs(ListDataSet listDataSet, ShowFunctionsPlan showPlan)
-      throws QueryProcessException {
+  private void appendUDFs(ListDataSet listDataSet) throws QueryProcessException {
     for (UDFRegistrationInformation info :
         UDFRegistrationService.getInstance().getRegistrationInformation()) {
       RowRecord rowRecord = new RowRecord(0); // ignore timestamp
@@ -1241,7 +1238,7 @@ public class PlanExecutor implements IPlanExecutor {
     return listDataSet;
   }
 
-  private void appendNativeFunctions(ListDataSet listDataSet, ShowFunctionsPlan showPlan) {
+  private void appendNativeFunctions(ListDataSet listDataSet) {
     final Binary functionType = Binary.valueOf(FUNCTION_TYPE_NATIVE);
     final Binary className = Binary.valueOf("");
     for (String functionName : BuiltinAggregationFunction.getNativeFunctionNames()) {