This is an automated email from the ASF dual-hosted git repository.
jackietien 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 fee62c1 [IOTDB-1387] Fix Without Null ALL doesn't take effect in
align by device clause (#3245)
fee62c1 is described below
commit fee62c1ad88121de22ce9519687ebd9710214ad1
Author: Jackie Tien <[email protected]>
AuthorDate: Fri May 21 18:25:58 2021 +0800
[IOTDB-1387] Fix Without Null ALL doesn't take effect in align by device
clause (#3245)
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 38e1821..c236e59 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
@@ -248,6 +248,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 edf720c..f467a14 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 4365732..df0c051 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
@@ -94,4 +94,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--;
+ }
}