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 11d234ba38 [IoTDB-3566] Add IT for UDTF Hybrid Query (#6354)
11d234ba38 is described below

commit 11d234ba3875b78d6318f466be13cf56dd920b82
Author: Liao Lanyu <[email protected]>
AuthorDate: Tue Jun 21 10:30:52 2022 +0800

    [IoTDB-3566] Add IT for UDTF Hybrid Query (#6354)
---
 .../constant}/BuiltinAggregationFunctionEnum.java  |   2 +-
 .../BuiltinTimeSeriesGeneratingFunctionEnum.java   |   2 +-
 .../iotdb/itbase/constant/UDFTestConstant.java     |  31 ++++
 .../iotdb/db/it/udf/IoTDBUDFManagementIT.java      |   2 +
 .../iotdb/db/it/udf/IoTDBUDTFHybridQueryIT.java    | 167 +++++++++++++++++++++
 5 files changed, 202 insertions(+), 2 deletions(-)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/db/it/udf/BuiltinAggregationFunctionEnum.java
 
b/integration-test/src/main/java/org/apache/iotdb/itbase/constant/BuiltinAggregationFunctionEnum.java
similarity index 97%
rename from 
integration-test/src/test/java/org/apache/iotdb/db/it/udf/BuiltinAggregationFunctionEnum.java
rename to 
integration-test/src/main/java/org/apache/iotdb/itbase/constant/BuiltinAggregationFunctionEnum.java
index 20fa5dc9eb..1b6702c150 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/db/it/udf/BuiltinAggregationFunctionEnum.java
+++ 
b/integration-test/src/main/java/org/apache/iotdb/itbase/constant/BuiltinAggregationFunctionEnum.java
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.iotdb.db.it.udf;
+package org.apache.iotdb.itbase.constant;
 
 import java.util.Arrays;
 import java.util.HashSet;
diff --git 
a/integration-test/src/test/java/org/apache/iotdb/db/it/udf/BuiltinTimeSeriesGeneratingFunctionEnum.java
 
b/integration-test/src/main/java/org/apache/iotdb/itbase/constant/BuiltinTimeSeriesGeneratingFunctionEnum.java
similarity index 98%
rename from 
integration-test/src/test/java/org/apache/iotdb/db/it/udf/BuiltinTimeSeriesGeneratingFunctionEnum.java
rename to 
integration-test/src/main/java/org/apache/iotdb/itbase/constant/BuiltinTimeSeriesGeneratingFunctionEnum.java
index 3e34873c8b..dd78d79f7c 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/db/it/udf/BuiltinTimeSeriesGeneratingFunctionEnum.java
+++ 
b/integration-test/src/main/java/org/apache/iotdb/itbase/constant/BuiltinTimeSeriesGeneratingFunctionEnum.java
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.iotdb.db.it.udf;
+package org.apache.iotdb.itbase.constant;
 
 /** All built-in UDFs need to register their function names and classes here. 
*/
 public enum BuiltinTimeSeriesGeneratingFunctionEnum {
diff --git 
a/integration-test/src/main/java/org/apache/iotdb/itbase/constant/UDFTestConstant.java
 
b/integration-test/src/main/java/org/apache/iotdb/itbase/constant/UDFTestConstant.java
new file mode 100644
index 0000000000..6613eed077
--- /dev/null
+++ 
b/integration-test/src/main/java/org/apache/iotdb/itbase/constant/UDFTestConstant.java
@@ -0,0 +1,31 @@
+/*
+ * 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.itbase.constant;
+
+public class UDFTestConstant {
+  public static final String ACCESS_STRATEGY_KEY = "access";
+  public static final String ACCESS_STRATEGY_ROW_BY_ROW = "row-by-row";
+  public static final String ACCESS_STRATEGY_SLIDING_SIZE = "size";
+  public static final String ACCESS_STRATEGY_SLIDING_TIME = "time";
+  public static final String WINDOW_SIZE_KEY = "windowSize";
+  public static final String TIME_INTERVAL_KEY = "timeInterval";
+  public static final String SLIDING_STEP_KEY = "slidingStep";
+  public static final String DISPLAY_WINDOW_BEGIN_KEY = "displayWindowBegin";
+  public static final String DISPLAY_WINDOW_END_KEY = "displayWindowEnd";
+}
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 e540b24f9c..729d74cc3f 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
@@ -22,6 +22,8 @@ import org.apache.iotdb.it.env.EnvFactory;
 import org.apache.iotdb.it.env.IoTDBTestRunner;
 import org.apache.iotdb.itbase.category.ClusterIT;
 import org.apache.iotdb.itbase.category.LocalStandaloneIT;
+import org.apache.iotdb.itbase.constant.BuiltinAggregationFunctionEnum;
+import 
org.apache.iotdb.itbase.constant.BuiltinTimeSeriesGeneratingFunctionEnum;
 
 import org.junit.After;
 import org.junit.Assert;
diff --git 
a/integration-test/src/test/java/org/apache/iotdb/db/it/udf/IoTDBUDTFHybridQueryIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/db/it/udf/IoTDBUDTFHybridQueryIT.java
new file mode 100644
index 0000000000..525b641926
--- /dev/null
+++ 
b/integration-test/src/test/java/org/apache/iotdb/db/it/udf/IoTDBUDTFHybridQueryIT.java
@@ -0,0 +1,167 @@
+/*
+ * 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.db.it.udf;
+
+import org.apache.iotdb.it.env.EnvFactory;
+import org.apache.iotdb.it.env.IoTDBTestRunner;
+import org.apache.iotdb.itbase.category.ClusterIT;
+import org.apache.iotdb.itbase.category.LocalStandaloneIT;
+import org.apache.iotdb.itbase.constant.UDFTestConstant;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+@RunWith(IoTDBTestRunner.class)
+@Category({LocalStandaloneIT.class, ClusterIT.class})
+public class IoTDBUDTFHybridQueryIT {
+
+  @BeforeClass
+  public static void setUp() throws Exception {
+    EnvFactory.getEnv().initBeforeClass();
+    createTimeSeries();
+    generateData();
+    registerUDF();
+  }
+
+  private static void createTimeSeries() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute("SET STORAGE GROUP TO root.vehicle");
+      statement.execute("CREATE TIMESERIES root.vehicle.d1.s1 with 
datatype=INT32,encoding=PLAIN");
+      statement.execute("CREATE TIMESERIES root.vehicle.d1.s2 with 
datatype=INT32,encoding=PLAIN");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void generateData() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      for (int i = 0; i < 10; ++i) {
+        statement.execute(
+            (String.format(
+                "insert into root.vehicle.d1(timestamp,s1,s2) 
values(%d,%d,%d)", i, i, i)));
+      }
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  private static void registerUDF() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "create function counter as 
'org.apache.iotdb.db.query.udf.example.Counter'");
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
+  }
+
+  @Ignore
+  @Test
+  public void testUserDefinedBuiltInHybridAggregationQuery() {
+    String sql =
+        String.format(
+            "select count(*), counter(s1, '%s'='%s') from root.vehicle.d1",
+            UDFTestConstant.ACCESS_STRATEGY_KEY, 
UDFTestConstant.ACCESS_STRATEGY_ROW_BY_ROW);
+
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.executeQuery(sql);
+      fail();
+    } catch (SQLException throwable) {
+      assertTrue(
+          throwable
+              .getMessage()
+              .contains("User-defined and built-in hybrid aggregation is not 
supported together."));
+    }
+  }
+
+  @Ignore
+  @Test
+  public void testUserDefinedFunctionFillFunctionHybridQuery() {
+    String sql =
+        String.format(
+            "select temperature, counter(temperature, '%s'='%s') from 
root.sgcc.wf03.wt01 where time = 2017-11-01T16:37:50.000 fill(float [linear, 
1m, 1m])",
+            UDFTestConstant.ACCESS_STRATEGY_KEY, 
UDFTestConstant.ACCESS_STRATEGY_ROW_BY_ROW);
+
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.executeQuery(sql);
+      fail();
+    } catch (SQLException throwable) {
+      assertTrue(
+          throwable.getMessage().contains("Fill functions are not supported in 
UDF queries."));
+    }
+  }
+
+  @Ignore
+  @Test
+  public void testLastUserDefinedFunctionQuery() {
+    String sql =
+        String.format(
+            "select last counter(temperature, '%s'='%s') from 
root.sgcc.wf03.wt01",
+            UDFTestConstant.ACCESS_STRATEGY_KEY, 
UDFTestConstant.ACCESS_STRATEGY_ROW_BY_ROW);
+
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.executeQuery(sql);
+      fail();
+    } catch (SQLException throwable) {
+      assertTrue(
+          throwable.getMessage().contains("Last queries can only be applied on 
raw time series."));
+    }
+  }
+
+  @Ignore
+  @Test
+  public void testUserDefinedFunctionAlignByDeviceQuery() {
+    String sql =
+        String.format(
+            "select adder(temperature), counter(temperature, '%s'='%s') from 
root.sgcc.wf03.wt01 align by device",
+            UDFTestConstant.ACCESS_STRATEGY_KEY, 
UDFTestConstant.ACCESS_STRATEGY_ROW_BY_ROW);
+
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.executeQuery(sql);
+      fail();
+    } catch (SQLException throwable) {
+      assertTrue(
+          throwable
+              .getMessage()
+              .contains("ALIGN BY DEVICE clause is not supported in UDF 
queries."));
+    }
+  }
+}

Reply via email to