You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by la...@apache.org on 2023/08/18 06:33:30 UTC

[iotdb] branch udf_win created (now 8cf8bb671a5)

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

lancelly pushed a change to branch udf_win
in repository https://gitbox.apache.org/repos/asf/iotdb.git


      at 8cf8bb671a5 Override existing jar instead of deleting it when registering UDF

This branch includes the following new commits:

     new 03e62ed1a0b Fix some ITs of UDFManagement
     new 8cf8bb671a5 Override existing jar instead of deleting it when registering UDF

The 2 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] 02/02: Override existing jar instead of deleting it when registering UDF

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

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

commit 8cf8bb671a554a990bec5e28fd069ae254e61bf1
Author: Liao Lanyu <14...@qq.com>
AuthorDate: Fri Aug 18 09:41:19 2023 +0800

    Override existing jar instead of deleting it when registering UDF
---
 .../apache/iotdb/commons/executable/ExecutableManager.java    | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/node-commons/src/main/java/org/apache/iotdb/commons/executable/ExecutableManager.java b/node-commons/src/main/java/org/apache/iotdb/commons/executable/ExecutableManager.java
index 0f195086230..4a730d2a5fa 100644
--- a/node-commons/src/main/java/org/apache/iotdb/commons/executable/ExecutableManager.java
+++ b/node-commons/src/main/java/org/apache/iotdb/commons/executable/ExecutableManager.java
@@ -223,11 +223,18 @@ public class ExecutableManager {
     }
   }
 
+  /**
+   * Create and save the file if the specified file does not exist, or this method will override the
+   * existing file.
+   */
   protected void saveToDir(ByteBuffer byteBuffer, String destination) throws IOException {
     try {
       Path path = Paths.get(destination);
-      Files.deleteIfExists(path);
-      Files.createFile(path);
+      if (!Files.exists(path)) {
+        Files.createFile(path);
+      }
+      // FileOutPutStream is not in append mode by default, so the file will be overridden if it
+      // already exists.
       try (FileOutputStream outputStream = new FileOutputStream(destination)) {
         outputStream.getChannel().write(byteBuffer);
       }


[iotdb] 01/02: Fix some ITs of UDFManagement

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

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

commit 03e62ed1a0b927ccddeb4707da255a47a1011477
Author: Liao Lanyu <14...@qq.com>
AuthorDate: Fri Aug 18 14:30:56 2023 +0800

    Fix some ITs of UDFManagement
---
 .../iotdb/db/it/udf/IoTDBUDFManagementIT.java      | 50 ++++++++++++++++++++--
 1 file changed, 46 insertions(+), 4 deletions(-)

diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/udf/IoTDBUDFManagementIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/udf/IoTDBUDFManagementIT.java
index 2362af361fb..908a997d420 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/udf/IoTDBUDFManagementIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/udf/IoTDBUDFManagementIT.java
@@ -32,6 +32,7 @@ import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.junit.runner.RunWith;
 
+import java.io.File;
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -54,6 +55,16 @@ public class IoTDBUDFManagementIT {
   private static final String FUNCTION_TYPE_BUILTIN_UDTF = "built-in UDTF";
   private static final String FUNCTION_TYPE_EXTERNAL_UDTF = "external UDTF";
 
+  private static final String UDF_LIB_PREFIX =
+      System.getProperty("user.dir")
+          + File.separator
+          + "target"
+          + File.separator
+          + "test-classes"
+          + File.separator;
+
+  private static final String UDF_JAR_PREFIX = new File(UDF_LIB_PREFIX).toURI().toString();
+
   @Before
   public void setUp() throws Exception {
     EnvFactory.getEnv().initClusterEnvironment();
@@ -208,6 +219,37 @@ public class IoTDBUDFManagementIT {
     }
   }
 
+  @Test
+  public void testCreateFunctionWithURI() throws SQLException {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          String.format(
+              "create function udf as 'org.apache.iotdb.db.query.udf.example.Adder' using URI '%s'",
+              UDF_JAR_PREFIX + "udf-example.jar"));
+
+      statement.execute(
+          String.format(
+              "create function udf1 as 'org.apache.iotdb.db.query.udf.example.Adder' using URI '%s'",
+              UDF_JAR_PREFIX + "udf-example.jar"));
+
+      try (ResultSet resultSet = statement.executeQuery("show functions")) {
+        int count = 0;
+        while (resultSet.next()) {
+          ++count;
+        }
+        Assert.assertEquals(
+            2 + NATIVE_FUNCTIONS_COUNT + BUILTIN_FUNCTIONS_COUNT + BUILTIN_SCALAR_FUNCTIONS_COUNT,
+            count);
+        assertEquals(3, resultSet.getMetaData().getColumnCount());
+        statement.execute("drop function udf");
+        statement.execute("drop function udf1");
+      } catch (Exception e) {
+        fail();
+      }
+    }
+  }
+
   @Test
   public void testCreateFunctionWithInvalidURI() {
     try (Connection connection = EnvFactory.getEnv().getConnection();
@@ -215,8 +257,8 @@ public class IoTDBUDFManagementIT {
       try {
         statement.execute(
             String.format(
-                "create stateless trigger %s before insert on root.test.stateless.* as '%s' using URI '%s' with (\"name\"=\"%s\")",
-                "a", "org.apache.iotdb.test", "", "test"));
+                "create function udf as 'org.apache.iotdb.db.query.udf.example.Adder' using URI '%s'",
+                ""));
         fail();
       } catch (Exception e) {
         assertTrue(e.getMessage().contains("URI"));
@@ -225,8 +267,8 @@ public class IoTDBUDFManagementIT {
       try {
         statement.execute(
             String.format(
-                "create stateless trigger %s before insert on root.test.stateless.* as '%s' using URI '%s' with (\"name\"=\"%s\")",
-                "a", "org.apache.iotdb.test", "file:///data/udf/upload-test.jar", "test"));
+                "create function udf as 'org.apache.iotdb.db.query.udf.example.Adder' using URI '%s'",
+                "file:///data/udf/upload-test.jar"));
         fail();
       } catch (Exception e) {
         assertTrue(e.getMessage().contains("URI"));