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

[iotdb] branch rel/0.12 updated: skip non exist measurement in where clause (#3590) (#3664)

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

qiaojialin 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 97e75df  skip non exist measurement in where clause (#3590) (#3664)
97e75df is described below

commit 97e75df46a691df154f4a97607e6e13061326037
Author: zyk990424 <38...@users.noreply.github.com>
AuthorDate: Mon Aug 2 20:59:27 2021 +0800

    skip non exist measurement in where clause (#3590) (#3664)
---
 .../iotdb/db/qp/strategy/PhysicalGenerator.java    | 24 ++++++++--
 .../iotdb/db/integration/IoTDBAlignByDeviceIT.java | 54 ++++++++++++++++++++++
 2 files changed, 73 insertions(+), 5 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/qp/strategy/PhysicalGenerator.java b/server/src/main/java/org/apache/iotdb/db/qp/strategy/PhysicalGenerator.java
index eddfa2b..4ddcf85 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/strategy/PhysicalGenerator.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/strategy/PhysicalGenerator.java
@@ -20,6 +20,7 @@ package org.apache.iotdb.db.qp.strategy;
 
 import org.apache.iotdb.db.auth.AuthException;
 import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.exception.metadata.PathNotExistException;
 import org.apache.iotdb.db.exception.query.LogicalOperatorException;
 import org.apache.iotdb.db.exception.query.LogicalOptimizeException;
 import org.apache.iotdb.db.exception.query.QueryProcessException;
@@ -135,6 +136,7 @@ import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
@@ -777,9 +779,16 @@ public class PhysicalGenerator {
       List<PartialPath> devices, FilterOperator operator) throws QueryProcessException {
     Map<String, IExpression> deviceToFilterMap = new HashMap<>();
     Set<PartialPath> filterPaths = new HashSet<>();
-    for (PartialPath device : devices) {
+    Iterator<PartialPath> deviceIterator = devices.iterator();
+    while (deviceIterator.hasNext()) {
+      PartialPath device = deviceIterator.next();
       FilterOperator newOperator = operator.copy();
-      concatFilterPath(device, newOperator, filterPaths);
+      try {
+        concatFilterPath(device, newOperator, filterPaths);
+      } catch (PathNotExistException e) {
+        deviceIterator.remove();
+        continue;
+      }
       // transform to a list so it can be indexed
       List<PartialPath> filterPathList = new ArrayList<>(filterPaths);
       try {
@@ -816,7 +825,8 @@ public class PhysicalGenerator {
   }
 
   private void concatFilterPath(
-      PartialPath prefix, FilterOperator operator, Set<PartialPath> filterPaths) {
+      PartialPath prefix, FilterOperator operator, Set<PartialPath> filterPaths)
+      throws PathNotExistException {
     if (!operator.isLeaf()) {
       for (FilterOperator child : operator.getChildren()) {
         concatFilterPath(prefix, child, filterPaths);
@@ -834,8 +844,12 @@ public class PhysicalGenerator {
     }
 
     PartialPath concatPath = prefix.concatPath(filterPath);
-    filterPaths.add(concatPath);
-    basicOperator.setSinglePath(concatPath);
+    if (IoTDB.metaManager.isPathExist(concatPath)) {
+      filterPaths.add(concatPath);
+      basicOperator.setSinglePath(concatPath);
+    } else {
+      throw new PathNotExistException(concatPath.getFullPath());
+    }
   }
 
   @SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity warning
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAlignByDeviceIT.java b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAlignByDeviceIT.java
index a57d6d3..46dce37 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAlignByDeviceIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAlignByDeviceIT.java
@@ -1274,4 +1274,58 @@ public class IoTDBAlignByDeviceIT {
       fail(e.getMessage());
     }
   }
+
+  @Test
+  public void selectWithNonExistMeasurementInWhereClause() throws ClassNotFoundException {
+    String[] retArray =
+        new String[] {
+          "1,root.vehicle.d0,101,1101,null,null,null,",
+        };
+
+    Class.forName(Config.JDBC_DRIVER_NAME);
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      boolean hasResultSet =
+          statement.execute("select * from root.vehicle.* where s1 == 1101 align by device");
+      Assert.assertTrue(hasResultSet);
+
+      try (ResultSet resultSet = statement.getResultSet()) {
+        ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
+        List<Integer> actualIndexToExpectedIndexList =
+            checkHeader(
+                resultSetMetaData,
+                "Time,Device,s0,s1,s2,s3,s4",
+                new int[] {
+                  Types.TIMESTAMP,
+                  Types.VARCHAR,
+                  Types.INTEGER,
+                  Types.BIGINT,
+                  Types.FLOAT,
+                  Types.VARCHAR,
+                  Types.BOOLEAN
+                });
+
+        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(1, cnt);
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.getMessage());
+    }
+  }
 }