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/02/08 04:36:38 UTC

[iotdb] 01/01: fix last query non cached path bug

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

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

commit b1e97c696878833acb91acf72a1c76305d79459b
Author: qiaojialin <64...@qq.com>
AuthorDate: Mon Feb 8 12:35:50 2021 +0800

    fix last query non cached path bug
---
 .../iotdb/db/query/executor/LastQueryExecutor.java | 22 +++++++------
 .../iotdb/db/integration/IoTDBSimpleQueryIT.java   | 36 ++++++++++++++++++++++
 2 files changed, 49 insertions(+), 9 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/query/executor/LastQueryExecutor.java b/server/src/main/java/org/apache/iotdb/db/query/executor/LastQueryExecutor.java
index 94768f3..516447f 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/executor/LastQueryExecutor.java
+++ b/server/src/main/java/org/apache/iotdb/db/query/executor/LastQueryExecutor.java
@@ -136,22 +136,23 @@ public class LastQueryExecutor {
     List<LastCacheAccessor> cacheAccessors = new ArrayList<>();
     Filter filter = (expression == null) ? null : ((GlobalTimeExpression) expression).getFilter();
 
-    List<PartialPath> restPaths = new ArrayList<>();
+    List<PartialPath> nonCachedPaths = new ArrayList<>();
+    List<TSDataType> nonCachedDataTypes = new ArrayList<>();
     List<Pair<Boolean, TimeValuePair>> resultContainer =
-        readLastPairsFromCache(seriesPaths, filter, cacheAccessors, restPaths);
-    if (restPaths.isEmpty()) {
+        readLastPairsFromCache(seriesPaths, dataTypes, filter, cacheAccessors, nonCachedPaths, nonCachedDataTypes);
+    if (nonCachedPaths.isEmpty()) {
       return resultContainer;
     }
 
     // Acquire query resources for the rest series paths
     List<LastPointReader> readerList = new ArrayList<>();
-    List<StorageGroupProcessor> list = StorageEngine.getInstance().mergeLock(restPaths);
+    List<StorageGroupProcessor> list = StorageEngine.getInstance().mergeLock(nonCachedPaths);
     try {
-      for (int i = 0; i < restPaths.size(); i++) {
+      for (int i = 0; i < nonCachedPaths.size(); i++) {
         QueryDataSource dataSource =
-            QueryResourceManager.getInstance().getQueryDataSource(seriesPaths.get(i), context, null);
-        LastPointReader lastReader = new LastPointReader(seriesPaths.get(i), dataTypes.get(i),
-            deviceMeasurementsMap.get(seriesPaths.get(i).getDevice()),
+            QueryResourceManager.getInstance().getQueryDataSource(nonCachedPaths.get(i), context, null);
+        LastPointReader lastReader = new LastPointReader(nonCachedPaths.get(i), nonCachedDataTypes.get(i),
+            deviceMeasurementsMap.get(nonCachedPaths.get(i).getDevice()),
             context, dataSource, Long.MAX_VALUE, null);
         readerList.add(lastReader);
       }
@@ -176,7 +177,8 @@ public class LastQueryExecutor {
   }
 
   private static List<Pair<Boolean, TimeValuePair>> readLastPairsFromCache(List<PartialPath> seriesPaths,
-      Filter filter, List<LastCacheAccessor> cacheAccessors, List<PartialPath> restPaths) {
+      List<TSDataType> dataTypes, Filter filter, List<LastCacheAccessor> cacheAccessors,
+      List<PartialPath> restPaths, List<TSDataType> restDataType) {
     List<Pair<Boolean, TimeValuePair>> resultContainer = new ArrayList<>();
     if (CACHE_ENABLED) {
       for (PartialPath path : seriesPaths) {
@@ -184,6 +186,7 @@ public class LastQueryExecutor {
       }
     } else {
       restPaths.addAll(seriesPaths);
+      restDataType.addAll(dataTypes);
       for (int i = 0; i < seriesPaths.size(); i++) {
         resultContainer.add(new Pair<>(false, null));
       }
@@ -193,6 +196,7 @@ public class LastQueryExecutor {
       if (tvPair == null) {
         resultContainer.add(new Pair<>(false, null));
         restPaths.add(seriesPaths.get(i));
+        restDataType.add(dataTypes.get(i));
       } else if (!satisfyFilter(filter, tvPair)) {
         resultContainer.add(new Pair<>(true, null));
       } else {
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBSimpleQueryIT.java b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBSimpleQueryIT.java
index cc478f9..b49e23d 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBSimpleQueryIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBSimpleQueryIT.java
@@ -153,6 +153,42 @@ public class IoTDBSimpleQueryIT {
   }
 
   @Test
+  public void testLastQueryNonCached() throws ClassNotFoundException {
+    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()) {
+      statement.execute("create timeseries root.turbine.d1.s1 with datatype=FLOAT, encoding=GORILLA, compression=SNAPPY");
+      statement.execute("create timeseries root.turbine.d1.s2 with datatype=FLOAT, encoding=GORILLA, compression=SNAPPY");
+      statement.execute("create timeseries root.turbine.d2.s1 with datatype=FLOAT, encoding=GORILLA, compression=SNAPPY");
+      statement.execute("insert into root.turbine.d1(timestamp,s1,s2) values(1,1,2)");
+
+      String[] results = {"root.turbine.d1.s1", "root.turbine.d1.s2"};
+
+      int count = 0;
+      try (ResultSet resultSet = statement.executeQuery("select last * from root")) {
+        while (resultSet.next()) {
+          String path = resultSet.getString("timeseries");
+          assertEquals(results[count], path);
+          count++;
+        }
+      }
+
+      assertEquals(2, count);
+
+      try (ResultSet resultSet = statement.executeQuery("select last * from root")) {
+        while (resultSet.next()) {
+          count++;
+        }
+      }
+
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+  }
+
+  @Test
   public void testSDTEncodingSeq() throws ClassNotFoundException {
     Class.forName(Config.JDBC_DRIVER_NAME);