You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ca...@apache.org on 2023/07/05 10:12:55 UTC

[iotdb] branch lmh/ABDwithView updated: add more test case for align by device

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

caogaofei pushed a commit to branch lmh/ABDwithView
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/lmh/ABDwithView by this push:
     new 2da7451faf4 add more test case for align by device
2da7451faf4 is described below

commit 2da7451faf4e74cd0d688b9f1a518bccaf3175b3
Author: Beyyes <cg...@foxmail.com>
AuthorDate: Wed Jul 5 18:12:41 2023 +0800

    add more test case for align by device
---
 .../db/it/alignbydevice/IoTDBAlignByDeviceIT.java  | 61 ++++++++++++++++++++++
 .../view/IoTDBAlignByDeviceWithViewIT.java         |  1 +
 .../queryengine/plan/analyze/AnalyzeVisitor.java   |  5 ++
 3 files changed, 67 insertions(+)

diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/alignbydevice/IoTDBAlignByDeviceIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/alignbydevice/IoTDBAlignByDeviceIT.java
index 90ad82e5a23..cc5fdeb5b27 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/alignbydevice/IoTDBAlignByDeviceIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/alignbydevice/IoTDBAlignByDeviceIT.java
@@ -1123,4 +1123,65 @@ public class IoTDBAlignByDeviceIT {
       fail(e.getMessage());
     }
   }
+
+  /**
+   * data structure D, time, s1, s2; d1: 1, 10, 20; d2: 1, 12, 22; d3: 1, null, 33
+   *
+   * <p>Query Sql: select s1 from root.good.** where s2 > 1 align by device
+   */
+  @Test
+  public void removeDeviceWhereMeasurementWhenNoDeviceSelectTest() {
+    String[] mockDataSql =
+        new String[] {
+          "create timeseries root.good.d1.s1 WITH DATATYPE=INT32;",
+          "create timeseries root.good.d1.s2 WITH DATATYPE=INT32;",
+          "create timeseries root.good.d2.s1 WITH DATATYPE=INT32;",
+          "create timeseries root.good.d2.s2 WITH DATATYPE=INT32;",
+          "create timeseries root.good.d3.s2 WITH DATATYPE=INT32;",
+          "insert into root.good.d1(time, s1, s2) values(1, 10, 20);",
+          "insert into root.good.d2(time, s1, s2) values(1, 12, 22);",
+          "insert into root.good.d3(time, s2) values(1, 33);"
+        };
+
+    String[] retArray = new String[] {"1,root.good.d1,10", "1,root.good.d2,12"};
+
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+
+      for (String sql : mockDataSql) {
+        statement.execute(sql);
+      }
+
+      try (ResultSet resultSet =
+          statement.executeQuery("select s1 from root.good.** where s2 > 1 align by device")) {
+        ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
+        List<Integer> actualIndexToExpectedIndexList =
+            checkHeader(
+                resultSetMetaData,
+                "Time,Device,s1",
+                new int[] {Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER});
+
+        int cnt = 0;
+        while (resultSet.next()) {
+          String[] expectedStrings = retArray[cnt].split(",");
+          StringBuilder expectedBuilder = new StringBuilder();
+          StringBuilder actualBuilder = new StringBuilder();
+          for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
+            actualBuilder.append(resultSet.getString(i)).append(",");
+            expectedBuilder
+                .append(expectedStrings[actualIndexToExpectedIndexList.get(i - 1)])
+                .append(",");
+          }
+          Assert.assertEquals(expectedBuilder.toString(), actualBuilder.toString());
+          cnt++;
+        }
+        Assert.assertEquals(retArray.length, cnt);
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(
+          "Meets exception in removeDeviceWhereMeasurementWhenNoDeviceSelectTest: "
+              + e.getMessage());
+    }
+  }
 }
diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/alignbydevice/view/IoTDBAlignByDeviceWithViewIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/alignbydevice/view/IoTDBAlignByDeviceWithViewIT.java
index eed35399cd0..c1e586d8a1a 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/alignbydevice/view/IoTDBAlignByDeviceWithViewIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/alignbydevice/view/IoTDBAlignByDeviceWithViewIT.java
@@ -64,6 +64,7 @@ public class IoTDBAlignByDeviceWithViewIT {
       }
     } catch (Exception e) {
       e.printStackTrace();
+      fail("Execute view sql meets error: " + e.getMessage());
     }
   }
 
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
index 14751cea1ae..acd65fa0266 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
@@ -640,6 +640,11 @@ public class AnalyzeVisitor extends StatementVisitor<Analysis, MPPQueryContext>
     // remove devices without measurements to compute
     deviceSet.removeAll(noMeasurementDevices);
 
+    // when the select expression of any device is empty,
+    // the where expression map also need remove this device
+    noMeasurementDevices.forEach(
+        devicePath -> analysis.getDeviceToWhereExpression().remove(devicePath.getFullPath()));
+
     analysis.setDeviceToSelectExpressions(deviceToSelectExpressions);
 
     // set selectExpressions