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:46:40 UTC

[iotdb] branch fix_0.11_last_query_bug created (now e54daae)

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

qiaojialin pushed a change to branch fix_0.11_last_query_bug
in repository https://gitbox.apache.org/repos/asf/iotdb.git.


      at e54daae  fix last query non cached bug

This branch includes the following new commits:

     new e54daae  fix last query non cached 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: fix last query non cached bug

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

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

commit e54daae29421e1a402cdad98172768867082bead
Author: qiaojialin <64...@qq.com>
AuthorDate: Mon Feb 8 12:46:14 2021 +0800

    fix last query non cached bug
---
 .../iotdb/db/query/executor/LastQueryExecutor.java | 17 ++++++----
 .../iotdb/db/integration/IoTDBSimpleQueryIT.java   | 36 ++++++++++++++++++++++
 2 files changed, 47 insertions(+), 6 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 fff37ee..e010c5b 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
@@ -126,9 +126,10 @@ public class LastQueryExecutor {
     List<LastCacheAccessor> cacheAccessors = new ArrayList<>();
     Filter filter = (expression == null) ? null : ((GlobalTimeExpression) expression).getFilter();
 
+    List<TSDataType> restDataTypes = new ArrayList<>();
     List<PartialPath> restPaths = new ArrayList<>();
     List<Pair<Boolean, TimeValuePair>> resultContainer =
-            readLastPairsFromCache(seriesPaths, filter, cacheAccessors, restPaths);
+            readLastPairsFromCache(seriesPaths, dataTypes, filter, cacheAccessors, restPaths, restDataTypes);
     // If any '>' or '>=' filters are specified, only access cache to get Last result.
     if (filter != null || restPaths.isEmpty()) {
       return resultContainer;
@@ -139,9 +140,9 @@ public class LastQueryExecutor {
     try {
       for (int i = 0; i < restPaths.size(); i++) {
         QueryDataSource dataSource =
-                QueryResourceManager.getInstance().getQueryDataSource(seriesPaths.get(i), context, null);
-        LastPointReader lastReader = new LastPointReader(seriesPaths.get(i), dataTypes.get(i),
-                lastQueryPlan.getAllMeasurementsInDevice(seriesPaths.get(i).getDevice()),
+                QueryResourceManager.getInstance().getQueryDataSource(restPaths.get(i), context, null);
+        LastPointReader lastReader = new LastPointReader(restPaths.get(i), restDataTypes.get(i),
+                lastQueryPlan.getAllMeasurementsInDevice(restPaths.get(i).getDevice()),
                 context, dataSource, Long.MAX_VALUE, null);
         readerList.add(lastReader);
       }
@@ -164,8 +165,10 @@ public class LastQueryExecutor {
     return resultContainer;
   }
 
-  private static List<Pair<Boolean, TimeValuePair>> readLastPairsFromCache(List<PartialPath> seriesPaths,
-          Filter filter, List<LastCacheAccessor> cacheAccessors, List<PartialPath> restPaths) {
+  private static List<Pair<Boolean, TimeValuePair>> readLastPairsFromCache(
+      List<PartialPath> seriesPaths, List<TSDataType> dataTypes, Filter filter,
+      List<LastCacheAccessor> cacheAccessors,
+      List<PartialPath> restPaths, List<TSDataType> restDataTypes) {
     List<Pair<Boolean, TimeValuePair>> resultContainer = new ArrayList<>();
     if (lastCacheEnabled) {
       for (PartialPath path : seriesPaths) {
@@ -173,6 +176,7 @@ public class LastQueryExecutor {
       }
     } else {
       restPaths.addAll(seriesPaths);
+      restDataTypes.addAll(dataTypes);
     }
     for (int i = 0; i < cacheAccessors.size(); i++) {
       TimeValuePair tvPair = cacheAccessors.get(i).read();
@@ -181,6 +185,7 @@ public class LastQueryExecutor {
       } else {
         resultContainer.add(new Pair<>(false, null));
         restPaths.add(seriesPaths.get(i));
+        restDataTypes.add(dataTypes.get(i));
       }
     }
     return resultContainer;
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 4afa443..cc4b857 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
@@ -283,6 +283,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 testShowTimeseriesDataSet4() throws ClassNotFoundException {
     Class.forName(Config.JDBC_DRIVER_NAME);
     try (Connection connection = DriverManager