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/02/19 01:00:57 UTC

[GitHub] [iotdb] FrankHWD commented on a change in pull request #4834: [IOTDB-2305]Library anomaly

FrankHWD commented on a change in pull request #4834:
URL: https://github.com/apache/iotdb/pull/4834#discussion_r810420524



##########
File path: library-udf/src/test/java/org/apache/iotdb/library/anomaly/AnomalyTests.java
##########
@@ -0,0 +1,512 @@
+/*
+ * 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.anomaly;
+
+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 AnomalyTests {
+  @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);
+  }
+
+  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) values(%d,%d,%d)", 100, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2) values(%d,%d,%d)", 200, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2) values(%d,%d,%d)", 300, -2, -2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2) values(%d,%d,%d)", 400, -1, -1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2) values(%d,%d,%d)", 500, 10, 10));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2) values(%d,%d,%d)", 600, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2) values(%d,%d,%d)", 700, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2) values(%d,%d,%d)", 800, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2) values(%d,%d,%d)", 900, -1, -1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d1(timestamp,s1,s2) values(%d,%d,%d)", 1000, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2) values(%d,%d,%d)", 100, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2) values(%d,%d,%d)", 200, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2) values(%d,%d,%d)", 300, -2, -2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2) values(%d,%d,%d)", 400, -1, -1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2) values(%d,%d,%d)", 500, 10, 10));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2) values(%d,%d,%d)", 600, 1, 1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2) values(%d,%d,%d)", 700, 0, 0));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2) values(%d,%d,%d)", 800, 2, 2));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2) values(%d,%d,%d)", 900, -1, -1));
+      statement.execute(
+          String.format(
+              "insert into root.vehicle.d2(timestamp,s1,s2) values(%d,%d,%d)", 1000, 1, 1));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute("create function iqr as 'org.apache.iotdb.library.anomaly.UDTFIQR'");
+      statement.execute("create function ksigma as 'org.apache.iotdb.library.anomaly.UDTFKSigma'");
+      statement.execute(
+          "create function missdetect as 'org.apache.iotdb.library.anomaly.UDTFMissDetect'");
+      statement.execute("create function lof as 'org.apache.iotdb.library.anomaly.UDTFLOF'");
+      statement.execute("create function range as 'org.apache.iotdb.library.anomaly.UDTFRange'");
+      statement.execute(
+          "create function TwoSidedFilter as 'org.apache.iotdb.library.anomaly.UDTFTwoSidedFilter'");
+    } 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 testIRQR1() {
+    String sqlStr = "select iqr(d1.s1) from 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.




-- 
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