You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2021/05/10 05:56:04 UTC
[iotdb] branch QueryWithoutNull updated: finish
This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a commit to branch QueryWithoutNull
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/QueryWithoutNull by this push:
new 92f7db5 finish
92f7db5 is described below
commit 92f7db565f2e5ccd26618a47e1370fe20e186ed9
Author: JackieTien97 <Ja...@foxmail.com>
AuthorDate: Mon May 10 13:55:31 2021 +0800
finish
---
.../antlr4/org/apache/iotdb/db/qp/sql/SqlBase.g4 | 2 +-
...utAnyNullIT.java => IoTDBWithoutAllNullIT.java} | 131 ++++++++-------------
.../db/integration/IoTDBWithoutAnyNullIT.java | 6 +-
.../tsfile/read/query/dataset/QueryDataSet.java | 10 +-
4 files changed, 64 insertions(+), 85 deletions(-)
diff --git a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/SqlBase.g4 b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/SqlBase.g4
index 67a9a10..0cc6f2d 100644
--- a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/SqlBase.g4
+++ b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/SqlBase.g4
@@ -107,7 +107,7 @@ statement
fromClause
whereClause?
specialClause?
- WITHOUT (ALL | ANY) NULL #selectStatement
+ (WITHOUT NULL (ALL | ANY))? #selectStatement
;
selectElements
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBWithoutAnyNullIT.java b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBWithoutAllNullIT.java
similarity index 57%
copy from server/src/test/java/org/apache/iotdb/db/integration/IoTDBWithoutAnyNullIT.java
copy to server/src/test/java/org/apache/iotdb/db/integration/IoTDBWithoutAllNullIT.java
index 98e23c4..306e6b0 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBWithoutAnyNullIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBWithoutAllNullIT.java
@@ -36,39 +36,26 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-public class IoTDBWithoutAnyNullIT {
+public class IoTDBWithoutAllNullIT {
private static final String[] dataSet =
new String[] {
- "SET STORAGE GROUP TO root.testWithoutAnyNull",
- "CREATE TIMESERIES root.testWithoutAnyNull.d1.s1 WITH DATATYPE=INT32, ENCODING=PLAIN",
- "CREATE TIMESERIES root.testWithoutAnyNull.d1.s2 WITH DATATYPE=BOOLEAN, ENCODING=PLAIN",
- "CREATE TIMESERIES root.testWithoutAnyNull.d1.s3 WITH DATATYPE=DOUBLE, ENCODING=PLAIN",
- "INSERT INTO root.testWithoutAnyNull.d1(timestamp,s1,s2,s3) "
- + "values(1, 21, false, 11.1)",
- "INSERT INTO root.testWithoutAnyNull.d1(timestamp,s1,s2) " + "values(2, 22, true)",
- "INSERT INTO root.testWithoutAnyNull.d1(timestamp,s1,s2,s3) "
- + "values(3, 23, false, 33.3)",
- "INSERT INTO root.testWithoutAnyNull.d1(timestamp,s1,s3) " + "values(4, 24, 44.4)",
- "INSERT INTO root.testWithoutAnyNull.d1(timestamp,s2,s3) " + "values(5, true, 55.5)",
- "INSERT INTO root.testWithoutAnyNull.d1(timestamp,s1) " + "values(6, 26)",
- "INSERT INTO root.testWithoutAnyNull.d1(timestamp,s2) " + "values(7, false)",
- "INSERT INTO root.testWithoutAnyNull.d1(timestamp,s3) " + "values(8, 88.8)",
- "INSERT INTO root.testWithoutAnyNull.d1(timestamp,s1,s2,s3) " + "values(9, 29, true, 99.9)",
+ "SET STORAGE GROUP TO root.testWithoutAllNull",
+ "CREATE TIMESERIES root.testWithoutAllNull.d1.s1 WITH DATATYPE=INT32, ENCODING=PLAIN",
+ "CREATE TIMESERIES root.testWithoutAllNull.d1.s2 WITH DATATYPE=BOOLEAN, ENCODING=PLAIN",
+ "CREATE TIMESERIES root.testWithoutAllNull.d1.s3 WITH DATATYPE=DOUBLE, ENCODING=PLAIN",
+ "INSERT INTO root.testWithoutAllNull.d1(timestamp,s1) " + "values(6, 26)",
+ "INSERT INTO root.testWithoutAllNull.d1(timestamp,s2) " + "values(7, false)",
+ "INSERT INTO root.testWithoutAllNull.d1(timestamp,s1,s2) " + "values(9, 29, true)",
"flush",
- "INSERT INTO root.testWithoutAnyNull.d1(timestamp,s1,s2,s3) "
- + "values(10, 20, true, 10.0)",
- "INSERT INTO root.testWithoutAnyNull.d1(timestamp,s1,s2,s3) "
+ "INSERT INTO root.testWithoutAllNull.d1(timestamp,s1,s2) " + "values(10, 20, true)",
+ "INSERT INTO root.testWithoutAllNull.d1(timestamp,s1,s2,s3) "
+ "values(11, 21, false, 11.1)",
- "INSERT INTO root.testWithoutAnyNull.d1(timestamp,s1,s2) " + "values(12, 22, true)",
- "INSERT INTO root.testWithoutAnyNull.d1(timestamp,s1,s2,s3) "
+ "INSERT INTO root.testWithoutAllNull.d1(timestamp,s1,s2) " + "values(12, 22, true)",
+ "INSERT INTO root.testWithoutAllNull.d1(timestamp,s1,s2,s3) "
+ "values(13, 23, false, 33.3)",
- "INSERT INTO root.testWithoutAnyNull.d1(timestamp,s1,s3) " + "values(14, 24, 44.4)",
- "INSERT INTO root.testWithoutAnyNull.d1(timestamp,s2,s3) " + "values(15, true, 55.5)",
- "INSERT INTO root.testWithoutAnyNull.d1(timestamp,s1) " + "values(16, 26)",
- "INSERT INTO root.testWithoutAnyNull.d1(timestamp,s2) " + "values(17, false)",
- "INSERT INTO root.testWithoutAnyNull.d1(timestamp,s3) " + "values(18, 88.8)",
- "INSERT INTO root.testWithoutAnyNull.d1(timestamp,s1,s2,s3) " + "values(19, 29, true, 99.9)"
+ "INSERT INTO root.testWithoutAllNull.d1(timestamp,s1,s3) " + "values(14, 24, 44.4)",
+ "INSERT INTO root.testWithoutAllNull.d1(timestamp,s2,s3) " + "values(15, true, 55.5)",
};
@BeforeClass
@@ -80,6 +67,21 @@ public class IoTDBWithoutAnyNullIT {
prepareData();
}
+ private static void prepareData() {
+ try (Connection connection =
+ DriverManager.getConnection(
+ Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+ Statement statement = connection.createStatement()) {
+
+ for (String sql : dataSet) {
+ statement.execute(sql);
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
@AfterClass
public static void tearDown() throws Exception {
IoTDBDescriptor.getInstance().getConfig().setPartitionInterval(86400);
@@ -87,22 +89,14 @@ public class IoTDBWithoutAnyNullIT {
}
@Test
- public void withoutAnyNullTest1() {
- String[] retArray1 =
- new String[] {
- "1,21,false,11.1",
- "3,23,false,33.3",
- "9,29,true,99.9",
- "10,20,true,10.0",
- "11,21,false,11.1",
- "13,23,false,33.3",
- "19,29,true,99.9"
- };
+ public void withoutAllNullTest1() {
+ String[] retArray1 = new String[] {"6,20,true,null", "11,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 * from root.testWithoutAnyNull.d1 WITHOUT ANY NULL");
+ statement.execute(
+ "select last_value(*) from root.testWithoutAllNull.d1 GROUP BY([1, 21), 5ms) WITHOUT NULL ALL");
assertTrue(hasResultSet);
int cnt;
@@ -112,11 +106,11 @@ public class IoTDBWithoutAnyNullIT {
String ans =
resultSet.getString(TIMESTAMP_STR)
+ ","
- + resultSet.getString("root.testWithoutAnyNull.d1.s1")
+ + resultSet.getString("last_value(root.testWithoutAllNull.d1.s1)")
+ ","
- + resultSet.getString("root.testWithoutAnyNull.d1.s2")
+ + resultSet.getString("last_value(root.testWithoutAllNull.d1.s2)")
+ ","
- + resultSet.getString("root.testWithoutAnyNull.d1.s3");
+ + resultSet.getString("last_value(root.testWithoutAllNull.d1.s3)");
assertEquals(retArray1[cnt], ans);
cnt++;
}
@@ -129,33 +123,32 @@ public class IoTDBWithoutAnyNullIT {
}
@Test
- public void withoutAnyNullTest2() {
- String[] retArray =
- new String[] {"10,20,true,10.0", "11,21,false,11.1", "13,23,false,33.3", "19,29,true,99.9"};
+ public void withoutAllNullTest2() {
+ String[] retArray1 = new String[] {"11,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 * from root.testWithoutAnyNull.d1 WHERE time >= 10 WITHOUT ANY NULL");
+ "select last_value(*) from root.testWithoutAllNull.d1 GROUP BY([1, 21), 5ms) limit 1 offset 1 WITHOUT NULL ALL");
- int cnt;
assertTrue(hasResultSet);
+ int cnt;
try (ResultSet resultSet = statement.getResultSet()) {
cnt = 0;
while (resultSet.next()) {
String ans =
resultSet.getString(TIMESTAMP_STR)
+ ","
- + resultSet.getString("root.testWithoutAnyNull.d1.s1")
+ + resultSet.getString("last_value(root.testWithoutAllNull.d1.s1)")
+ ","
- + resultSet.getString("root.testWithoutAnyNull.d1.s2")
+ + resultSet.getString("last_value(root.testWithoutAllNull.d1.s2)")
+ ","
- + resultSet.getString("root.testWithoutAnyNull.d1.s3");
- assertEquals(retArray[cnt], ans);
+ + resultSet.getString("last_value(root.testWithoutAllNull.d1.s3)");
+ assertEquals(retArray1[cnt], ans);
cnt++;
}
- assertEquals(retArray.length, cnt);
+ assertEquals(retArray1.length, cnt);
}
} catch (Exception e) {
e.printStackTrace();
@@ -164,21 +157,14 @@ public class IoTDBWithoutAnyNullIT {
}
@Test
- public void withoutAnyNullTest3() {
- String[] retArray1 =
- new String[] {
- "3,23,false,33.3",
- "9,29,true,99.9",
- "10,20,true,10.0",
- "11,21,false,11.1",
- "13,23,false,33.3"
- };
+ public void withoutAllNullTest3() {
+ String[] retArray1 = new String[] {"11,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 * from root.testWithoutAnyNull.d1 limit 5 offset 1 WITHOUT ANY NULL");
+ "select last_value(*) from root.testWithoutAllNull.d1 GROUP BY([1, 21), 5ms) WITHOUT NULL ANY");
assertTrue(hasResultSet);
int cnt;
@@ -188,11 +174,11 @@ public class IoTDBWithoutAnyNullIT {
String ans =
resultSet.getString(TIMESTAMP_STR)
+ ","
- + resultSet.getString("root.testWithoutAnyNull.d1.s1")
+ + resultSet.getString("last_value(root.testWithoutAllNull.d1.s1)")
+ ","
- + resultSet.getString("root.testWithoutAnyNull.d1.s2")
+ + resultSet.getString("last_value(root.testWithoutAllNull.d1.s2)")
+ ","
- + resultSet.getString("root.testWithoutAnyNull.d1.s3");
+ + resultSet.getString("last_value(root.testWithoutAllNull.d1.s3)");
assertEquals(retArray1[cnt], ans);
cnt++;
}
@@ -203,19 +189,4 @@ public class IoTDBWithoutAnyNullIT {
fail(e.getMessage());
}
}
-
- private static void prepareData() {
- try (Connection connection =
- DriverManager.getConnection(
- Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
- Statement statement = connection.createStatement()) {
-
- for (String sql : dataSet) {
- statement.execute(sql);
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
}
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBWithoutAnyNullIT.java b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBWithoutAnyNullIT.java
index 98e23c4..35f9858 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBWithoutAnyNullIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBWithoutAnyNullIT.java
@@ -102,7 +102,7 @@ public class IoTDBWithoutAnyNullIT {
DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
Statement statement = connection.createStatement()) {
boolean hasResultSet =
- statement.execute("select * from root.testWithoutAnyNull.d1 WITHOUT ANY NULL");
+ statement.execute("select * from root.testWithoutAnyNull.d1 WITHOUT NULL ANY");
assertTrue(hasResultSet);
int cnt;
@@ -137,7 +137,7 @@ public class IoTDBWithoutAnyNullIT {
Statement statement = connection.createStatement()) {
boolean hasResultSet =
statement.execute(
- "select * from root.testWithoutAnyNull.d1 WHERE time >= 10 WITHOUT ANY NULL");
+ "select * from root.testWithoutAnyNull.d1 WHERE time >= 10 WITHOUT NULL ANY");
int cnt;
assertTrue(hasResultSet);
@@ -178,7 +178,7 @@ public class IoTDBWithoutAnyNullIT {
Statement statement = connection.createStatement()) {
boolean hasResultSet =
statement.execute(
- "select * from root.testWithoutAnyNull.d1 limit 5 offset 1 WITHOUT ANY NULL");
+ "select * from root.testWithoutAnyNull.d1 limit 5 offset 1 WITHOUT NULL ANY");
assertTrue(hasResultSet);
int cnt;
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 2d4be4d..2be08a7 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
@@ -103,7 +103,15 @@ public abstract class QueryDataSet {
// proceed to the OFFSET row by skipping rows
while (rowOffset > 0) {
if (hasNextWithoutConstraint()) {
- nextWithoutConstraint(); // DO NOT use next()
+ RowRecord rowRecord = nextWithoutConstraint(); // DO NOT use next()
+ // filter the row that all columns are null
+ if (withoutAllNull && rowRecord.isAllNull()) {
+ continue;
+ }
+ // filter the row that any column is null
+ if (withoutAnyNull && rowRecord.hasNullField()) {
+ continue;
+ }
rowOffset--;
} else {
return false;