Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
import java.sql.Statement;

import static org.apache.iotdb.db.it.utils.TestUtils.resultSetEqualTest;
import static org.apache.iotdb.itbase.constant.TestConstant.DEVICE;
import static org.apache.iotdb.itbase.constant.TestConstant.TIMESTAMP_STR;
import static org.apache.iotdb.itbase.constant.TestConstant.count;
import static org.junit.Assert.fail;

@RunWith(IoTDBTestRunner.class)
Expand Down Expand Up @@ -290,4 +293,51 @@ public void testDoubleLiteralOverflow() {
expectedHeaderInt64,
allInt64Rows);
}

@Test
public void testWhereAndHavingWithNot() {
// Non align by device: WHERE with NOT
String[] expectedWhereHeader = new String[] {TIMESTAMP_STR, DEVICE_ID + ".int32_col"};
String[] whereRetArray = new String[] {"1,20,", "8,1000,", "9,-29,", "10,-30,"};
resultSetEqualTest(
"SELECT int32_col FROM " + DEVICE_ID + " WHERE NOT (int32_col > 20 AND int32_col < 40)",
expectedWhereHeader,
whereRetArray);

// Non align by device: HAVING with NOT
String[] expectedHavingHeader = new String[] {TIMESTAMP_STR, count(DEVICE_ID + ".int32_col")};
String[] havingRetArray = new String[] {"5,1,", "7,1,"};
resultSetEqualTest(
"SELECT count(int32_col) FROM "
+ DEVICE_ID
+ " GROUP BY ([1,11),2ms) HAVING NOT (count(int32_col) > 1)",
expectedHavingHeader,
havingRetArray);

// Align by device: WHERE with NOT
String[] expectedWhereAlignByDeviceHeader = new String[] {TIMESTAMP_STR, DEVICE, "int32_col"};
String[] whereAlignByDeviceRetArray =
new String[] {
"1,root.test_pred.d1,20,",
"8,root.test_pred.d1,1000,",
"9,root.test_pred.d1,-29,",
"10,root.test_pred.d1,-30,",
};
resultSetEqualTest(
"SELECT int32_col FROM root.test_pred.* WHERE NOT (int32_col > 20 AND int32_col < 40) ALIGN BY DEVICE",
expectedWhereAlignByDeviceHeader,
whereAlignByDeviceRetArray);

// Align by device: HAVING with NOT
String[] expectedHavingAlignByDeviceHeader =
new String[] {TIMESTAMP_STR, DEVICE, count("int32_col")};
String[] havingAlignByDeviceRetArray =
new String[] {
"5,root.test_pred.d1,1,", "7,root.test_pred.d1,1,",
};
resultSetEqualTest(
"SELECT count(int32_col) FROM root.test_pred.* GROUP BY ([1,11),2ms) HAVING NOT (count(int32_col) > 1) ALIGN BY DEVICE",
expectedHavingAlignByDeviceHeader,
havingAlignByDeviceRetArray);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@
return analyzeLastSourceAndDataPartition(analysis, selectExpressions, schemaTree, context);
}

private Analysis analyzeLastSourceAndDataPartition(

Check warning on line 554 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

A "Brain Method" was detected. Refactor it to reduce at least one of the following metrics: LOC from 73 to 64, Complexity from 15 to 14, Nesting Level from 5 to 2, Number of Variables from 20 to 6.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ5nLNMM54-UuHs-DuAL&open=AZ5nLNMM54-UuHs-DuAL&pullRequest=17774
Analysis analysis,
List<Expression> selectExpressions,
ISchemaTree schemaTree,
Expand Down Expand Up @@ -983,10 +983,12 @@
ISchemaTree schemaTree,
UnaryOperator<Expression> havingExpressionAnalyzer,
MPPQueryContext queryContext) {
Expression havingPredicate =
PredicateUtils.predicateRemoveNot(queryStatement.getHavingCondition().getPredicate());
// get removeWildcard Expressions in Having
List<Expression> conJunctions =
ExpressionAnalyzer.bindSchemaForPredicate(
queryStatement.getHavingCondition().getPredicate(),
havingPredicate,
queryStatement.getFromComponent().getPrefixPaths(),
schemaTree,
true,
Expand Down Expand Up @@ -1062,7 +1064,8 @@
Map<IDeviceID, Set<Expression>> deviceToOutputExpressions =
analysis.getDeviceToOutputExpressions();

Expression havingExpression = queryStatement.getHavingCondition().getPredicate();
Expression havingExpression =
PredicateUtils.predicateRemoveNot(queryStatement.getHavingCondition().getPredicate());
Set<Expression> conJunctions = new HashSet<>();

for (PartialPath device : deviceSet) {
Expand Down Expand Up @@ -1522,9 +1525,11 @@
if (!queryStatement.hasWhere()) {
return;
}
Expression wherePredicate =
PredicateUtils.predicateRemoveNot(queryStatement.getWhereCondition().getPredicate());
List<Expression> conJunctions =
ExpressionAnalyzer.bindSchemaForPredicate(
queryStatement.getWhereCondition().getPredicate(),
wherePredicate,
queryStatement.getFromComponent().getPrefixPaths(),
schemaTree,
true,
Expand All @@ -1548,13 +1553,11 @@
final PartialPath devicePath,
final ISchemaTree schemaTree,
final MPPQueryContext queryContext) {
Expression wherePredicate =
PredicateUtils.predicateRemoveNot(queryStatement.getWhereCondition().getPredicate());
List<Expression> conJunctions =
ExpressionAnalyzer.concatDeviceAndBindSchemaForPredicate(
queryStatement.getWhereCondition().getPredicate(),
devicePath,
schemaTree,
true,
queryContext);
wherePredicate, devicePath, schemaTree, true, queryContext);
return convertConJunctionsToWhereExpression(conJunctions);
}

Expand Down Expand Up @@ -2172,7 +2175,7 @@
* contains [XX, +oo), res.right.right = true
*/
@SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity warning
public static Pair<List<TTimePartitionSlot>, Pair<Boolean, Boolean>> getTimePartitionSlotList(

Check warning on line 2178 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

A "Brain Method" was detected. Refactor it to reduce at least one of the following metrics: LOC from 71 to 64, Complexity from 15 to 14, Nesting Level from 3 to 2, Number of Variables from 14 to 6.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ5nLNMM54-UuHs-DuAM&open=AZ5nLNMM54-UuHs-DuAM&pullRequest=17774
Filter timeFilter, MPPQueryContext context) {
if (timeFilter == null) {
// (-oo, +oo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public Boolean visitRegularExpression(RegularExpression regularExpression, Void

@Override
public Boolean visitLogicNotExpression(LogicNotExpression logicNotExpression, Void context) {
// Not should have been removed in analyze stage
throw new IllegalArgumentException(CONTAIN_NOT_ERR_MSG);
}

Expand Down
Loading