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 06:26:42 UTC
[iotdb] branch rel/0.11 updated: fix last query non cached bug
(#2652)
This is an automated email from the ASF dual-hosted git repository.
qiaojialin pushed a commit to branch rel/0.11
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/rel/0.11 by this push:
new bfed90a fix last query non cached bug (#2652)
bfed90a is described below
commit bfed90aad10d8c3c3c60aa178ad871c036f614e1
Author: Jialin Qiao <qj...@mails.tsinghua.edu.cn>
AuthorDate: Mon Feb 8 00:26:22 2021 -0600
fix last query non cached bug (#2652)
---
.../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