From 5c3283a6de8485fba5200f63edaa957c172c54b8 Mon Sep 17 00:00:00 2001 From: xsren <285808407@qq.com> Date: Tue, 15 Oct 2024 17:00:25 +0800 Subject: [PATCH 1/3] fix: not condition --- source/libs/scalar/src/filter.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index e07ef69990..802bec00f8 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -4679,6 +4679,9 @@ EDealRes fltReviseRewriter(SNode **pNode, void *pContext) { cell = cell->pNext; } + if (node->condType == LOGIC_COND_TYPE_NOT) { + stat->scalarMode = true; + } return DEAL_RES_CONTINUE; } From 200ca2cb10cca5c10f189310e54ee35791f91155 Mon Sep 17 00:00:00 2001 From: xsren <285808407@qq.com> Date: Tue, 15 Oct 2024 19:40:04 +0800 Subject: [PATCH 2/3] not test case --- tests/system-test/2-query/not.py | 133 +++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 tests/system-test/2-query/not.py diff --git a/tests/system-test/2-query/not.py b/tests/system-test/2-query/not.py new file mode 100644 index 0000000000..a0bd1d4e1d --- /dev/null +++ b/tests/system-test/2-query/not.py @@ -0,0 +1,133 @@ +from wsgiref.headers import tspecials +from util.log import * +from util.cases import * +from util.sql import * +from util.common import tdCom +import numpy as np + + +class TDTestCase: + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + self.dbname = "db" + self.rowNum = 10 + self.ts = 1537146000000 + + def notConditionTest(self): + dbname = "nottest" + stbname = "st1" + + tdsql = tdCom.newTdSql() + tdsql.execute(f"create database if not exists {dbname}") + + stype = ["INT", "INT UNSIGNED", "BIGINT", "BIGINT UNSIGNED", "DOUBLE", "FLOAT", "SMALLINT", "SMALLINT UNSIGNED", "TINYINT", "TINYINT UNSIGNED"] + + for type_name in stype: + tdsql.execute(f"drop table if exists {dbname}.{stbname}") + tdsql.execute(f"create table if not exists {dbname}.{stbname} (ts timestamp, v1 {type_name}) tags(t1 {type_name})") + tdsql.execute(f"insert into {dbname}.sub_1 using {dbname}.{stbname} tags(1) values({self.ts}, 10)") + tdsql.execute(f"insert into {dbname}.sub_2 using {dbname}.{stbname} tags(2) values({self.ts + 1000}, 20)") + tdsql.execute(f"insert into {dbname}.sub_3 using {dbname}.{stbname} tags(3) values({self.ts + 2000}, 30)") + + # Test case 1: NOT IN + tdsql.query(f"select t1, * from {dbname}.{stbname} where t1 not in (1, 2) order by t1") + tdsql.checkRows(1) + tdsql.checkData(0, 0, 3) + + # Test case 2: NOT BETWEEN + tdsql.query(f"select * from {dbname}.{stbname} where v1 not between 10 and 20 order by t1") + tdsql.checkRows(1) + tdsql.checkData(0, 1, 30) + tdsql.query(f"select * from {dbname}.{stbname} where not(v1 not between 10 and 20) order by t1") + tdsql.checkRows(2) + + # Test case 4: NOT EQUAL + tdsql.query(f"select * from {dbname}.{stbname} where v1 != 20 order by t1") + tdsql.checkRows(2) + tdsql.checkData(0, 1, 10) + tdsql.checkData(1, 1, 30) + + # Test case 8: NOT (v1 < 20 OR v1 > 30) + tdsql.query(f"select * from {dbname}.{stbname} where not (v1 < 20 or v1 > 30) order by t1") + tdsql.checkRows(2) + tdsql.checkData(0, 1, 20) + tdsql.checkData(1, 1, 30) + + tdsql.query(f"select * from {dbname}.{stbname} where not (v1 < 20 or v1 >= 30) order by t1") + tdsql.checkRows(1) + + # Test case 9: NOT (t1 != 1) + tdsql.query(f"select * from {dbname}.{stbname} where not (t1 != 1) order by t1") + tdsql.checkRows(1) + tdsql.checkData(0, 1, 10) + + tdsql.query(f"select * from {dbname}.{stbname} where (t1 != 1) or not (v1 == 20) order by t1") + tdsql.checkRows(3) + tdsql.checkData(0, 1, 10) + tdsql.checkData(1, 1, 20) + tdsql.checkData(2, 1, 30) + + tdsql.query(f"select * from {dbname}.{stbname} where not((t1 != 1) or not (v1 == 20)) order by t1") + tdsql.checkRows(0) + + tdsql.query(f"select * from {dbname}.{stbname} where not (t1 != 1) and not (v1 != 20) order by t1") + tdsql.checkRows(0) + + tdsql.query(f"select * from {dbname}.{stbname} where not(not (t1 != 1) and not (v1 != 20)) order by t1") + tdsql.checkRows(3) + + tdsql.query(f"select * from {dbname}.{stbname} where not (t1 != 1) and not (v1 != 10) order by t1") + tdsql.checkRows(1) + tdsql.checkData(0, 1, 10) + + tdsql.query(f"select * from {dbname}.{stbname} where not (t1 > 2) order by t1") + tdsql.checkRows(2) + tdsql.checkData(0, 1, 10) + tdsql.checkData(1, 1, 20) + + tdsql.query(f"select * from {dbname}.{stbname} where not (t1 == 2) order by t1") + tdsql.checkRows(2) + tdsql.checkData(0, 1, 10) + tdsql.checkData(1, 1, 30) + + tdsql.query(f"select * from {dbname}.{stbname} where not (v1 > 10 and v1 < 30) order by t1") + tdsql.checkRows(2) + tdsql.checkData(0, 1, 10) + tdsql.checkData(1, 1, 30) + + # tdsql.query(f"select * from {dbname}.{stbname} where not(not (v1 < 20 or v1 > 30)) order by t1") + # tdsql.checkRows(1) + # + # tdsql.checkData(0, 1, 20) + # tdsql.query(f"select * from {dbname}.{stbname} where not(not (v1 < 20 or v1 >= 30)) order by t1") + # tdsql.checkRows(2) + # + # tdsql.query(f"select * from {dbname}.{stbname} where not(not (t1 != 1)) order by t1") + # tdsql.checkRows(2) + # + # tdsql.query(f"select * from {dbname}.{stbname} where not(not (t1 > 2)) order by t1") + # tdsql.checkRows(1) + # + # tdsql.query(f"select * from {dbname}.{stbname} where not(not (t1 == 2)) order by t1") + # tdsql.checkRows(1) + # + # tdsql.query(f"select * from {dbname}.{stbname} where not(not (v1 > 10 and v1 < 30)) order by t1") + # tdsql.checkRows(1) + + def run(self): + dbname = "db" + tdSql.prepare() + + self.notConditionTest() + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) + +tdCases.addLinux(__file__, TDTestCase()) From 9bf2c61d9357faae785e78fc7209a1b686c03745 Mon Sep 17 00:00:00 2001 From: factosea <285808407@qq.com> Date: Wed, 16 Oct 2024 16:15:45 +0800 Subject: [PATCH 3/3] not nest --- source/libs/parser/src/parAstCreater.c | 3 ++- tests/pytest/fulltest.sh | 1 + tests/pytest/regressiontest.sh | 1 + tests/system-test/2-query/not.py | 35 +++++++++++++------------- tests/system-test/runAllOne.sh | 5 ++++ 5 files changed, 26 insertions(+), 19 deletions(-) diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 5db7e18fc5..3bb9e15182 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -887,7 +887,8 @@ _err: } static int32_t addParamToLogicConditionNode(SLogicConditionNode* pCond, SNode* pParam) { - if (QUERY_NODE_LOGIC_CONDITION == nodeType(pParam) && pCond->condType == ((SLogicConditionNode*)pParam)->condType) { + if (QUERY_NODE_LOGIC_CONDITION == nodeType(pParam) && pCond->condType == ((SLogicConditionNode*)pParam)->condType && + ((SLogicConditionNode*)pParam)->condType != LOGIC_COND_TYPE_NOT) { int32_t code = nodesListAppendList(pCond->pParameterList, ((SLogicConditionNode*)pParam)->pParameterList); ((SLogicConditionNode*)pParam)->pParameterList = NULL; nodesDestroyNode(pParam); diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index 3df42cbf33..eb975ec46f 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -225,6 +225,7 @@ python3 test.py -f query/distinctOneColTb.py python3 ./test.py -f query/filter.py python3 ./test.py -f query/filterCombo.py python3 ./test.py -f query/queryNormal.py +python3 ./test.py -f query/not.py python3 ./test.py -f query/queryError.py python3 ./test.py -f query/filterAllIntTypes.py python3 ./test.py -f query/filterFloatAndDouble.py diff --git a/tests/pytest/regressiontest.sh b/tests/pytest/regressiontest.sh index b69ee37a55..e42d53ded1 100755 --- a/tests/pytest/regressiontest.sh +++ b/tests/pytest/regressiontest.sh @@ -139,6 +139,7 @@ python3 ./test.py -f query/querySort.py python3 ./test.py -f query/queryJoin.py python3 ./test.py -f query/filterCombo.py python3 ./test.py -f query/queryNormal.py +python3 ./test.py -f query/not.py python3 ./test.py -f query/select_last_crash.py python3 ./test.py -f query/queryNullValueTest.py python3 ./test.py -f query/queryInsertValue.py diff --git a/tests/system-test/2-query/not.py b/tests/system-test/2-query/not.py index a0bd1d4e1d..1254226db3 100644 --- a/tests/system-test/2-query/not.py +++ b/tests/system-test/2-query/not.py @@ -98,24 +98,23 @@ class TDTestCase: tdsql.checkData(0, 1, 10) tdsql.checkData(1, 1, 30) - # tdsql.query(f"select * from {dbname}.{stbname} where not(not (v1 < 20 or v1 > 30)) order by t1") - # tdsql.checkRows(1) - # - # tdsql.checkData(0, 1, 20) - # tdsql.query(f"select * from {dbname}.{stbname} where not(not (v1 < 20 or v1 >= 30)) order by t1") - # tdsql.checkRows(2) - # - # tdsql.query(f"select * from {dbname}.{stbname} where not(not (t1 != 1)) order by t1") - # tdsql.checkRows(2) - # - # tdsql.query(f"select * from {dbname}.{stbname} where not(not (t1 > 2)) order by t1") - # tdsql.checkRows(1) - # - # tdsql.query(f"select * from {dbname}.{stbname} where not(not (t1 == 2)) order by t1") - # tdsql.checkRows(1) - # - # tdsql.query(f"select * from {dbname}.{stbname} where not(not (v1 > 10 and v1 < 30)) order by t1") - # tdsql.checkRows(1) + tdsql.query(f"select * from {dbname}.{stbname} where not(not (v1 < 20 or v1 > 30)) order by t1") + tdsql.checkRows(1) + + tdsql.query(f"select * from {dbname}.{stbname} where not(not (v1 < 20 or v1 >= 30)) order by t1") + tdsql.checkRows(2) + + tdsql.query(f"select * from {dbname}.{stbname} where not(not (t1 != 1)) order by t1") + tdsql.checkRows(2) + + tdsql.query(f"select * from {dbname}.{stbname} where not(not (t1 > 2)) order by t1") + tdsql.checkRows(1) + + tdsql.query(f"select * from {dbname}.{stbname} where not(not (t1 == 2)) order by t1") + tdsql.checkRows(1) + + tdsql.query(f"select * from {dbname}.{stbname} where not(not (v1 > 10 and v1 < 30)) order by t1") + tdsql.checkRows(1) def run(self): dbname = "db" diff --git a/tests/system-test/runAllOne.sh b/tests/system-test/runAllOne.sh index 3bb128ea28..0d65fd616b 100644 --- a/tests/system-test/runAllOne.sh +++ b/tests/system-test/runAllOne.sh @@ -245,6 +245,8 @@ python3 ./test.py -f 2-query/min.py -P python3 ./test.py -f 2-query/min.py -P -R python3 ./test.py -f 2-query/normal.py -P python3 ./test.py -f 2-query/normal.py -P -R +python3 ./test.py -f 2-query/not.py -P +python3 ./test.py -f 2-query/not.py -P -R python3 ./test.py -f 2-query/mode.py -P python3 ./test.py -f 2-query/mode.py -P -R python3 ./test.py -f 2-query/Now.py -P @@ -427,6 +429,7 @@ python3 ./test.py -f 2-query/Today.py -P -Q 2 python3 ./test.py -f 2-query/max.py -P -Q 2 python3 ./test.py -f 2-query/min.py -P -Q 2 python3 ./test.py -f 2-query/normal.py -P -Q 2 +python3 ./test.py -f 2-query/not.py -P -Q 2 python3 ./test.py -f 2-query/mode.py -P -Q 2 python3 ./test.py -f 2-query/count.py -P -Q 2 python3 ./test.py -f 2-query/countAlwaysReturnValue.py -P -Q 2 @@ -526,6 +529,7 @@ python3 ./test.py -f 2-query/Today.py -P -Q 3 python3 ./test.py -f 2-query/max.py -P -Q 3 python3 ./test.py -f 2-query/min.py -P -Q 3 python3 ./test.py -f 2-query/normal.py -P -Q 3 +python3 ./test.py -f 2-query/not.py -P -Q 3 python3 ./test.py -f 2-query/mode.py -P -Q 3 python3 ./test.py -f 2-query/count.py -P -Q 3 python3 ./test.py -f 2-query/countAlwaysReturnValue.py -P -Q 3 @@ -624,6 +628,7 @@ python3 ./test.py -f 2-query/Today.py -P -Q 4 python3 ./test.py -f 2-query/max.py -P -Q 4 python3 ./test.py -f 2-query/min.py -P -Q 4 python3 ./test.py -f 2-query/normal.py -P -Q 4 +python3 ./test.py -f 2-query/not.py -P -Q 4 python3 ./test.py -f 2-query/mode.py -P -Q 4 python3 ./test.py -f 2-query/count.py -P -Q 4 python3 ./test.py -f 2-query/countAlwaysReturnValue.py -P -Q 4