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 2020/12/17 12:12:08 UTC

[iotdb] branch master updated: Fix Last query output when last value does not exist in a series (#2275)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new b85ddfc  Fix Last query output when last value does not exist in a series (#2275)
b85ddfc is described below

commit b85ddfc235de049869732c28cf86cc1ecf47aadc
Author: wshao08 <59...@users.noreply.github.com>
AuthorDate: Thu Dec 17 20:11:48 2020 +0800

    Fix Last query output when last value does not exist in a series (#2275)
---
 .../iotdb/db/query/executor/LastQueryExecutor.java     | 18 ++++++++----------
 .../org/apache/iotdb/db/integration/IoTDBLastIT.java   | 13 ++++++++++---
 2 files changed, 18 insertions(+), 13 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 b67fbf4..94768f3 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
@@ -92,7 +92,7 @@ public class LastQueryExecutor {
             selectedSeries, dataTypes, context, expression, lastQueryPlan);
 
     for (int i = 0; i < lastPairList.size(); i++) {
-      if (lastPairList.get(i).right != null) {
+      if (lastPairList.get(i).right != null && lastPairList.get(i).right.getValue() != null) {
         TimeValuePair lastTimeValuePair = lastPairList.get(i).right;
         RowRecord resultRecord = new RowRecord(lastTimeValuePair.getTimestamp());
         Field pathField = new Field(TSDataType.TEXT);
@@ -108,12 +108,8 @@ public class LastQueryExecutor {
         resultRecord.addField(pathField);
 
         Field valueField = new Field(TSDataType.TEXT);
-        if (lastTimeValuePair.getValue() != null) {
-          valueField.setBinaryV(new Binary(lastTimeValuePair.getValue().getStringValue()));
-          resultRecord.addField(valueField);
-        } else {
-          resultRecord.addField(null);
-        }
+        valueField.setBinaryV(new Binary(lastTimeValuePair.getValue().getStringValue()));
+        resultRecord.addField(valueField);
 
         dataSet.putRecord(resultRecord);
       }
@@ -167,10 +163,12 @@ public class LastQueryExecutor {
     int index = 0;
     for (int i = 0; i < resultContainer.size(); i++) {
       if (Boolean.FALSE.equals(resultContainer.get(i).left)) {
-        resultContainer.get(i).left = true;
         resultContainer.get(i).right = readerList.get(index++).readLastPoint();
-        if (CACHE_ENABLED) {
-          cacheAccessors.get(i).write(resultContainer.get(i).right);
+        if (resultContainer.get(i).right.getValue() != null) {
+          resultContainer.get(i).left = true;
+          if (CACHE_ENABLED) {
+            cacheAccessors.get(i).write(resultContainer.get(i).right);
+          }
         }
       }
     }
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBLastIT.java b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBLastIT.java
index dabb6bb..37949a7 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBLastIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBLastIT.java
@@ -103,9 +103,8 @@ public class IoTDBLastIT {
   @Test
   public void lastWithEmptySeriesTest() throws Exception {
     String[] retArray = new String[]{
-            "root.ln.wf02.temperature,null",
-            "root.ln.wf02.status,true"
-        };
+            "root.ln.wf02.status,true",
+    };
 
     try (Connection connection =
              DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
@@ -127,6 +126,14 @@ public class IoTDBLastIT {
         Assert.assertEquals(retArray[cnt], ans);
         cnt++;
       }
+
+      // Last query resultSet is empty after deletion
+      statement.execute("INSERT INTO root.ln.wf02(timestamp, temperature) values(300, 100.0)");
+      statement.execute("delete from root.ln.wf02.status where time > 0");
+      statement.execute("select last status from root.ln.wf02");
+
+      resultSet = statement.getResultSet();
+      Assert.assertFalse(resultSet.next());
     }
   }