You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by xi...@apache.org on 2022/02/11 08:45:59 UTC

[iotdb] branch alignbydevicebug created (now 0ae3f22)

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

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


      at 0ae3f22  align by device bug

This branch includes the following new commits:

     new 0ae3f22  align by device bug

The 1 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] 01/01: align by device bug

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

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

commit 0ae3f224079ed39664bfdc45fe445087fcb5be4b
Author: Alima777 <wx...@gmail.com>
AuthorDate: Fri Feb 11 16:45:04 2022 +0800

    align by device bug
---
 .../iotdb/db/integration/IoTDBAlignByDeviceIT.java | 96 ++++++++++++++++++++++
 .../iotdb/db/qp/logical/crud/QueryOperator.java    |  1 -
 .../db/qp/physical/crud/RawDataQueryPlan.java      | 15 ++++
 3 files changed, 111 insertions(+), 1 deletion(-)

diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBAlignByDeviceIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBAlignByDeviceIT.java
index 4e6c6b3..18ebf76 100644
--- a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBAlignByDeviceIT.java
+++ b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBAlignByDeviceIT.java
@@ -467,6 +467,102 @@ public class IoTDBAlignByDeviceIT {
   }
 
   @Test
+  public void selectDifferentSeriesWithValueFilterWithoutCacheTest() {
+    String[] retArray =
+        new String[] {
+          "100,root.vehicle.d0,99,",
+          "101,root.vehicle.d0,99,",
+          "102,root.vehicle.d0,80,",
+          "103,root.vehicle.d0,99,",
+          "104,root.vehicle.d0,90,",
+          "105,root.vehicle.d0,99,",
+        };
+
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute("CLEAR CACHE");
+      // single device
+      boolean hasResultSet =
+          statement.execute("select s0 from root.vehicle.d0 where s1 < 200 align by device");
+      Assert.assertTrue(hasResultSet);
+
+      try (ResultSet resultSet = statement.getResultSet()) {
+        ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
+        List<Integer> actualIndexToExpectedIndexList =
+            checkHeader(
+                resultSetMetaData,
+                "Time,Device,s0",
+                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(e.getMessage());
+    }
+  }
+
+  @Test
+  public void selectDifferentSeriesWithBinaryValueFilterWithoutCacheTest() {
+    String[] retArray =
+        new String[] {
+          "105,root.vehicle.d0,99,",
+        };
+
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute("CLEAR CACHE");
+      // single device
+      boolean hasResultSet =
+          statement.execute(
+              "select s0 from root.vehicle.d0 where s1 < 200 and s2 > 10 align by device");
+      Assert.assertTrue(hasResultSet);
+
+      try (ResultSet resultSet = statement.getResultSet()) {
+        ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
+        List<Integer> actualIndexToExpectedIndexList =
+            checkHeader(
+                resultSetMetaData,
+                "Time,Device,s0",
+                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(e.getMessage());
+    }
+  }
+
+  @Test
   public void aggregateTest() {
     String[] retArray =
         new String[] {"root.vehicle.d1,2,null,null,null,null,", "root.vehicle.d0,11,11,6,6,1,"};
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/QueryOperator.java b/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/QueryOperator.java
index 54290f1..d93c976 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/QueryOperator.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/QueryOperator.java
@@ -228,7 +228,6 @@ public class QueryOperator extends Operator {
     List<PartialPath> filterPaths = new ArrayList<>(filterOperator.getPathSet());
     HashMap<PartialPath, TSDataType> pathTSDataTypeHashMap = new HashMap<>();
     for (PartialPath filterPath : filterPaths) {
-      rawDataQueryPlan.addFilterPathInDeviceToMeasurements(filterPath);
       pathTSDataTypeHashMap.put(
           filterPath,
           SQLConstant.isReservedPath(filterPath) ? TSDataType.INT64 : filterPath.getSeriesType());
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/RawDataQueryPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/RawDataQueryPlan.java
index 2d1aa1d..5810551 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/RawDataQueryPlan.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/RawDataQueryPlan.java
@@ -26,7 +26,9 @@ import org.apache.iotdb.db.qp.strategy.PhysicalGenerator;
 import org.apache.iotdb.db.utils.SchemaUtils;
 import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
 import org.apache.iotdb.tsfile.read.common.Path;
+import org.apache.iotdb.tsfile.read.expression.IBinaryExpression;
 import org.apache.iotdb.tsfile.read.expression.IExpression;
+import org.apache.iotdb.tsfile.read.expression.impl.SingleSeriesExpression;
 import org.apache.iotdb.tsfile.utils.Pair;
 
 import java.util.ArrayList;
@@ -96,6 +98,19 @@ public class RawDataQueryPlan extends QueryPlan {
 
   public void setExpression(IExpression expression) throws QueryProcessException {
     this.expression = expression;
+    updateDeviceMeasurementsUsingExpression(expression);
+  }
+
+  public void updateDeviceMeasurementsUsingExpression(IExpression expression) {
+    if (expression instanceof SingleSeriesExpression) {
+      Path path = ((SingleSeriesExpression) expression).getSeriesPath();
+      deviceToMeasurements
+          .computeIfAbsent(path.getDevice(), key -> new HashSet<>())
+          .add(path.getMeasurement());
+    } else if (expression instanceof IBinaryExpression) {
+      updateDeviceMeasurementsUsingExpression(((IBinaryExpression) expression).getLeft());
+      updateDeviceMeasurementsUsingExpression(((IBinaryExpression) expression).getRight());
+    }
   }
 
   public List<PartialPath> getDeduplicatedPaths() {