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

jackietien 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 a22c006  [IOTDB-1387] [To rel/0.12] Fix Without Null ALL doesn't take 
effect in align by device clause (#3246)
a22c006 is described below

commit a22c006570f6690e54f60cf06812d980e0f5f084
Author: Jackie Tien <[email protected]>
AuthorDate: Fri May 21 18:26:29 2021 +0800

    [IOTDB-1387] [To rel/0.12] Fix Without Null ALL doesn't take effect in 
align by device clause (#3246)
    
    Fix Without Null ALL doesn't take effect in align by device clause
---
 .../db/query/dataset/AlignByDeviceDataSet.java     |  3 +
 .../apache/iotdb/db/utils/QueryDataSetUtils.java   |  2 +
 .../db/integration/IoTDBWithoutAllNullIT.java      | 72 ++++++++++++++++++++++
 .../apache/iotdb/tsfile/read/common/RowRecord.java |  5 ++
 .../tsfile/read/query/dataset/QueryDataSet.java    |  4 ++
 5 files changed, 86 insertions(+)

diff --git 
a/server/src/main/java/org/apache/iotdb/db/query/dataset/AlignByDeviceDataSet.java
 
b/server/src/main/java/org/apache/iotdb/db/query/dataset/AlignByDeviceDataSet.java
index b37a16e..500a845 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/query/dataset/AlignByDeviceDataSet.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/query/dataset/AlignByDeviceDataSet.java
@@ -235,6 +235,9 @@ public class AlignByDeviceDataSet extends QueryDataSet {
     Field deviceField = new Field(TSDataType.TEXT);
     deviceField.setBinaryV(new Binary(currentDevice.getFullPath()));
     rowRecord.addField(deviceField);
+    // device field should not be considered as a value field it should affect 
the WITHOUT NULL
+    // judgement
+    rowRecord.resetNullFlag();
 
     List<Field> measurementFields = originRowRecord.getFields();
     Map<String, Field> currentColumnMap = new HashMap<>();
diff --git 
a/server/src/main/java/org/apache/iotdb/db/utils/QueryDataSetUtils.java 
b/server/src/main/java/org/apache/iotdb/db/utils/QueryDataSetUtils.java
index a88b074..cf92cdb 100644
--- a/server/src/main/java/org/apache/iotdb/db/utils/QueryDataSetUtils.java
+++ b/server/src/main/java/org/apache/iotdb/db/utils/QueryDataSetUtils.java
@@ -70,6 +70,8 @@ public class QueryDataSetUtils {
         // filter rows whose columns are null according to the rule
         if ((queryDataSet.isWithoutAllNull() && rowRecord.isAllNull())
             || (queryDataSet.isWithoutAnyNull() && rowRecord.hasNullField())) {
+          // if the current RowRecord doesn't satisfy, we should also decrease 
AlreadyReturnedRowNum
+          queryDataSet.decreaseAlreadyReturnedRowNum();
           i--;
           continue;
         }
diff --git 
a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBWithoutAllNullIT.java
 
b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBWithoutAllNullIT.java
index 95cce53..b8efe89 100644
--- 
a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBWithoutAllNullIT.java
+++ 
b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBWithoutAllNullIT.java
@@ -189,4 +189,76 @@ public class IoTDBWithoutAllNullIT {
       fail(e.getMessage());
     }
   }
+
+  @Test
+  public void withoutAllNullTest4() {
+    String[] retArray1 = new String[] 
{"11,root.testWithoutAllNull.d1,24,true,55.5"};
+    try (Connection connection =
+            DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", 
"root", "root");
+        Statement statement = connection.createStatement()) {
+      boolean hasResultSet =
+          statement.execute(
+              "select last_value(*) from root.testWithoutAllNull.d1 GROUP 
BY([1, 21), 5ms) WITHOUT NULL ALL LIMIT 1 OFFSET 1 ALIGN BY DEVICE");
+
+      assertTrue(hasResultSet);
+      int cnt;
+      try (ResultSet resultSet = statement.getResultSet()) {
+        cnt = 0;
+        while (resultSet.next()) {
+          String ans =
+              resultSet.getString(TIMESTAMP_STR)
+                  + ","
+                  + resultSet.getString("Device")
+                  + ","
+                  + resultSet.getString("last_value(s1)")
+                  + ","
+                  + resultSet.getString("last_value(s2)")
+                  + ","
+                  + resultSet.getString("last_value(s3)");
+          assertEquals(retArray1[cnt], ans);
+          cnt++;
+        }
+        assertEquals(retArray1.length, cnt);
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.getMessage());
+    }
+  }
+
+  @Test
+  public void withoutAllNullTest5() {
+    String[] retArray1 = new String[] 
{"6,root.testWithoutAllNull.d1,20,true,null"};
+    try (Connection connection =
+            DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", 
"root", "root");
+        Statement statement = connection.createStatement()) {
+      boolean hasResultSet =
+          statement.execute(
+              "select last_value(*) from root.testWithoutAllNull.d1 GROUP 
BY([1, 21), 5ms) ORDER BY TIME DESC WITHOUT NULL ALL LIMIT 1 OFFSET 1 ALIGN BY 
DEVICE");
+
+      assertTrue(hasResultSet);
+      int cnt;
+      try (ResultSet resultSet = statement.getResultSet()) {
+        cnt = 0;
+        while (resultSet.next()) {
+          String ans =
+              resultSet.getString(TIMESTAMP_STR)
+                  + ","
+                  + resultSet.getString("Device")
+                  + ","
+                  + resultSet.getString("last_value(s1)")
+                  + ","
+                  + resultSet.getString("last_value(s2)")
+                  + ","
+                  + resultSet.getString("last_value(s3)");
+          assertEquals(retArray1[cnt], ans);
+          cnt++;
+        }
+        assertEquals(retArray1.length, cnt);
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.getMessage());
+    }
+  }
 }
diff --git 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/RowRecord.java 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/RowRecord.java
index ba41702..e45bc4e 100644
--- a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/RowRecord.java
+++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/RowRecord.java
@@ -98,4 +98,9 @@ public class RowRecord {
   public boolean isAllNull() {
     return allNull;
   }
+
+  public void resetNullFlag() {
+    hasNullField = false;
+    allNull = true;
+  }
 }
diff --git 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/dataset/QueryDataSet.java
 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/dataset/QueryDataSet.java
index c782743..0aaed56 100644
--- 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/dataset/QueryDataSet.java
+++ 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/dataset/QueryDataSet.java
@@ -194,4 +194,8 @@ public abstract class QueryDataSet {
   public void setWithoutAllNull(boolean withoutAllNull) {
     this.withoutAllNull = withoutAllNull;
   }
+
+  public void decreaseAlreadyReturnedRowNum() {
+    alreadyReturnedRowNum--;
+  }
 }

Reply via email to