From 4d595938df61b031ab7b61f9a012149212e9a24f Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Tue, 26 Apr 2022 16:40:30 +0800 Subject: [PATCH] handle null value --- source/libs/scalar/src/filter.c | 5 + tests/script/jenkins/basic.txt | 1 + tests/script/tsim/query/scalarNull.sim | 146 ++++++++++++------------- 3 files changed, 74 insertions(+), 78 deletions(-) diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index ef35d19544..5522bfc6a3 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -3587,6 +3587,11 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { return DEAL_RES_CONTINUE; } + if (node->opType == OP_TYPE_NOT_IN || node->opType == OP_TYPE_NOT_LIKE || node->opType > OP_TYPE_IS_NOT_NULL) { + stat->scalarMode = true; + return DEAL_RES_CONTINUE; + } + if (NULL == node->pRight) { if (scalarGetOperatorParamNum(node->opType) > 1) { fltError("invalid operator, pRight:%p, nodeType:%d, opType:%d", node->pRight, nodeType(node), node->opType); diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 83bd016d2f..0256905a6e 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -34,6 +34,7 @@ ./test.sh -f tsim/query/charScalarFunction.sim ./test.sh -f tsim/query/explain.sim ./test.sh -f tsim/query/session.sim +./test.sh -f tsim/query/scalarNull.sim # ---- qnode ./test.sh -f tsim/qnode/basic1.sim diff --git a/tests/script/tsim/query/scalarNull.sim b/tests/script/tsim/query/scalarNull.sim index 66d3c48f5d..c7e7aa9a34 100644 --- a/tests/script/tsim/query/scalarNull.sim +++ b/tests/script/tsim/query/scalarNull.sim @@ -14,89 +14,79 @@ sql create database db1 vgroups 3; sql use db1; sql show databases; sql create stable st1 (ts timestamp, f1 int, f2 binary(200)) tags(t1 int); -sql create stable st2 (ts timestamp, f1 int, f2 binary(200)) tags(t1 int); sql create table tb1 using st1 tags(1); -sql insert into tb1 values (now, 1, "Hash Join (cost=230.47..713.98 rows=101 width=488) (actual time=0.711..7.427 rows=100 loops=1)"); +sql insert into tb1 values ('2022-04-26 15:15:00', 1, "a"); +sql insert into tb1 values ('2022-04-26 15:15:01', 2, "b"); +sql insert into tb1 values ('2022-04-26 15:15:02', 3, "c"); +sql insert into tb1 values ('2022-04-26 15:15:03', 4, "d"); +sql insert into tb1 values ('2022-04-26 15:15:04', 5, "e"); +sql insert into tb1 values ('2022-04-26 15:15:05', 6, "f"); +sql insert into tb1 values ('2022-04-26 15:15:06', null, null); +sql insert into tb1 values ('2022-04-26 15:15:07', null, "g"); +sql insert into tb1 values ('2022-04-26 15:15:08', 7, null); -sql create table tb2 using st1 tags(2); -sql insert into tb2 values (now, 2, "Seq Scan on tenk2 t2 (cost=0.00..445.00 rows=10000 width=244) (actual time=0.007..2.583 rows=10000 loops=1)"); -sql create table tb3 using st1 tags(3); -sql insert into tb3 values (now, 3, "Hash (cost=229.20..229.20 rows=101 width=244) (actual time=0.659..0.659 rows=100 loops=1)"); -sql create table tb4 using st1 tags(4); -sql insert into tb4 values (now, 4, "Bitmap Heap Scan on tenk1 t1 (cost=5.07..229.20 rows=101 width=244) (actual time=0.080..0.526 rows=100 loops=1)"); +sql select * from tb1 where f1 in (1,2,3); +if $rows != 3 then + return -1 +endi +sql select * from tb1 where f1 <>3; +if $rows != 6 then + return -1 +endi +sql select * from tb1 where f1 in (1,2,3,null); +if $rows != 3 then + return -1 +endi +sql select * from tb1 where f1 not in (1,2,3,null); +if $rows != 0 then + return -1 +endi +sql select * from tb1 where f1 in (null); +if $rows != 0 then + return -1 +endi +sql select * from tb1 where f1 = null; +if $rows != 0 then + return -1 +endi +sql select * from tb1 where f1 <> null; +if $rows != 0 then + return -1 +endi +sql select * from tb1 where f1 + 3 <> null; +if $rows != 0 then + return -1 +endi +sql select * from tb1 where f1+1 <>3+null; +if $rows != 0 then + return -1 +endi +sql select * from tb1 where f1+1*null <>3+null; +if $rows != 0 then + return -1 +endi +sql select * from tb1 where null; +if $rows != 0 then + return -1 +endi +sql select * from tb1 where null = null; +if $rows != 0 then + return -1 +endi +sql select * from tb1 where null <> null; +if $rows != 0 then + return -1 +endi -sql create table tb1 using st2 tags(1); -sql insert into tb1 values (now, 1, "Hash Join (cost=230.47..713.98 rows=101 width=488) (actual time=0.711..7.427 rows=100 loops=1)"); - -sql create table tb2 using st2 tags(2); -sql insert into tb2 values (now, 2, "Seq Scan on tenk2 t2 (cost=0.00..445.00 rows=10000 width=244) (actual time=0.007..2.583 rows=10000 loops=1)"); -sql create table tb3 using st2 tags(3); -sql insert into tb3 values (now, 3, "Hash (cost=229.20..229.20 rows=101 width=244) (actual time=0.659..0.659 rows=100 loops=1)"); -sql create table tb4 using st2 tags(4); -sql insert into tb4 values (now, 4, "Bitmap Heap Scan on tenk1 t1 (cost=5.07..229.20 rows=101 width=244) (actual time=0.080..0.526 rows=100 loops=1)"); +#TODO: ENABLE IT +#sql select * from tb1 where not (null <> null); +#if $rows != 9 then +# return -1 +#endi -print ======== step2 -sql explain select * from st1 where -2; -sql explain select ts from tb1; -sql explain select * from st1; -sql explain select * from st1 order by ts; -sql explain select * from information_schema.user_stables; -sql explain select count(*),sum(f1) from tb1; -sql explain select count(*),sum(f1) from st1; -sql explain select count(*),sum(f1) from st1 group by f1; -#sql explain select count(f1) from tb1 interval(10s, 2s) sliding(3s) fill(prev); -sql explain select min(f1) from st1 interval(1m, 2a) sliding(30s); - -print ======== step3 -sql explain verbose true select * from st1 where -2; -sql explain verbose true select ts from tb1 where f1 > 0; -sql explain verbose true select * from st1 where f1 > 0 and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00'; -sql explain verbose true select * from information_schema.user_stables where db_name='db2'; -sql explain verbose true select count(*),sum(f1) from st1 where f1 > 0 and ts > '2021-10-31 00:00:00' group by f1 having sum(f1) > 0; - -print ======== step4 -sql explain analyze select ts from st1 where -2; -sql explain analyze select ts from tb1; -sql explain analyze select ts from st1; -sql explain analyze select ts from st1; -sql explain analyze select ts from st1 order by ts; -sql explain analyze select * from information_schema.user_stables; -sql explain analyze select count(*),sum(f1) from tb1; -sql explain analyze select count(*),sum(f1) from st1; -sql explain analyze select count(*),sum(f1) from st1 group by f1; -#sql explain analyze select count(f1) from tb1 interval(10s, 2s) sliding(3s) fill(prev); -sql explain analyze select min(f1) from st1 interval(3m, 2a) sliding(1m); - -print ======== step5 -sql explain analyze verbose true select ts from st1 where -2; -sql explain analyze verbose true select ts from tb1; -sql explain analyze verbose true select ts from st1; -sql explain analyze verbose true select ts from st1; -sql explain analyze verbose true select ts from st1 order by ts; -sql explain analyze verbose true select * from information_schema.user_stables; -sql explain analyze verbose true select count(*),sum(f1) from tb1; -sql explain analyze verbose true select count(*),sum(f1) from st1; -sql explain analyze verbose true select count(*),sum(f1) from st1 group by f1; -#sql explain analyze verbose true select count(f1) from tb1 interval(10s, 2s) sliding(3s) fill(prev); -sql explain analyze verbose true select ts from tb1 where f1 > 0; -sql explain analyze verbose true select f1 from st1 where f1 > 0 and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00'; -sql explain analyze verbose true select * from information_schema.user_stables where db_name='db2'; -sql explain analyze verbose true select count(*),sum(f1) from st1 where f1 > 0 and ts > '2021-10-31 00:00:00' group by f1 having sum(f1) > 0; -sql explain analyze verbose true select min(f1) from st1 interval(3m, 2a) sliding(1m); -sql explain analyze verbose true select * from (select min(f1),count(*) a from st1 where f1 > 0) where a < 0; - -#not pass case -#sql explain verbose true select count(*),sum(f1) as aa from tb1 where (f1 > 0 or f1 < -1) and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00' order by aa; -#sql explain verbose true select * from st1 where (f1 > 0 or f1 < -1) and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00' order by ts; -#sql explain verbose true select count(*),sum(f1) from st1 where (f1 > 0 or f1 < -1) and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00' order by ts; -#sql explain verbose true select count(f1) from tb1 where (f1 > 0 or f1 < -1) and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00' interval(10s, 2s) sliding(3s) order by ts; -#sql explain verbose true select min(f1) from st1 where (f1 > 0 or f1 < -1) and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00' interval(1m, 2a) sliding(30s) fill(linear) order by ts; -#sql explain select max(f1) from tb1 SESSION(ts, 1s); -#sql explain select max(f1) from st1 SESSION(ts, 1s); -#sql explain select * from tb1, tb2 where tb1.ts=tb2.ts; -#sql explain select * from st1, st2 where tb1.ts=tb2.ts; -#sql explain analyze verbose true select sum(a+b) from (select _rowts, min(f1) b,count(*) a from st1 where f1 > 0 interval(1a)) where a < 0 interval(1s); +#TODO: MOVE IT TO NORMAL CASE +sql_error select * from tb1 where not (null); system sh/exec.sh -n dnode1 -s stop -x SIGINT