This is an automated email from the ASF dual-hosted git repository.
wangchao316 pushed a commit to branch rel/0.12
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/rel/0.12 by this push:
new 2c54eb8 [IOTDB-1733] Fix dropping built-in function (#4026) (#4027)
2c54eb8 is described below
commit 2c54eb822524f311e2be7d474adb5f297f394087
Author: BaiJian <[email protected]>
AuthorDate: Sun Sep 26 09:17:51 2021 +0800
[IOTDB-1733] Fix dropping built-in function (#4026) (#4027)
[IOTDB-1733] Fix dropping built-in function (#4026) (#4027)
---
.../query/udf/service/UDFRegistrationService.java | 5 ++---
.../iotdb/db/integration/IoTDBUDFManagementIT.java | 21 +++++++++++++++++++++
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git
a/server/src/main/java/org/apache/iotdb/db/query/udf/service/UDFRegistrationService.java
b/server/src/main/java/org/apache/iotdb/db/query/udf/service/UDFRegistrationService.java
index 88ceaba..b36b46b 100644
---
a/server/src/main/java/org/apache/iotdb/db/query/udf/service/UDFRegistrationService.java
+++
b/server/src/main/java/org/apache/iotdb/db/query/udf/service/UDFRegistrationService.java
@@ -203,7 +203,7 @@ public class UDFRegistrationService implements IService {
public void deregister(String functionName) throws UDFRegistrationException {
functionName = functionName.toUpperCase();
- UDFRegistrationInformation information =
registrationInformation.remove(functionName);
+ UDFRegistrationInformation information =
registrationInformation.get(functionName);
if (information == null) {
String errorMessage = String.format("UDF %s does not exist.",
functionName);
logger.warn(errorMessage);
@@ -216,12 +216,10 @@ public class UDFRegistrationService implements IService {
logger.error(errorMessage);
throw new UDFRegistrationException(errorMessage);
}
-
if (!information.isTemporary()) {
try {
appendDeregistrationLog(functionName);
} catch (IOException e) {
- registrationInformation.put(functionName, information);
String errorMessage =
String.format(
"Failed to append UDF log when deregistering UDF %s, because
%s", functionName, e);
@@ -229,6 +227,7 @@ public class UDFRegistrationService implements IService {
throw new UDFRegistrationException(errorMessage, e);
}
}
+ registrationInformation.remove(functionName);
}
private void appendRegistrationLog(String functionName, String className)
throws IOException {
diff --git
a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBUDFManagementIT.java
b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBUDFManagementIT.java
index f85e012..c75009a 100644
---
a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBUDFManagementIT.java
+++
b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBUDFManagementIT.java
@@ -353,6 +353,27 @@ public class IoTDBUDFManagementIT {
}
@Test
+ public void testDropBuiltInFunction() throws SQLException { // drop
+ try (Connection connection =
+ DriverManager.getConnection(
+ Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+ Statement statement = connection.createStatement()) {
+ try {
+ statement.execute("drop function abs");
+ fail();
+ } catch (SQLException throwable) {
+ assertTrue(throwable.getMessage().contains("Built-in function"));
+ }
+ statement.execute("INSERT INTO root.vehicle.d1(time, s1) VALUES(1,
-10.0)");
+ ResultSet rs = statement.executeQuery("SELECT ABS(s1) FROM
root.vehicle.d1");
+ Assert.assertTrue(rs.next());
+ Assert.assertEquals(1, rs.getLong(1));
+ Assert.assertEquals(10.0F, rs.getFloat(2), 0.00001);
+ Assert.assertFalse(rs.next());
+ }
+ }
+
+ @Test
public void testCreateBuiltinFunction() throws ClassNotFoundException {
UDFRegistrationService.getInstance()
.registerBuiltinFunction("adder",
"org.apache.iotdb.db.query.udf.example.Adder");