You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2022/11/16 09:44:00 UTC

[iotdb] branch master updated: [IOTDB-4943][IOTDB-4956] Check type of Class and add detailed message for StateWindowStrategy

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

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


The following commit(s) were added to refs/heads/master by this push:
     new f87401b793 [IOTDB-4943][IOTDB-4956] Check type of Class and add detailed message for StateWindowStrategy
f87401b793 is described below

commit f87401b793dd8414a997886ce47d7052094a91d0
Author: Liao Lanyu <14...@qq.com>
AuthorDate: Wed Nov 16 17:43:53 2022 +0800

    [IOTDB-4943][IOTDB-4956] Check type of Class and add detailed message for StateWindowStrategy
---
 docs/UserGuide/Process-Data/UDF-User-Defined-Function.md     |  2 ++
 docs/zh/UserGuide/Process-Data/UDF-User-Defined-Function.md  |  2 +-
 .../iotdb/commons/udf/service/UDFManagementService.java      |  3 ++-
 .../execution/config/executor/ClusterConfigTaskExecutor.java | 12 +++++++++---
 .../dag/intermediate/ConstantIntermediateLayer.java          |  3 ++-
 .../dag/intermediate/MultiInputColumnIntermediateLayer.java  |  3 ++-
 6 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/docs/UserGuide/Process-Data/UDF-User-Defined-Function.md b/docs/UserGuide/Process-Data/UDF-User-Defined-Function.md
index 82a3cab44b..23335a490b 100644
--- a/docs/UserGuide/Process-Data/UDF-User-Defined-Function.md
+++ b/docs/UserGuide/Process-Data/UDF-User-Defined-Function.md
@@ -218,6 +218,8 @@ The `StateWindowAccessStrategy` is shown schematically below.
 - Constructor 3: For numerical data, there are 1 parameters: you can only provide the threshold delta that is allowed to change within a single window. The start time of the time axis display time window will be defined as the smallest timestamp in the entire query result set, and the time axis display time window end time will be defined as The largest timestamp in the entire query result set.
 - Constructor 4: For text data and boolean data, you can provide no parameter. The start and end timestamps are explained in Constructor 3.
 
+StateWindowAccessStrategy can only take one column as input for now.
+
 Please see the Javadoc for more details. 
 
 
diff --git a/docs/zh/UserGuide/Process-Data/UDF-User-Defined-Function.md b/docs/zh/UserGuide/Process-Data/UDF-User-Defined-Function.md
index af305c9015..bb2e69a8d4 100644
--- a/docs/zh/UserGuide/Process-Data/UDF-User-Defined-Function.md
+++ b/docs/zh/UserGuide/Process-Data/UDF-User-Defined-Function.md
@@ -196,7 +196,7 @@ void beforeStart(UDFParameters parameters, UDTFConfigurations configurations) th
 3. 针对数值型数据,可以只提供单个窗口内部允许变化的阈值delta,时间轴显示时间窗开始时间会被定义为整个查询结果集中最小的时间戳,时间轴显示时间窗结束时间会被定义为整个查询结果集中最大的时间戳。
 4. 针对文本数据以及布尔数据,可以不提供任何参数,开始与结束时间戳见3中解释。
 
-策略的构造方法详见 Javadoc。
+StateWindowAccessStrategy 目前只能接收一列输入。策略的构造方法详见 Javadoc。
 
  * setOutputDataType
 
diff --git a/node-commons/src/main/java/org/apache/iotdb/commons/udf/service/UDFManagementService.java b/node-commons/src/main/java/org/apache/iotdb/commons/udf/service/UDFManagementService.java
index f98be3ecf1..07b82d8c32 100644
--- a/node-commons/src/main/java/org/apache/iotdb/commons/udf/service/UDFManagementService.java
+++ b/node-commons/src/main/java/org/apache/iotdb/commons/udf/service/UDFManagementService.java
@@ -202,7 +202,8 @@ public class UDFManagementService {
       updateAllRegisteredClasses(currentActiveClassLoader);
 
       Class<?> functionClass = Class.forName(className, true, currentActiveClassLoader);
-      functionClass.getDeclaredConstructor().newInstance();
+      // ensure that it is a UDF class
+      UDTF udtf = (UDTF) functionClass.getDeclaredConstructor().newInstance();
       udfTable.addUDFInformation(functionName, udfInformation);
       udfTable.addFunctionAndClass(functionName, functionClass);
     } catch (IOException
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/executor/ClusterConfigTaskExecutor.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/executor/ClusterConfigTaskExecutor.java
index 0b8655a9ca..f597340b75 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/executor/ClusterConfigTaskExecutor.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/executor/ClusterConfigTaskExecutor.java
@@ -138,6 +138,7 @@ import org.apache.iotdb.rpc.StatementExecutionException;
 import org.apache.iotdb.rpc.TSStatusCode;
 import org.apache.iotdb.trigger.api.Trigger;
 import org.apache.iotdb.trigger.api.enums.FailureStrategy;
+import org.apache.iotdb.udf.api.UDTF;
 
 import com.google.common.util.concurrent.SettableFuture;
 import org.apache.commons.codec.digest.DigestUtils;
@@ -356,9 +357,14 @@ public class ClusterConfigTaskExecutor implements IConfigTaskExecutor {
 
       // try to create instance, this request will fail if creation is not successful
       try (UDFClassLoader classLoader = new UDFClassLoader(libRoot)) {
-        // Ensure that jar file contains the class
-        Class.forName(createFunctionStatement.getClassName(), true, classLoader);
-      } catch (ClassNotFoundException e) {
+        // ensure that jar file contains the class and the class is a UDF
+        Class<?> clazz = Class.forName(createFunctionStatement.getClassName(), true, classLoader);
+        UDTF udtf = (UDTF) clazz.getDeclaredConstructor().newInstance();
+      } catch (ClassNotFoundException
+          | NoSuchMethodException
+          | InstantiationException
+          | IllegalAccessException
+          | InvocationTargetException e) {
         LOGGER.warn(
             "Failed to create function when try to create UDF({}) instance first, the cause is: {}",
             createFunctionStatement.getUdfName(),
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/intermediate/ConstantIntermediateLayer.java b/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/intermediate/ConstantIntermediateLayer.java
index dc9865a5ed..f8489e9139 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/intermediate/ConstantIntermediateLayer.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/intermediate/ConstantIntermediateLayer.java
@@ -77,6 +77,7 @@ public class ConstantIntermediateLayer extends IntermediateLayer {
   protected LayerRowWindowReader constructRowStateWindowReader(
       StateWindowAccessStrategy strategy, float memoryBudgetInMB) {
     // Not allowed since the timestamp of a constant row is not defined.
-    throw new UnsupportedOperationException();
+    throw new UnsupportedOperationException(
+        "StateWindowAccessStrategy does not support pure constant input.");
   }
 }
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/intermediate/MultiInputColumnIntermediateLayer.java b/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/intermediate/MultiInputColumnIntermediateLayer.java
index 588ba5ae3a..41c72c1c4f 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/intermediate/MultiInputColumnIntermediateLayer.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/intermediate/MultiInputColumnIntermediateLayer.java
@@ -777,6 +777,7 @@ public class MultiInputColumnIntermediateLayer extends IntermediateLayer
   @Override
   protected LayerRowWindowReader constructRowStateWindowReader(
       StateWindowAccessStrategy strategy, float memoryBudgetInMB) {
-    throw new UnsupportedOperationException();
+    throw new UnsupportedOperationException(
+        "StateWindowAccessStrategy only support one input series for now.");
   }
 }