You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by hu...@apache.org on 2023/02/02 01:27:20 UTC
[iotdb] branch master updated: [IOTDB-5455] Fix case sensitive when use Diff in where & NPE when series in where/having is not exist (#8956)
This is an automated email from the ASF dual-hosted git repository.
hui 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 c7fa8ac1d2 [IOTDB-5455] Fix case sensitive when use Diff in where & NPE when series in where/having is not exist (#8956)
c7fa8ac1d2 is described below
commit c7fa8ac1d2444f3db64dc236c987081636c2f11b
Author: Weihao Li <60...@users.noreply.github.com>
AuthorDate: Thu Feb 2 09:27:13 2023 +0800
[IOTDB-5455] Fix case sensitive when use Diff in where & NPE when series in where/having is not exist (#8956)
---
.../scalar/IoTDBDiffFunctionIT.java | 14 ++++++++
.../iotdb/db/it/query/IoTDBNullOperandIT.java | 40 ++++++++++++++++++++++
.../iotdb/db/mpp/plan/analyze/TypeProvider.java | 5 ++-
.../plan/statement/component/WhereCondition.java | 6 ++--
.../apache/iotdb/db/utils/TypeInferenceUtils.java | 8 +++++
5 files changed, 70 insertions(+), 3 deletions(-)
diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/builtinfunction/scalar/IoTDBDiffFunctionIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/builtinfunction/scalar/IoTDBDiffFunctionIT.java
index da613856a4..37887b4d38 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/builtinfunction/scalar/IoTDBDiffFunctionIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/builtinfunction/scalar/IoTDBDiffFunctionIT.java
@@ -343,4 +343,18 @@ public class IoTDBDiffFunctionIT {
expectedHeader,
retArray);
}
+
+ @Test
+ public void testCaseInSensitive() {
+ String[] expectedHeader = new String[] {TIMESTAMP_STR, "root.db.d1.s1", "root.db.d1.s2"};
+ String[] retArray = new String[] {"2,2,null,", "4,4,null,", "5,5,5.0,"};
+ resultSetEqualTest(
+ "select s1, s2 from root.db.d1 where Diff(s1) between 1 and 2", expectedHeader, retArray);
+
+ retArray = new String[] {};
+ resultSetEqualTest(
+ "select s1, s2 from root.db.d1 where Diff(notExist) between 1 and 2",
+ expectedHeader,
+ retArray);
+ }
}
diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBNullOperandIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBNullOperandIT.java
index b4eccec6b4..8889c9c702 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBNullOperandIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBNullOperandIT.java
@@ -236,4 +236,44 @@ public class IoTDBNullOperandIT {
expectedHeader,
retArray);
}
+
+ @Test
+ public void testSeriesNotExist() {
+ // series in select not exist
+ String[] expectedHeader =
+ new String[] {
+ TIMESTAMP_STR, "root.test.sg1.s1", "root.test.sg1.s3", "root.test.sg1.s4",
+ };
+ String[] retArray =
+ new String[] {
+ "1,1,true,false,", "2,2,true,null,", "3,3,null,false,",
+ };
+ resultSetEqualTest("select s1, s3, s4, notExist from root.**", expectedHeader, retArray);
+
+ // series in where not exist
+
+ retArray = new String[] {};
+ resultSetEqualTest("select s1, s3, s4 from root.** where notExist>0", expectedHeader, retArray);
+
+ resultSetEqualTest(
+ "select s1, s3, s4 from root.** where diff(notExist)>0", expectedHeader, retArray);
+
+ retArray =
+ new String[] {
+ "1,1,true,false,", "2,2,true,null,", "3,3,null,false,",
+ };
+ resultSetEqualTest(
+ "select s1, s3, s4 from root.** where diff(notExist) is null", expectedHeader, retArray);
+
+ // series in having not exist
+ expectedHeader =
+ new String[] {
+ TIMESTAMP_STR, "count(root.test.sg1.s1)", "count(root.test.sg1.s2)",
+ };
+ retArray = new String[] {};
+ resultSetEqualTest(
+ "select count(s1), count(s2) from root.** group by ([1,4),1ms) having count(notExist)>0",
+ expectedHeader,
+ retArray);
+ }
}
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/TypeProvider.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/TypeProvider.java
index 00a433f449..115fafd834 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/TypeProvider.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/TypeProvider.java
@@ -46,7 +46,10 @@ public class TypeProvider {
}
public void setType(String symbol, TSDataType dataType) {
- this.typeMap.put(symbol, dataType);
+ // DataType of NullOperand is null, we needn't put it into TypeProvider
+ if (dataType != null) {
+ this.typeMap.put(symbol, dataType);
+ }
}
public boolean containsTypeInfoOf(String path) {
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/component/WhereCondition.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/component/WhereCondition.java
index 8aa7eb04df..af05803894 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/component/WhereCondition.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/component/WhereCondition.java
@@ -19,6 +19,7 @@
package org.apache.iotdb.db.mpp.plan.statement.component;
+import org.apache.iotdb.db.mpp.plan.analyze.ExpressionAnalyzer;
import org.apache.iotdb.db.mpp.plan.expression.Expression;
import org.apache.iotdb.db.mpp.plan.statement.StatementNode;
@@ -29,8 +30,9 @@ public class WhereCondition extends StatementNode {
public WhereCondition() {}
+ // cast functionName to lowercase in where predicate
public WhereCondition(Expression predicate) {
- this.predicate = predicate;
+ this.predicate = ExpressionAnalyzer.removeAliasFromExpression(predicate);
}
public Expression getPredicate() {
@@ -38,7 +40,7 @@ public class WhereCondition extends StatementNode {
}
public void setPredicate(Expression predicate) {
- this.predicate = predicate;
+ this.predicate = ExpressionAnalyzer.removeAliasFromExpression(predicate);
}
public String toSQLString() {
diff --git a/server/src/main/java/org/apache/iotdb/db/utils/TypeInferenceUtils.java b/server/src/main/java/org/apache/iotdb/db/utils/TypeInferenceUtils.java
index 4df33dad2e..4b2da0c72e 100644
--- a/server/src/main/java/org/apache/iotdb/db/utils/TypeInferenceUtils.java
+++ b/server/src/main/java/org/apache/iotdb/db/utils/TypeInferenceUtils.java
@@ -140,6 +140,10 @@ public class TypeInferenceUtils {
private static boolean verifyIsAggregationDataTypeMatched(
String aggrFuncName, TSDataType dataType) {
+ // input is NullOperand, needn't check
+ if (dataType == null) {
+ return true;
+ }
switch (aggrFuncName.toLowerCase()) {
case SqlConstant.AVG:
case SqlConstant.SUM:
@@ -173,6 +177,10 @@ public class TypeInferenceUtils {
}
private static void verifyIsScalarFunctionDataTypeMatched(String funcName, TSDataType dataType) {
+ // input is NullOperand, needn't check
+ if (dataType == null) {
+ return;
+ }
switch (funcName.toLowerCase()) {
case SqlConstant.DIFF:
if (dataType.isNumeric()) {