From 70980e84b51f09ee8564956df05c5f5ba829d397 Mon Sep 17 00:00:00 2001 From: cpwu Date: Thu, 7 Apr 2022 10:48:20 +0800 Subject: [PATCH 01/16] add complex sim case --- tests/script/tsim/query/complex_select.sim | 426 +++++++++++++++++++++ 1 file changed, 426 insertions(+) create mode 100644 tests/script/tsim/query/complex_select.sim diff --git a/tests/script/tsim/query/complex_select.sim b/tests/script/tsim/query/complex_select.sim new file mode 100644 index 0000000000..1cb58237c4 --- /dev/null +++ b/tests/script/tsim/query/complex_select.sim @@ -0,0 +1,426 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +print =============== create database +sql create database db +sql show databases +if $rows != 2 then + return -1 +endi + +sql use db + +print =============== create super table and child table +sql create table stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int) +sql show stables +print $rows $data00 $data01 $data02 +if $rows != 1 then + return -1 +endi + +sql create table ct1 using stb1 tags ( 1 ) +sql create table ct2 using stb1 tags ( 2 ) +sql create table ct3 using stb1 tags ( 3 ) +sql create table ct4 using stb1 tags ( 4 ) +sql show tables +print $rows $data00 $data10 $data20 +if $rows != 4 then + return -1 +endi + +print =============== insert data into child table ct1 (s) +sql insert into ct1 values ( '2022-01-01 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now ) +sql insert into ct1 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now ) +sql insert into ct1 values ( '2022-01-01 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now ) +sql insert into ct1 values ( '2022-01-01 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now ) +sql insert into ct1 values ( '2022-01-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now ) +sql insert into ct1 values ( '2022-01-01 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now ) +sql insert into ct1 values ( '2022-01-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now ) +sql insert into ct1 values ( '2022-01-01 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now ) + +print =============== insert data into child table ct2 (d) +sql insert into ct2 values ( '2022-01-01 01:00:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now ) +sql insert into ct2 values ( '2022-01-01 10:00:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now ) +sql insert into ct2 values ( '2022-01-01 20:00:01.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now ) +sql insert into ct2 values ( '2022-01-02 10:00:01.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now ) +sql insert into ct2 values ( '2022-01-02 20:00:01.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now ) +sql insert into ct2 values ( '2022-01-03 10:00:01.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now ) +sql insert into ct2 values ( '2022-01-03 20:00:01.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now ) + +print =============== insert data into child table ct3 (n) +sql insert into ct3 values ( '2021-12-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) +sql insert into ct3 values ( '2021-12-31 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now ) +sql insert into ct3 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now ) +sql insert into ct3 values ( '2022-01-07 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now ) +sql insert into ct3 values ( '2022-01-31 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now ) +sql insert into ct3 values ( '2022-02-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now ) +sql insert into ct3 values ( '2022-02-28 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now ) +sql insert into ct3 values ( '2022-03-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct3 values ( '2022-03-08 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) + +print =============== insert data into child table ct4 (y) +sql insert into ct4 values ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now ) +sql insert into ct4 values ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now ) +sql insert into ct4 values ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now ) +sql insert into ct4 values ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now ) +sql insert into ct4 values ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now ) +sql insert into ct4 values ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now ) +sql insert into ct4 values ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct4 values ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) +sql insert into ct4 values ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) + +print ================ start query ====================== +print ================ query 1 limit/offset +sql select * from ct1 limit 1 +print ====> sql : select * from ct1 limit 1 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi + +sql select * from ct1 limit 9 +print ====> sql : select * from ct1 limit 9 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct1 limit 1 offset 2 +print ====> sql : select * from ct1 limit 1 offset 2 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi +if $data01 != 2 then + return -1 +endi + +sql select * from ct1 limit 2 offset 1 +print ====> sql : select * from ct1 limit 2 offset 7 +print ====> rows: $rows +if $rows != 2 then + return -1 +endi +if $data01 != 8 then + return -1 +endi + +sql select * from ct1 limit 2 offset 7 +print ====> sql : select * from ct1 limit 2 offset 7 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data11 != 3 then + return -1 +endi + +sql select * from ct1 limit 2 offset 10 +print ====> sql : select * from ct1 limit 2 offset 7 +print ====> rows: $rows +if $rows != 0 then + return -1 +endi + +sql select c1 from stb1 limit 1 +print ====> sql : select c1 from stb1 limit 1 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 1 then + return -1 +endi + +sql select c1 from stb1 limit 50 +print ====> sql : select c1 from stb1 limit 50 +print ====> rows: $rows +if $rows != 33 then + return -1 +endi + +sql select c1 from stb1 limit 1 offset 2 +print ====> sql : select c1 from stb1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select c1 from stb1 limit 2 offset 1 +print ====> sql : select c1 from stb1 limit 2 offset 1 +print ====> rows: $rows +if $rows != 2 then + return -1 +endi + +sql select c1 from stb1 limit 2 offset 32 +print ====> sql : select c1 from stb1 limit 2 offset 32 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select c1 from stb1 limit 2 offset 40 +print ====> sql : select c1 from stb1 limit 2 offset 40 +print ====> rows: $rows +if $rows != 0 then + return -1 +endi + +print ================ query 2 where condition +sql select * from ct3 where c1 < 5 +print ====> sql : select * from ct3 where c1 < 5 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 4 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select * from ct3 where c1 > 5 and c1 <= 6 +print ====> sql : select * from ct3 where c1 > 5 and c1 <= 6 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi +if $data01 != 6 then + return -1 +endi + +sql select * from ct3 where c1 >= 5 or c1 != 4 or c1 <> 3 or c1 = 2 +print ====> sql : select * from ct3 where c1 > 5 and c1 <= 6 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 8 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select * from ct3 where c1 >= 5 and c1 is not NULL +print ====> sql : select * from ct3 where c1 >= 5 and c1 is not NULL +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 4 then + return -1 +endi +if $data01 != 5 then + return -1 +endi + +sql_error select ts from ct3 where ts != 0 +sql select * from ct3 where ts <> 0 +print ====> sql : select * from ct3 where ts <> 0 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct3 where c1 between 1 and 3 +print ====> sql : select * from ct3 where c1 between 1 and 3 +print ====> rows: $rows +if $rows != 3 then + return -1 +endi + +sql_error select * from ct3 where c7 between false and true + +sql select * from ct3 where c1 in (1,2,3) +print ====> sql : select * from ct3 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 3 then + return -1 +endi + +sql select * from ct3 where c1 in (‘true','false') +print ====> sql : select * from ct3 where c1 in (‘true','false') +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct3 where c9 like "_char_" +print ====> sql : select * from ct3 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct3 where c8 like "bi%" +print ====> sql : select * from ct3 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select c1 from stb1 where c1 < 5 +print ====> sql : select c1 from stb1 where c1 < 5 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 16 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select c1 from stb1 where stb1 > 5 and c1 <= 6 +print ====> sql : select c1 from stb1 where c1 > 5 and c1 <= 6 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 4 then + return -1 +endi +if $data01 != 6 then + return -1 +endi + +sql select c1 from stb1 where c1 >= 5 or c1 != 4 or c1 <> 3 or c1 = 2 +print ====> sql : sselect c1 from stb1 where c1 >= 5 or c1 != 4 or c1 <> 3 or c1 = 2 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 32 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select c1 from stb1 where c1 >= 5 and c1 is not NULL +print ====> sql : select c1 from stb1 where c1 >= 5 and c1 is not NULL +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 17 then + return -1 +endi +if $data01 != 5 then + return -1 +endi + +sql_error select ts from stb1 where ts != 0 +sql select c1 from stb1 where ts <> 0 +print ====> sql : select c1 from stb1 where ts <> 0 +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + +sql select c1 from stb1 where c1 between 1 and 3 +print ====> sql : select c1 from stb1 where c1 between 1 and 3 +print ====> rows: $rows +if $rows != 12 then + return -1 +endi + +sql_error select c1 from stb1 where c7 between false and true + +sql select c1 from stb1 where c1 in (1,2,3) +print ====> sql : select c1 from stb1 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 12 then + return -1 +endi + +sql select c1 from stb1 where c1 in (‘true','false') +print ====> sql : select c1 from stb1 where c1 in (‘true','false') +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + +sql select c1 from stb1 where c9 like "_char_" +print ====> sql : select c1 from stb1 where c9 like "_char_" +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + +sql select c1 from stb1 where c8 like "bi%" +print ====> sql : select c1 from stb1 where c8 like "bi%" +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + + +## TODO : group by +print ================ query 3 group by filter + + + +## TODO : complex +print ================ query 4 scalar function + where + group by + limit/offset + + + + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 33 then + return -1 +endi + +#================================================= +print =============== stop and restart taosd +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready_0: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready_0 +endi + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 33 then + return -1 +endi + + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file From 30def824b64e961cc08858e3ed65f3f0ebabc5a7 Mon Sep 17 00:00:00 2001 From: cpwu Date: Thu, 7 Apr 2022 16:09:38 +0800 Subject: [PATCH 02/16] add group by --- tests/script/tsim/query/complex_select.sim | 123 ++++++++++++++++----- 1 file changed, 94 insertions(+), 29 deletions(-) diff --git a/tests/script/tsim/query/complex_select.sim b/tests/script/tsim/query/complex_select.sim index 1cb58237c4..4a710c4b58 100644 --- a/tests/script/tsim/query/complex_select.sim +++ b/tests/script/tsim/query/complex_select.sim @@ -50,42 +50,42 @@ if $rows != 4 then endi print =============== insert data into child table ct1 (s) -sql insert into ct1 values ( '2022-01-01 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now ) -sql insert into ct1 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now ) -sql insert into ct1 values ( '2022-01-01 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now ) -sql insert into ct1 values ( '2022-01-01 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now ) -sql insert into ct1 values ( '2022-01-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now ) -sql insert into ct1 values ( '2022-01-01 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now ) -sql insert into ct1 values ( '2022-01-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now ) -sql insert into ct1 values ( '2022-01-01 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now ) +sql insert into ct1 values ( '2022-01-01 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct1 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct1 values ( '2022-01-01 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct1 values ( '2022-01-01 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct1 values ( '2022-01-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct1 values ( '2022-01-01 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct1 values ( '2022-01-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+7a ) +sql insert into ct1 values ( '2022-01-01 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+8a ) print =============== insert data into child table ct2 (d) -sql insert into ct2 values ( '2022-01-01 01:00:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now ) -sql insert into ct2 values ( '2022-01-01 10:00:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now ) -sql insert into ct2 values ( '2022-01-01 20:00:01.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now ) -sql insert into ct2 values ( '2022-01-02 10:00:01.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now ) -sql insert into ct2 values ( '2022-01-02 20:00:01.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now ) -sql insert into ct2 values ( '2022-01-03 10:00:01.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now ) -sql insert into ct2 values ( '2022-01-03 20:00:01.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now ) +sql insert into ct2 values ( '2022-01-01 01:00:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct2 values ( '2022-01-01 10:00:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct2 values ( '2022-01-01 20:00:01.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct2 values ( '2022-01-02 10:00:01.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct2 values ( '2022-01-02 20:00:01.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct2 values ( '2022-01-03 10:00:01.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+6a ) +sql insert into ct2 values ( '2022-01-03 20:00:01.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+7a ) print =============== insert data into child table ct3 (n) sql insert into ct3 values ( '2021-12-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) -sql insert into ct3 values ( '2021-12-31 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now ) -sql insert into ct3 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now ) -sql insert into ct3 values ( '2022-01-07 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now ) -sql insert into ct3 values ( '2022-01-31 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now ) -sql insert into ct3 values ( '2022-02-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now ) -sql insert into ct3 values ( '2022-02-28 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now ) +sql insert into ct3 values ( '2021-12-31 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct3 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct3 values ( '2022-01-07 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct3 values ( '2022-01-31 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct3 values ( '2022-02-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct3 values ( '2022-02-28 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) sql insert into ct3 values ( '2022-03-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) sql insert into ct3 values ( '2022-03-08 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) print =============== insert data into child table ct4 (y) -sql insert into ct4 values ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now ) -sql insert into ct4 values ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now ) -sql insert into ct4 values ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now ) -sql insert into ct4 values ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now ) -sql insert into ct4 values ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now ) -sql insert into ct4 values ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now ) +sql insert into ct4 values ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct4 values ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct4 values ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct4 values ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct4 values ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct4 values ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) sql insert into ct4 values ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) sql insert into ct4 values ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) sql insert into ct4 values ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) @@ -372,12 +372,77 @@ if $rows != 32 then endi -## TODO : group by print ================ query 3 group by filter +sql select count(*) from ct3 group by c1 +print ====> sql : select count(*) from ct3 group by c1 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi +sql select count(*) from ct3 group by c2 +print ====> sql : select count(*) from ct3 group by c2 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi +sql select count(*) from ct3 group by c3 +print ====> sql : select count(*) from ct3 group by c3 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c4 +print ====> sql : select count(*) from ct3 group by c4 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c5 +print ====> sql : select count(*) from ct3 group by c5 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c6 +print ====> sql : select count(*) from ct3 group by c6 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c7 +print ====> sql : select count(*) from ct3 group by c7 +print ====> rows: $rows +if $rows != 2 then + return -1 +endi + +sql select count(*) from ct3 group by c8 +print ====> sql : select count(*) from ct3 group by c8 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c9 +print ====> sql : select count(*) from ct3 group by c9 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c10 +print ====> sql : select count(*) from ct3 group by c10 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi -## TODO : complex print ================ query 4 scalar function + where + group by + limit/offset From c7dd60ff85b566437ccc6fccd218d1543ce657b7 Mon Sep 17 00:00:00 2001 From: cpwu Date: Sat, 9 Apr 2022 14:07:27 +0800 Subject: [PATCH 03/16] fix the case --- tests/script/tsim/query/complex_select.sim | 94 ++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/tests/script/tsim/query/complex_select.sim b/tests/script/tsim/query/complex_select.sim index 4a710c4b58..1696d22da7 100644 --- a/tests/script/tsim/query/complex_select.sim +++ b/tests/script/tsim/query/complex_select.sim @@ -444,9 +444,103 @@ if $rows != 8 then endi print ================ query 4 scalar function + where + group by + limit/offset +sql select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi +sql select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi +sql select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi +sql select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi print =================== count all rows sql select count(c1) from stb1 From 1df069814a28903da29596789f7363dd25f46b49 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sun, 10 Apr 2022 15:35:09 +0800 Subject: [PATCH 04/16] feat[query]:add time slice operator. --- source/client/test/clientTests.cpp | 5 +- source/libs/executor/inc/executorimpl.h | 10 +++- source/libs/executor/src/executorimpl.c | 70 ++++++++++++------------- 3 files changed, 45 insertions(+), 40 deletions(-) diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 772f9049e5..fd2abbb559 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -400,7 +400,7 @@ TEST(testCase, show_vgroup_Test) { taos_free_result(pRes); taos_close(pConn); } -#endif + TEST(testCase, create_multiple_tables) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); @@ -653,6 +653,7 @@ TEST(testCase, projection_query_stables) { taos_free_result(pRes); taos_close(pConn); } +#endif TEST(testCase, agg_query_tables) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); @@ -661,7 +662,7 @@ TEST(testCase, agg_query_tables) { TAOS_RES* pRes = taos_query(pConn, "use abc1"); taos_free_result(pRes); - pRes = taos_query(pConn, "select count(*) from tu"); + pRes = taos_query(pConn, "select length('abc') from tu"); if (taos_errno(pRes) != 0) { printf("failed to select from table, reason:%s\n", taos_errstr(pRes)); taos_free_result(pRes); diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index 32a5140da2..b1f15482a9 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -609,6 +609,12 @@ typedef struct SSessionAggOperatorInfo { SColumnInfoData timeWindowData; // query time window info for scalar function execution. } SSessionAggOperatorInfo; +typedef struct STimeSliceOperatorInfo { + SOptrBasicInfo binfo; + SInterval interval; + SGroupResInfo groupResInfo; // multiple results build supporter +} STimeSliceOperatorInfo; + typedef struct SStateWindowOperatorInfo { SOptrBasicInfo binfo; SAggSupporter aggSup; @@ -707,6 +713,8 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SExprInf SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SArray* pGroupColList, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo); +SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SExecTaskInfo* pTaskInfo); + #if 0 SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntimeEnv* pRuntimeEnv); SOperatorInfo* createAllTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, @@ -716,7 +724,7 @@ SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntim SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createAllMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput); -SOperatorInfo* createTagScanOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SExprInfo* pExpr, int32_t numOfOutput); +SOperatorInfo* createTagScanOperatorInfo(SReaderHandle* pReaderHandle, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createJoinOperatorInfo(SOperatorInfo** pdownstream, int32_t numOfDownstream, SSchema* pSchema, int32_t numOfOutput); diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index ee5c675989..1bc84f85d7 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -5429,58 +5429,48 @@ static SSDataBlock* doAllIntervalAgg(SOperatorInfo *pOperator, bool* newgroup) { return NULL; } - STableIntervalOperatorInfo* pIntervalInfo = pOperator->info; - - STaskRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; + STimeSliceOperatorInfo* pSliceInfo = pOperator->info; if (pOperator->status == OP_RES_TO_RETURN) { // toSDatablock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pIntervalInfo->pRes); - - if (pIntervalInfo->binfo.pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pRuntimeEnv->groupResInfo)) { + if (pSliceInfo->binfo.pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pSliceInfo->groupResInfo)) { doSetOperatorCompleted(pOperator); } - return pIntervalInfo->binfo.pRes; + return pSliceInfo->binfo.pRes; } - STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; - int32_t order = pQueryAttr->order.order; - STimeWindow win = pQueryAttr->window; - + int32_t order = TSDB_ORDER_ASC; +// STimeWindow win = pQueryAttr->window; SOperatorInfo* downstream = pOperator->pDownstream[0]; while (1) { publishOperatorProfEvent(downstream, QUERY_PROF_BEFORE_OPERATOR_EXEC); SSDataBlock* pBlock = downstream->getNextFn(downstream, newgroup); publishOperatorProfEvent(downstream, QUERY_PROF_AFTER_OPERATOR_EXEC); - if (pBlock == NULL) { break; } // setTagValue(pOperator, pRuntimeEnv->current->pTable, pIntervalInfo->pCtx, pOperator->numOfOutput); - // the pDataBlock are always the same one, no need to call this again - setInputDataBlock(pOperator, pIntervalInfo->binfo.pCtx, pBlock, pQueryAttr->order.order); - hashAllIntervalAgg(pOperator, &pIntervalInfo->binfo.resultRowInfo, pBlock, 0); + setInputDataBlock(pOperator, pSliceInfo->binfo.pCtx, pBlock, order); + hashAllIntervalAgg(pOperator, &pSliceInfo->binfo.resultRowInfo, pBlock, 0); } // restore the value - pQueryAttr->order.order = order; - pQueryAttr->window = win; - pOperator->status = OP_RES_TO_RETURN; - closeAllResultRows(&pIntervalInfo->binfo.resultRowInfo); + closeAllResultRows(&pSliceInfo->binfo.resultRowInfo); setTaskStatus(pOperator->pTaskInfo, TASK_COMPLETED); - finalizeQueryResult(pIntervalInfo->binfo.pCtx, pOperator->numOfOutput); + finalizeQueryResult(pSliceInfo->binfo.pCtx, pOperator->numOfOutput); - initGroupResInfo(&pRuntimeEnv->groupResInfo, &pIntervalInfo->binfo.resultRowInfo); - // toSDatablock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pIntervalInfo->pRes); + initGroupResInfo(&pSliceInfo->groupResInfo, &pSliceInfo->binfo.resultRowInfo); + // toSDatablock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pSliceInfo->pRes); - if (pIntervalInfo->binfo.pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pRuntimeEnv->groupResInfo)) { + if (pSliceInfo->binfo.pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pSliceInfo->groupResInfo)) { pOperator->status = OP_EXEC_DONE; } - return pIntervalInfo->binfo.pRes->info.rows == 0 ? NULL : pIntervalInfo->binfo.pRes; + return pSliceInfo->binfo.pRes->info.rows == 0 ? NULL : pSliceInfo->binfo.pRes; } static SSDataBlock* doSTableIntervalAgg(SOperatorInfo* pOperator, bool* newgroup) { @@ -6238,28 +6228,34 @@ _error: return NULL; } -SOperatorInfo* createAllTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, - SExprInfo* pExpr, int32_t numOfOutput) { - STableIntervalOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STableIntervalOperatorInfo)); +SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SExecTaskInfo* pTaskInfo) { + STimeSliceOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STimeSliceOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); + if (pOperator == NULL || pInfo == NULL) { + goto _error; + } - // pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); - // pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); - SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); - - pOperator->name = "AllTimeIntervalAggOperator"; + pOperator->name = "TimeSliceOperator"; // pOperator->operatorType = OP_AllTimeWindow; pOperator->blockingOptr = true; - pOperator->status = OP_NOT_OPENED; - pOperator->pExpr = pExpr; - pOperator->numOfOutput = numOfOutput; - pOperator->info = pInfo; - pOperator->getNextFn = doAllIntervalAgg; - pOperator->closeFn = destroyBasicOperatorInfo; + pOperator->status = OP_NOT_OPENED; + pOperator->pExpr = pExprInfo; + pOperator->numOfOutput = numOfCols; + pOperator->info = pInfo; + pOperator->pTaskInfo = pTaskInfo; + pOperator->getNextFn = doAllIntervalAgg; + pOperator->closeFn = destroyBasicOperatorInfo; int32_t code = appendDownstream(pOperator, &downstream, 1); return pOperator; + + _error: + taosMemoryFree(pInfo); + taosMemoryFree(pOperator); + pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY; + return NULL; } SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfCols, SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo) { From 14ec5b672a2cd70264c42a4f8cec5511ca7ea76d Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sun, 10 Apr 2022 18:24:16 +0800 Subject: [PATCH 05/16] fix[cluster]: redirect msg when mnode not deployed --- source/dnode/mgmt/main/dndInt.c | 4 ++-- source/dnode/mgmt/main/dndTransport.c | 16 +++++++++++----- tests/script/tsim/mnode/basic1.sim | 1 - 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/source/dnode/mgmt/main/dndInt.c b/source/dnode/mgmt/main/dndInt.c index 7b207fd496..d406b0c02e 100644 --- a/source/dnode/mgmt/main/dndInt.c +++ b/source/dnode/mgmt/main/dndInt.c @@ -158,7 +158,7 @@ SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, EDndType ntype) { int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1); dTrace("node:%s, is acquired, refCount:%d", pWrapper->name, refCount); } else { - terrno = TSDB_CODE_NODE_REDIRECT; + terrno = TSDB_CODE_NODE_NOT_DEPLOYED; pRetWrapper = NULL; } taosRUnLockLatch(&pWrapper->latch); @@ -174,7 +174,7 @@ int32_t dndMarkWrapper(SMgmtWrapper *pWrapper) { int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1); dTrace("node:%s, is marked, refCount:%d", pWrapper->name, refCount); } else { - terrno = TSDB_CODE_NODE_REDIRECT; + terrno = TSDB_CODE_NODE_NOT_DEPLOYED; code = -1; } taosRUnLockLatch(&pWrapper->latch); diff --git a/source/dnode/mgmt/main/dndTransport.c b/source/dnode/mgmt/main/dndTransport.c index 75722c8f9c..b639b79935 100644 --- a/source/dnode/mgmt/main/dndTransport.c +++ b/source/dnode/mgmt/main/dndTransport.c @@ -53,8 +53,9 @@ static void dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpS int32_t code = -1; SNodeMsg *pMsg = NULL; NodeMsgFp msgFp = NULL; + uint16_t msgType = pRpc->msgType; - if (pEpSet && pEpSet->numOfEps > 0 && pRpc->msgType == TDMT_MND_STATUS_RSP) { + if (pEpSet && pEpSet->numOfEps > 0 && msgType == TDMT_MND_STATUS_RSP) { dndUpdateMnodeEpSet(pWrapper->pDnode, pEpSet); } @@ -84,9 +85,15 @@ _OVER: } } else { dError("msg:%p, failed to process since 0x%04x:%s", pMsg, code & 0XFFFF, terrstr()); - if (pRpc->msgType & 1U) { + if (msgType & 1U) { if (terrno != 0) code = terrno; - SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = terrno}; + if (code == TSDB_CODE_NODE_NOT_DEPLOYED || code == TSDB_CODE_NODE_OFFLINE) { + if (msgType > TDMT_MND_MSG && msgType < TDMT_VND_MSG) { + code = TSDB_CODE_NODE_REDIRECT; + } + } + + SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = code}; tmsgSendRsp(&rsp); } dTrace("msg:%p, is freed", pMsg); @@ -348,8 +355,7 @@ static int32_t dndSendRpcReq(STransMgmt *pMgmt, const SEpSet *pEpSet, SRpcMsg *p } static void dndSendRpcRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) { - if (pRsp->code == TSDB_CODE_APP_NOT_READY || pRsp->code == TSDB_CODE_NODE_REDIRECT || - pRsp->code == TSDB_CODE_NODE_OFFLINE) { + if (pRsp->code == TSDB_CODE_NODE_REDIRECT) { dmSendRedirectRsp(pWrapper->pMgmt, pRsp); } else { rpcSendResponse(pRsp); diff --git a/tests/script/tsim/mnode/basic1.sim b/tests/script/tsim/mnode/basic1.sim index 74ec44328d..e3d27d0c13 100644 --- a/tests/script/tsim/mnode/basic1.sim +++ b/tests/script/tsim/mnode/basic1.sim @@ -75,7 +75,6 @@ if $data02 != master then return -1 endi -return print =============== create drop mnode 1 sql_error create mnode on dnode 1 sql_error drop mnode on dnode 1 From c4ee7142b9dd9cdc8518e65f9a12a52311d172af Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sun, 10 Apr 2022 22:34:18 +0800 Subject: [PATCH 06/16] fix[cluster]: manage mnode in multi-process mode --- source/dnode/mgmt/main/dndTransport.c | 3 ++- source/dnode/mgmt/mm/mmHandle.c | 2 +- source/dnode/mgmt/mm/mmInt.c | 3 +++ source/dnode/mgmt/test/mnode/dmnode.cpp | 2 +- tests/script/jenkins/basic.txt | 10 ++++++++-- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/source/dnode/mgmt/main/dndTransport.c b/source/dnode/mgmt/main/dndTransport.c index b639b79935..bcebd521b6 100644 --- a/source/dnode/mgmt/main/dndTransport.c +++ b/source/dnode/mgmt/main/dndTransport.c @@ -448,7 +448,8 @@ static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int16_t static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen, ProcFuncType ftype) { pMsg->pCont = pCont; - dTrace("msg:%p, get from parent queue, ftype:%d handle:%p, app:%p", pMsg, ftype, pMsg->handle, pMsg->ahandle); + dTrace("msg:%p, get from parent queue, ftype:%d handle:%p code:0x%04x mtype:%d, app:%p", pMsg, ftype, pMsg->handle, + pMsg->code & 0xFFFF, pMsg->msgType, pMsg->ahandle); switch (ftype) { case PROC_REGIST: diff --git a/source/dnode/mgmt/mm/mmHandle.c b/source/dnode/mgmt/mm/mmHandle.c index eeae9da8b7..6ad0b8c0ed 100644 --- a/source/dnode/mgmt/mm/mmHandle.c +++ b/source/dnode/mgmt/mm/mmHandle.c @@ -96,7 +96,7 @@ int32_t mmProcessAlterReq(SMnodeMgmt *pMgmt, SNodeMsg *pMsg) { if (alterReq.dnodeId != pDnode->dnodeId) { terrno = TSDB_CODE_INVALID_OPTION; - dError("failed to alter mnode since %s", terrstr()); + dError("failed to alter mnode since %s, dnodeId:%d input:%d", terrstr(), pDnode->dnodeId, alterReq.dnodeId); return -1; } else { return mmAlter(pMgmt, &alterReq); diff --git a/source/dnode/mgmt/mm/mmInt.c b/source/dnode/mgmt/mm/mmInt.c index 64daf09bf9..49886621ec 100644 --- a/source/dnode/mgmt/mm/mmInt.c +++ b/source/dnode/mgmt/mm/mmInt.c @@ -112,6 +112,9 @@ static int32_t mmOpenImp(SMnodeMgmt *pMgmt, SDCreateMnodeReq *pReq) { if (!deployed) { dInfo("mnode start to deploy"); + if (pMgmt->pWrapper->procType == PROC_CHILD) { + pMgmt->pDnode->dnodeId = 1; + } mmBuildOptionForDeploy(pMgmt, &option); } else { dInfo("mnode start to open"); diff --git a/source/dnode/mgmt/test/mnode/dmnode.cpp b/source/dnode/mgmt/test/mnode/dmnode.cpp index 348eb50c8f..e92e51fa39 100644 --- a/source/dnode/mgmt/test/mnode/dmnode.cpp +++ b/source/dnode/mgmt/test/mnode/dmnode.cpp @@ -188,7 +188,7 @@ TEST_F(DndTestMnode, 03_Drop_Mnode) { SRpcMsg* pRsp = test.SendReq(TDMT_DND_ALTER_MNODE, pReq, contLen); ASSERT_NE(pRsp, nullptr); - ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_REDIRECT); + ASSERT_EQ(pRsp->code, TSDB_CODE_NODE_NOT_DEPLOYED); } { diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 2d18167337..761a8921d5 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -43,7 +43,7 @@ ./test.sh -f tsim/bnode/basic1.sim # ---- mnode -./test.sh -f tsim/bnode/basic1.sim +./test.sh -f tsim/mnode/basic1.sim # ---- show ./test.sh -f tsim/show/basic.sim @@ -69,7 +69,13 @@ # --- for multi process mode ./test.sh -f tsim/user/basic1.sim -m -./test.sh -f tsim/stable/vnode3.sim -m +./test.sh -f tsim/db/basic3.sim -m +./test.sh -f tsim/insert/backquote.sim +./test.sh -f tsim/parser/fourArithmetic-basic.sim -m +./test.sh -f tsim/query/interval-offset.sim -m ./test.sh -f tsim/tmq/basic.sim -m +./test.sh -f tsim/stable/vnode3.sim -m +./test.sh -f tsim/qnode/basic1.sim -m +./test.sh -f tsim/mnode/basic1.sim -m #======================b1-end=============== From ca5d5ca7bb6f4ee3ebce6d67beab74dfc81e9d0a Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 11 Apr 2022 10:44:37 +0800 Subject: [PATCH 07/16] test[query]:update the script. --- source/libs/executor/inc/executorimpl.h | 3 - tests/script/tsim/query/session.sim | 114 ++++++++++++------------ 2 files changed, 57 insertions(+), 60 deletions(-) diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index b1f15482a9..9a75830ec4 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -717,9 +717,6 @@ SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SExprInfo* #if 0 SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntimeEnv* pRuntimeEnv); -SOperatorInfo* createAllTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, - SExprInfo* pExpr, int32_t numOfOutput); - SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createAllMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, diff --git a/tests/script/tsim/query/session.sim b/tests/script/tsim/query/session.sim index c1d3437e4a..3a57581668 100644 --- a/tests/script/tsim/query/session.sim +++ b/tests/script/tsim/query/session.sim @@ -98,15 +98,15 @@ if $data01 != 2 then return -1 endi - -print ====> select count(*) from (select * from dev_001) session(ts,5a) -sql select _wstartts, count(*) from (select * from dev_001) session(ts,5a) -if $rows != 15 then - return -1 -endi -if $data01 != 2 then - return -1 -endi +# +#print ====> select count(*) from (select * from dev_001) session(ts,5a) +#sql select _wstartts, count(*) from (select * from dev_001) session(ts,5a) +#if $rows != 15 then +# return -1 +#endi +#if $data01 != 2 then +# return -1 +#endi print ====> select count(*) from dev_001 session(ts,1s) sql select _wstartts, count(*) from dev_001 session(ts,1s) @@ -117,14 +117,14 @@ if $data01 != 5 then return -1 endi -print ====> select count(*) from (select * from dev_001) session(ts,1s) -sql select _wstartts, count(*) from (select * from dev_001) session(ts,1s) -if $rows != 12 then - return -1 -endi -if $data01 != 5 then - return -1 -endi +#print ====> select count(*) from (select * from dev_001) session(ts,1s) +#sql select _wstartts, count(*) from (select * from dev_001) session(ts,1s) +#if $rows != 12 then +# return -1 +#endi +#if $data01 != 5 then +# return -1 +#endi print ====> select count(*) from dev_001 session(ts,1000a) sql select _wstartts, count(*) from dev_001 session(ts,1000a) @@ -135,14 +135,14 @@ if $data01 != 5 then return -1 endi -print ====> select count(*) from (select * from dev_001) session(ts,1000a) -sql select _wstartts, count(*) from (select * from dev_001) session(ts,1000a) -if $rows != 12 then - return -1 -endi -if $data01 != 5 then - return -1 -endi +#print ====> select count(*) from (select * from dev_001) session(ts,1000a) +#sql select _wstartts, count(*) from (select * from dev_001) session(ts,1000a) +#if $rows != 12 then +# return -1 +#endi +#if $data01 != 5 then +# return -1 +#endi print ====> select count(*) from dev_001 session(ts,1m) sql select _wstartts, count(*) from dev_001 session(ts,1m) @@ -153,14 +153,14 @@ if $data01 != 8 then return -1 endi -print ====> select count(*) from (select * from dev_001) session(ts,1m) -sql select _wstartts, count(*) from (select * from dev_001) session(ts,1m) -if $rows != 9 then - return -1 -endi -if $data01 != 8 then - return -1 -endi +#print ====> select count(*) from (select * from dev_001) session(ts,1m) +#sql select _wstartts, count(*) from (select * from dev_001) session(ts,1m) +#if $rows != 9 then +# return -1 +#endi +#if $data01 != 8 then +# return -1 +#endi print ====> select count(*) from dev_001 session(ts,1h) sql select _wstartts, count(*) from dev_001 session(ts,1h) @@ -171,14 +171,14 @@ if $data01 != 11 then return -1 endi -print ====> select count(*) from (select * from dev_001) session(ts,1h) -sql select _wstartts, count(*) from (select * from dev_001) session(ts,1h) -if $rows != 6 then - return -1 -endi -if $data01 != 11 then - return -1 -endi +#print ====> select count(*) from (select * from dev_001) session(ts,1h) +#sql select _wstartts, count(*) from (select * from dev_001) session(ts,1h) +#if $rows != 6 then +# return -1 +#endi +#if $data01 != 11 then +# return -1 +#endi print ====> select count(*) from dev_001 session(ts,1d) sql select _wstartts, count(*) from dev_001 session(ts,1d) @@ -189,14 +189,14 @@ if $data01 != 13 then return -1 endi -print ====> select count(*) from (select * from dev_001) session(ts,1d) -sql select _wstartts, count(*) from (select * from dev_001) session(ts,1d) -if $rows != 4 then - return -1 -endi -if $data01 != 13 then - return -1 -endi +#print ====> select count(*) from (select * from dev_001) session(ts,1d) +#sql select _wstartts, count(*) from (select * from dev_001) session(ts,1d) +#if $rows != 4 then +# return -1 +#endi +#if $data01 != 13 then +# return -1 +#endi print ====> select count(*) from dev_001 session(ts,1w) sql select _wstartts, count(*) from dev_001 session(ts,1w) @@ -207,14 +207,14 @@ if $data01 != 15 then return -1 endi -print ====> select count(*) from (select * from dev_001) session(ts,1w) -sql select _wstartts, count(*) from (select * from dev_001) session(ts,1w) -if $rows != 2 then - return -1 -endi -if $data01 != 15 then - return -1 -endi +#print ====> select count(*) from (select * from dev_001) session(ts,1w) +#sql select _wstartts, count(*) from (select * from dev_001) session(ts,1w) +#if $rows != 2 then +# return -1 +#endi +#if $data01 != 15 then +# return -1 +#endi print ====> leastsquares not supported yet. From 984a508774a155dbfbdfe7703dbd03de34abf280 Mon Sep 17 00:00:00 2001 From: cpwu Date: Mon, 11 Apr 2022 11:51:03 +0800 Subject: [PATCH 08/16] add group by case --- tests/script/tsim/query/complex_group.sim | 278 ++++++++++++++++++++++ 1 file changed, 278 insertions(+) create mode 100644 tests/script/tsim/query/complex_group.sim diff --git a/tests/script/tsim/query/complex_group.sim b/tests/script/tsim/query/complex_group.sim new file mode 100644 index 0000000000..5372f9bd9b --- /dev/null +++ b/tests/script/tsim/query/complex_group.sim @@ -0,0 +1,278 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +print =============== create database +sql create database db +sql show databases +if $rows != 2 then + return -1 +endi + +sql use db + +print =============== create super table and child table +sql create table stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int) +sql show stables +print $rows $data00 $data01 $data02 +if $rows != 1 then + return -1 +endi + +sql create table ct1 using stb1 tags ( 1 ) +sql create table ct2 using stb1 tags ( 2 ) +sql create table ct3 using stb1 tags ( 3 ) +sql create table ct4 using stb1 tags ( 4 ) +sql show tables +print $rows $data00 $data10 $data20 +if $rows != 4 then + return -1 +endi + +print =============== insert data into child table ct1 (s) +sql insert into ct1 values ( '2022-01-01 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct1 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct1 values ( '2022-01-01 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct1 values ( '2022-01-01 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct1 values ( '2022-01-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct1 values ( '2022-01-01 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct1 values ( '2022-01-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+7a ) +sql insert into ct1 values ( '2022-01-01 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+8a ) + +print =============== insert data into child table ct2 (d) +sql insert into ct2 values ( '2022-01-01 01:00:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct2 values ( '2022-01-01 10:00:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct2 values ( '2022-01-01 20:00:01.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct2 values ( '2022-01-02 10:00:01.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct2 values ( '2022-01-02 20:00:01.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct2 values ( '2022-01-03 10:00:01.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+6a ) +sql insert into ct2 values ( '2022-01-03 20:00:01.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+7a ) + +print =============== insert data into child table ct3 (n) +sql insert into ct3 values ( '2021-12-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) +sql insert into ct3 values ( '2021-12-31 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct3 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct3 values ( '2022-01-07 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct3 values ( '2022-01-31 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct3 values ( '2022-02-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct3 values ( '2022-02-28 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct3 values ( '2022-03-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct3 values ( '2022-03-08 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) + +print =============== insert data into child table ct4 (y) +sql insert into ct4 values ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct4 values ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct4 values ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct4 values ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct4 values ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct4 values ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct4 values ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct4 values ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) +sql insert into ct4 values ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) + +print ================ start query ====================== + + +print ================ query 1 group by filter +sql select count(*) from ct3 group by c1 +print ====> sql : select count(*) from ct3 group by c1 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c2 +print ====> sql : select count(*) from ct3 group by c2 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c3 +print ====> sql : select count(*) from ct3 group by c3 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c4 +print ====> sql : select count(*) from ct3 group by c4 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c5 +print ====> sql : select count(*) from ct3 group by c5 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c6 +print ====> sql : select count(*) from ct3 group by c6 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c7 +print ====> sql : select count(*) from ct3 group by c7 +print ====> rows: $rows +if $rows != 2 then + return -1 +endi + +sql select count(*) from ct3 group by c8 +print ====> sql : select count(*) from ct3 group by c8 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c9 +print ====> sql : select count(*) from ct3 group by c9 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c10 +print ====> sql : select count(*) from ct3 group by c10 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 33 then + return -1 +endi + +#================================================= +print =============== stop and restart taosd +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready_0: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready_0 +endi + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 33 then + return -1 +endi + +print ================ query 1 group by filter +sql select count(*) from ct3 group by c1 +print ====> sql : select count(*) from ct3 group by c1 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c2 +print ====> sql : select count(*) from ct3 group by c2 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c3 +print ====> sql : select count(*) from ct3 group by c3 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c4 +print ====> sql : select count(*) from ct3 group by c4 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c5 +print ====> sql : select count(*) from ct3 group by c5 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c6 +print ====> sql : select count(*) from ct3 group by c6 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c7 +print ====> sql : select count(*) from ct3 group by c7 +print ====> rows: $rows +if $rows != 2 then + return -1 +endi + +sql select count(*) from ct3 group by c8 +print ====> sql : select count(*) from ct3 group by c8 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c9 +print ====> sql : select count(*) from ct3 group by c9 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c10 +print ====> sql : select count(*) from ct3 group by c10 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file From f17bead78e1e83624a22ab9e73f81ff153573f1a Mon Sep 17 00:00:00 2001 From: cpwu Date: Mon, 11 Apr 2022 12:48:09 +0800 Subject: [PATCH 09/16] add complex case --- tests/script/tsim/query/complex_group.sim | 198 +++++++ tests/script/tsim/query/complex_limit.sim | 535 +++++++++++++++++ tests/script/tsim/query/complex_where.sim | 691 ++++++++++++++++++++++ 3 files changed, 1424 insertions(+) create mode 100644 tests/script/tsim/query/complex_limit.sim create mode 100644 tests/script/tsim/query/complex_where.sim diff --git a/tests/script/tsim/query/complex_group.sim b/tests/script/tsim/query/complex_group.sim index 5372f9bd9b..3a1ec523fe 100644 --- a/tests/script/tsim/query/complex_group.sim +++ b/tests/script/tsim/query/complex_group.sim @@ -164,6 +164,105 @@ if $rows != 8 then return -1 endi +print ================ query 2 complex with group by +sql select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + print =================== count all rows sql select count(c1) from stb1 @@ -275,4 +374,103 @@ if $rows != 8 then return -1 endi +print ================ query 2 complex with group by +sql select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + #system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/tsim/query/complex_limit.sim b/tests/script/tsim/query/complex_limit.sim new file mode 100644 index 0000000000..ac25135685 --- /dev/null +++ b/tests/script/tsim/query/complex_limit.sim @@ -0,0 +1,535 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +print =============== create database +sql create database db +sql show databases +if $rows != 2 then + return -1 +endi + +sql use db + +print =============== create super table and child table +sql create table stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int) +sql show stables +print $rows $data00 $data01 $data02 +if $rows != 1 then + return -1 +endi + +sql create table ct1 using stb1 tags ( 1 ) +sql create table ct2 using stb1 tags ( 2 ) +sql create table ct3 using stb1 tags ( 3 ) +sql create table ct4 using stb1 tags ( 4 ) +sql show tables +print $rows $data00 $data10 $data20 +if $rows != 4 then + return -1 +endi + +print =============== insert data into child table ct1 (s) +sql insert into ct1 values ( '2022-01-01 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct1 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct1 values ( '2022-01-01 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct1 values ( '2022-01-01 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct1 values ( '2022-01-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct1 values ( '2022-01-01 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct1 values ( '2022-01-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+7a ) +sql insert into ct1 values ( '2022-01-01 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+8a ) + +print =============== insert data into child table ct2 (d) +sql insert into ct2 values ( '2022-01-01 01:00:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct2 values ( '2022-01-01 10:00:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct2 values ( '2022-01-01 20:00:01.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct2 values ( '2022-01-02 10:00:01.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct2 values ( '2022-01-02 20:00:01.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct2 values ( '2022-01-03 10:00:01.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+6a ) +sql insert into ct2 values ( '2022-01-03 20:00:01.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+7a ) + +print =============== insert data into child table ct3 (n) +sql insert into ct3 values ( '2021-12-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) +sql insert into ct3 values ( '2021-12-31 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct3 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct3 values ( '2022-01-07 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct3 values ( '2022-01-31 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct3 values ( '2022-02-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct3 values ( '2022-02-28 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct3 values ( '2022-03-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct3 values ( '2022-03-08 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) + +print =============== insert data into child table ct4 (y) +sql insert into ct4 values ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct4 values ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct4 values ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct4 values ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct4 values ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct4 values ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct4 values ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct4 values ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) +sql insert into ct4 values ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) + +print ================ start query ====================== +print ================ query 1 limit/offset +sql select * from ct1 limit 1 +print ====> sql : select * from ct1 limit 1 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi + +sql select * from ct1 limit 9 +print ====> sql : select * from ct1 limit 9 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct1 limit 1 offset 2 +print ====> sql : select * from ct1 limit 1 offset 2 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi +if $data01 != 2 then + return -1 +endi + +sql select * from ct1 limit 2 offset 1 +print ====> sql : select * from ct1 limit 2 offset 7 +print ====> rows: $rows +if $rows != 2 then + return -1 +endi +if $data01 != 8 then + return -1 +endi + +sql select * from ct1 limit 2 offset 7 +print ====> sql : select * from ct1 limit 2 offset 7 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data11 != 3 then + return -1 +endi + +sql select * from ct1 limit 2 offset 10 +print ====> sql : select * from ct1 limit 2 offset 7 +print ====> rows: $rows +if $rows != 0 then + return -1 +endi + +sql select c1 from stb1 limit 1 +print ====> sql : select c1 from stb1 limit 1 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 1 then + return -1 +endi + +sql select c1 from stb1 limit 50 +print ====> sql : select c1 from stb1 limit 50 +print ====> rows: $rows +if $rows != 33 then + return -1 +endi + +sql select c1 from stb1 limit 1 offset 2 +print ====> sql : select c1 from stb1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select c1 from stb1 limit 2 offset 1 +print ====> sql : select c1 from stb1 limit 2 offset 1 +print ====> rows: $rows +if $rows != 2 then + return -1 +endi + +sql select c1 from stb1 limit 2 offset 32 +print ====> sql : select c1 from stb1 limit 2 offset 32 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select c1 from stb1 limit 2 offset 40 +print ====> sql : select c1 from stb1 limit 2 offset 40 +print ====> rows: $rows +if $rows != 0 then + return -1 +endi + + +print ================ query 2 complex with limit +sql select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 33 then + return -1 +endi + +#================================================= +print =============== stop and restart taosd +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready_0: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready_0 +endi + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 33 then + return -1 +endi + +print ================ query 1 limit/offset +sql select * from ct1 limit 1 +print ====> sql : select * from ct1 limit 1 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi + +sql select * from ct1 limit 9 +print ====> sql : select * from ct1 limit 9 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct1 limit 1 offset 2 +print ====> sql : select * from ct1 limit 1 offset 2 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi +if $data01 != 2 then + return -1 +endi + +sql select * from ct1 limit 2 offset 1 +print ====> sql : select * from ct1 limit 2 offset 7 +print ====> rows: $rows +if $rows != 2 then + return -1 +endi +if $data01 != 8 then + return -1 +endi + +sql select * from ct1 limit 2 offset 7 +print ====> sql : select * from ct1 limit 2 offset 7 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data11 != 3 then + return -1 +endi + +sql select * from ct1 limit 2 offset 10 +print ====> sql : select * from ct1 limit 2 offset 7 +print ====> rows: $rows +if $rows != 0 then + return -1 +endi + +sql select c1 from stb1 limit 1 +print ====> sql : select c1 from stb1 limit 1 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 1 then + return -1 +endi + +sql select c1 from stb1 limit 50 +print ====> sql : select c1 from stb1 limit 50 +print ====> rows: $rows +if $rows != 33 then + return -1 +endi + +sql select c1 from stb1 limit 1 offset 2 +print ====> sql : select c1 from stb1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select c1 from stb1 limit 2 offset 1 +print ====> sql : select c1 from stb1 limit 2 offset 1 +print ====> rows: $rows +if $rows != 2 then + return -1 +endi + +sql select c1 from stb1 limit 2 offset 32 +print ====> sql : select c1 from stb1 limit 2 offset 32 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select c1 from stb1 limit 2 offset 40 +print ====> sql : select c1 from stb1 limit 2 offset 40 +print ====> rows: $rows +if $rows != 0 then + return -1 +endi + + +print ================ query 2 complex with limit +sql select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/tsim/query/complex_where.sim b/tests/script/tsim/query/complex_where.sim new file mode 100644 index 0000000000..7a5de85a3c --- /dev/null +++ b/tests/script/tsim/query/complex_where.sim @@ -0,0 +1,691 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +print =============== create database +sql create database db +sql show databases +if $rows != 2 then + return -1 +endi + +sql use db + +print =============== create super table and child table +sql create table stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int) +sql show stables +print $rows $data00 $data01 $data02 +if $rows != 1 then + return -1 +endi + +sql create table ct1 using stb1 tags ( 1 ) +sql create table ct2 using stb1 tags ( 2 ) +sql create table ct3 using stb1 tags ( 3 ) +sql create table ct4 using stb1 tags ( 4 ) +sql show tables +print $rows $data00 $data10 $data20 +if $rows != 4 then + return -1 +endi + +print =============== insert data into child table ct1 (s) +sql insert into ct1 values ( '2022-01-01 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct1 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct1 values ( '2022-01-01 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct1 values ( '2022-01-01 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct1 values ( '2022-01-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct1 values ( '2022-01-01 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct1 values ( '2022-01-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+7a ) +sql insert into ct1 values ( '2022-01-01 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+8a ) + +print =============== insert data into child table ct2 (d) +sql insert into ct2 values ( '2022-01-01 01:00:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct2 values ( '2022-01-01 10:00:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct2 values ( '2022-01-01 20:00:01.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct2 values ( '2022-01-02 10:00:01.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct2 values ( '2022-01-02 20:00:01.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct2 values ( '2022-01-03 10:00:01.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+6a ) +sql insert into ct2 values ( '2022-01-03 20:00:01.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+7a ) + +print =============== insert data into child table ct3 (n) +sql insert into ct3 values ( '2021-12-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) +sql insert into ct3 values ( '2021-12-31 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct3 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct3 values ( '2022-01-07 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct3 values ( '2022-01-31 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct3 values ( '2022-02-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct3 values ( '2022-02-28 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct3 values ( '2022-03-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct3 values ( '2022-03-08 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) + +print =============== insert data into child table ct4 (y) +sql insert into ct4 values ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct4 values ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct4 values ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct4 values ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct4 values ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct4 values ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct4 values ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct4 values ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) +sql insert into ct4 values ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) + +print ================ start query ====================== +print ================ query 1 where condition +sql select * from ct3 where c1 < 5 +print ====> sql : select * from ct3 where c1 < 5 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 4 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select * from ct3 where c1 > 5 and c1 <= 6 +print ====> sql : select * from ct3 where c1 > 5 and c1 <= 6 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi +if $data01 != 6 then + return -1 +endi + +sql select * from ct3 where c1 >= 5 or c1 != 4 or c1 <> 3 or c1 = 2 +print ====> sql : select * from ct3 where c1 > 5 and c1 <= 6 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 8 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select * from ct3 where c1 >= 5 and c1 is not NULL +print ====> sql : select * from ct3 where c1 >= 5 and c1 is not NULL +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 4 then + return -1 +endi +if $data01 != 5 then + return -1 +endi + +sql_error select ts from ct3 where ts != 0 +sql select * from ct3 where ts <> 0 +print ====> sql : select * from ct3 where ts <> 0 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct3 where c1 between 1 and 3 +print ====> sql : select * from ct3 where c1 between 1 and 3 +print ====> rows: $rows +if $rows != 3 then + return -1 +endi + +sql_error select * from ct3 where c7 between false and true + +sql select * from ct3 where c1 in (1,2,3) +print ====> sql : select * from ct3 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 3 then + return -1 +endi + +sql select * from ct3 where c1 in (‘true','false') +print ====> sql : select * from ct3 where c1 in (‘true','false') +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct3 where c9 like "_char_" +print ====> sql : select * from ct3 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct3 where c8 like "bi%" +print ====> sql : select * from ct3 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select c1 from stb1 where c1 < 5 +print ====> sql : select c1 from stb1 where c1 < 5 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 16 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select c1 from stb1 where stb1 > 5 and c1 <= 6 +print ====> sql : select c1 from stb1 where c1 > 5 and c1 <= 6 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 4 then + return -1 +endi +if $data01 != 6 then + return -1 +endi + +sql select c1 from stb1 where c1 >= 5 or c1 != 4 or c1 <> 3 or c1 = 2 +print ====> sql : sselect c1 from stb1 where c1 >= 5 or c1 != 4 or c1 <> 3 or c1 = 2 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 32 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select c1 from stb1 where c1 >= 5 and c1 is not NULL +print ====> sql : select c1 from stb1 where c1 >= 5 and c1 is not NULL +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 17 then + return -1 +endi +if $data01 != 5 then + return -1 +endi + +sql_error select ts from stb1 where ts != 0 +sql select c1 from stb1 where ts <> 0 +print ====> sql : select c1 from stb1 where ts <> 0 +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + +sql select c1 from stb1 where c1 between 1 and 3 +print ====> sql : select c1 from stb1 where c1 between 1 and 3 +print ====> rows: $rows +if $rows != 12 then + return -1 +endi + +sql_error select c1 from stb1 where c7 between false and true + +sql select c1 from stb1 where c1 in (1,2,3) +print ====> sql : select c1 from stb1 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 12 then + return -1 +endi + +sql select c1 from stb1 where c1 in (‘true','false') +print ====> sql : select c1 from stb1 where c1 in (‘true','false') +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + +sql select c1 from stb1 where c9 like "_char_" +print ====> sql : select c1 from stb1 where c9 like "_char_" +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + +sql select c1 from stb1 where c8 like "bi%" +print ====> sql : select c1 from stb1 where c8 like "bi%" +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + + +print ================ query 2 complex with where +sql select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 33 then + return -1 +endi + +#================================================= +print =============== stop and restart taosd +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready_0: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready_0 +endi + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 33 then + return -1 +endi + +print ================ query 1 where condition +sql select * from ct3 where c1 < 5 +print ====> sql : select * from ct3 where c1 < 5 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 4 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select * from ct3 where c1 > 5 and c1 <= 6 +print ====> sql : select * from ct3 where c1 > 5 and c1 <= 6 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi +if $data01 != 6 then + return -1 +endi + +sql select * from ct3 where c1 >= 5 or c1 != 4 or c1 <> 3 or c1 = 2 +print ====> sql : select * from ct3 where c1 > 5 and c1 <= 6 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 8 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select * from ct3 where c1 >= 5 and c1 is not NULL +print ====> sql : select * from ct3 where c1 >= 5 and c1 is not NULL +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 4 then + return -1 +endi +if $data01 != 5 then + return -1 +endi + +sql_error select ts from ct3 where ts != 0 +sql select * from ct3 where ts <> 0 +print ====> sql : select * from ct3 where ts <> 0 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct3 where c1 between 1 and 3 +print ====> sql : select * from ct3 where c1 between 1 and 3 +print ====> rows: $rows +if $rows != 3 then + return -1 +endi + +sql_error select * from ct3 where c7 between false and true + +sql select * from ct3 where c1 in (1,2,3) +print ====> sql : select * from ct3 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 3 then + return -1 +endi + +sql select * from ct3 where c1 in (‘true','false') +print ====> sql : select * from ct3 where c1 in (‘true','false') +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct3 where c9 like "_char_" +print ====> sql : select * from ct3 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct3 where c8 like "bi%" +print ====> sql : select * from ct3 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select c1 from stb1 where c1 < 5 +print ====> sql : select c1 from stb1 where c1 < 5 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 16 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select c1 from stb1 where stb1 > 5 and c1 <= 6 +print ====> sql : select c1 from stb1 where c1 > 5 and c1 <= 6 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 4 then + return -1 +endi +if $data01 != 6 then + return -1 +endi + +sql select c1 from stb1 where c1 >= 5 or c1 != 4 or c1 <> 3 or c1 = 2 +print ====> sql : sselect c1 from stb1 where c1 >= 5 or c1 != 4 or c1 <> 3 or c1 = 2 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 32 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select c1 from stb1 where c1 >= 5 and c1 is not NULL +print ====> sql : select c1 from stb1 where c1 >= 5 and c1 is not NULL +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 17 then + return -1 +endi +if $data01 != 5 then + return -1 +endi + +sql_error select ts from stb1 where ts != 0 +sql select c1 from stb1 where ts <> 0 +print ====> sql : select c1 from stb1 where ts <> 0 +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + +sql select c1 from stb1 where c1 between 1 and 3 +print ====> sql : select c1 from stb1 where c1 between 1 and 3 +print ====> rows: $rows +if $rows != 12 then + return -1 +endi + +sql_error select c1 from stb1 where c7 between false and true + +sql select c1 from stb1 where c1 in (1,2,3) +print ====> sql : select c1 from stb1 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 12 then + return -1 +endi + +sql select c1 from stb1 where c1 in (‘true','false') +print ====> sql : select c1 from stb1 where c1 in (‘true','false') +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + +sql select c1 from stb1 where c9 like "_char_" +print ====> sql : select c1 from stb1 where c9 like "_char_" +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + +sql select c1 from stb1 where c8 like "bi%" +print ====> sql : select c1 from stb1 where c8 like "bi%" +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + + +print ================ query 2 complex with where +sql select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file From b223010bdd69e917c0dd5db9f0c14305a2fb1dc4 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 11 Apr 2022 14:54:16 +0800 Subject: [PATCH 10/16] fix[query]:fix memory invalid write in group by nchar data. --- source/libs/executor/inc/executorimpl.h | 2 +- source/libs/executor/src/executorimpl.c | 45 ++++++++++++++---------- source/libs/executor/src/groupoperator.c | 17 ++++++--- 3 files changed, 39 insertions(+), 25 deletions(-) diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index 9a75830ec4..f6f863c82d 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -671,7 +671,7 @@ int32_t operatorDummyOpenFn(SOperatorInfo* pOperator); void operatorDummyCloseFn(void* param, int32_t numOfCols); int32_t appendDownstream(SOperatorInfo* p, SOperatorInfo** pDownstream, int32_t num); int32_t initAggInfo(SOptrBasicInfo* pBasicInfo, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols, - int32_t numOfRows, SSDataBlock* pResultBlock, const char* pkey); + int32_t numOfRows, SSDataBlock* pResultBlock, size_t keyBufSize, const char* pkey); void toSDatablock(SGroupResInfo* pGroupResInfo, SDiskbasedBuf* pBuf, SSDataBlock* pBlock, int32_t rowCapacity, int32_t* rowCellOffset); void finalizeMultiTupleQueryResult(SqlFunctionCtx* pCtx, int32_t numOfOutput, SDiskbasedBuf* pBuf, SResultRowInfo* pResultRowInfo, int32_t* rowCellInfoOffset); void doApplyFunctions(SqlFunctionCtx* pCtx, STimeWindow* pWin, SColumnInfoData* pTimeWindowData, int32_t offset, int32_t forwardStep, TSKEY* tsCol, int32_t numOfTotal, int32_t numOfOutput, int32_t order); diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 1bc84f85d7..1c9ca87563 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -1687,12 +1687,13 @@ static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSessionAggOperator static void setResultRowKey(SResultRow* pResultRow, char* pData, int16_t type) { if (IS_VAR_DATA_TYPE(type)) { - if (pResultRow->key == NULL) { - pResultRow->key = taosMemoryMalloc(varDataTLen(pData)); - varDataCopy(pResultRow->key, pData); - } else { - assert(memcmp(pResultRow->key, pData, varDataTLen(pData)) == 0); - } + // todo disable this +// if (pResultRow->key == NULL) { +// pResultRow->key = taosMemoryMalloc(varDataTLen(pData)); +// varDataCopy(pResultRow->key, pData); +// } else { +// ASSERT(memcmp(pResultRow->key, pData, varDataTLen(pData)) == 0); +// } } else { int64_t v = -1; GET_TYPED_DATA(v, int64_t, type, pData); @@ -4467,7 +4468,7 @@ SSDataBlock* createResultDataBlock(const SArray* pExprInfo) { return pResBlock; } -static int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t numOfOutput, const char* pKey); +static int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t numOfOutput, size_t keyBufSize, const char* pKey); static void cleanupAggSup(SAggSupporter* pAggSup); static void destroySortedMergeOperatorInfo(void* param, int32_t numOfOutput) { @@ -4826,7 +4827,8 @@ SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t goto _error; } - int32_t code = doInitAggInfoSup(&pInfo->aggSup, pInfo->binfo.pCtx, num, pTaskInfo->id.str); + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; + int32_t code = doInitAggInfoSup(&pInfo->aggSup, pInfo->binfo.pCtx, num, keyBufSize, pTaskInfo->id.str); if (code != TSDB_CODE_SUCCESS) { goto _error; } @@ -5890,11 +5892,11 @@ static void destroyOperatorInfo(SOperatorInfo* pOperator) { taosMemoryFreeClear(pOperator); } -int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t numOfOutput, const char* pKey) { +int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t numOfOutput, size_t keyBufSize, const char* pKey) { _hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY); pAggSup->resultRowSize = getResultRowSize(pCtx, numOfOutput); - pAggSup->keyBuf = taosMemoryCalloc(1, sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES); + pAggSup->keyBuf = taosMemoryCalloc(1, keyBufSize); pAggSup->pResultRowHashTable = taosHashInit(10, hashFn, true, HASH_NO_LOCK); pAggSup->pResultRowListSet = taosHashInit(100, hashFn, false, HASH_NO_LOCK); pAggSup->pResultRowArrayList = taosArrayInit(10, sizeof(SResultRowCell)); @@ -5921,12 +5923,12 @@ static void cleanupAggSup(SAggSupporter* pAggSup) { } int32_t initAggInfo(SOptrBasicInfo* pBasicInfo, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols, - int32_t numOfRows, SSDataBlock* pResultBlock, const char* pkey) { + int32_t numOfRows, SSDataBlock* pResultBlock, size_t keyBufSize, const char* pkey) { pBasicInfo->pCtx = createSqlFunctionCtx_rv(pExprInfo, numOfCols, &pBasicInfo->rowCellInfoOffset); pBasicInfo->pRes = pResultBlock; pBasicInfo->capacity = numOfRows; - doInitAggInfoSup(pAggSup, pBasicInfo->pCtx, numOfCols, pkey); + doInitAggInfoSup(pAggSup, pBasicInfo->pCtx, numOfCols, keyBufSize, pkey); return TSDB_CODE_SUCCESS; } @@ -5965,7 +5967,8 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* //(int32_t)(getRowNumForMultioutput(pQueryAttr, pQueryAttr->topBotQuery, pQueryAttr->stableQuery)); int32_t numOfRows = 1; - int32_t code = initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResultBlock, pTaskInfo->id.str); + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; + int32_t code = initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResultBlock, keyBufSize, pTaskInfo->id.str); pInfo->pTableQueryInfo = initTableQueryInfo(pTableGroupInfo); if (code != TSDB_CODE_SUCCESS || pInfo->pTableQueryInfo == NULL) { goto _error; @@ -6081,8 +6084,9 @@ SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SExprI SAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SAggOperatorInfo)); int32_t numOfRows = 1; + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; int32_t code = - initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, pTaskInfo->id.str); + initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, keyBufSize, pTaskInfo->id.str); pInfo->pTableQueryInfo = initTableQueryInfo(pTableGroupInfo); if (code != TSDB_CODE_SUCCESS || pInfo->pTableQueryInfo == NULL) { goto _error; @@ -6142,7 +6146,8 @@ SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SExprInfo* p int32_t numOfCols = num; int32_t numOfRows = 4096; - initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, pTaskInfo->id.str); + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; + initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, keyBufSize, pTaskInfo->id.str); setFunctionResultOutput(&pInfo->binfo, &pInfo->aggSup, MAIN_SCAN, pTaskInfo); pInfo->pPseudoColInfo = setRowTsColumnOutputInfo(pInfo->binfo.pCtx, numOfCols); @@ -6190,7 +6195,8 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pInfo->primaryTsIndex = primaryTsSlot; int32_t numOfRows = 4096; - int32_t code = initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, pTaskInfo->id.str); + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; + int32_t code = initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, keyBufSize, pTaskInfo->id.str); initExecTimeWindowInfo(&pInfo->timeWindowData, &pInfo->win); // pInfo->pTableQueryInfo = initTableQueryInfo(pTableGroupInfo); @@ -6266,8 +6272,8 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SExprInf } pInfo->colIndex = -1; - - initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExpr, numOfCols, 4096, pResBlock, pTaskInfo->id.str); + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; + initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExpr, numOfCols, 4096, pResBlock, keyBufSize, pTaskInfo->id.str); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); pOperator->name = "StateWindowOperator"; @@ -6299,7 +6305,8 @@ SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo } int32_t numOfRows = 4096; - int32_t code = initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, pTaskInfo->id.str); + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; + int32_t code = initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, keyBufSize, pTaskInfo->id.str); if (code != TSDB_CODE_SUCCESS) { goto _error; } diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c index 3eb8ff1b72..9410d1384d 100644 --- a/source/libs/executor/src/groupoperator.c +++ b/source/libs/executor/src/groupoperator.c @@ -46,7 +46,7 @@ static int32_t initGroupOptrInfo(SArray** pGroupColVals, int32_t* keyLen, char** int32_t numOfGroupCols = taosArrayGetSize(pGroupColList); for (int32_t i = 0; i < numOfGroupCols; ++i) { SColumn* pCol = taosArrayGet(pGroupColList, i); - (*keyLen) += pCol->bytes; + (*keyLen) += pCol->bytes; // actual data + null_flag SGroupKeys key = {0}; key.bytes = pCol->bytes; @@ -61,8 +61,9 @@ static int32_t initGroupOptrInfo(SArray** pGroupColVals, int32_t* keyLen, char** } int32_t nullFlagSize = sizeof(int8_t) * numOfGroupCols; + (*keyLen) += nullFlagSize; - (*keyBuf) = taosMemoryCalloc(1, (*keyLen) + nullFlagSize); + (*keyBuf) = taosMemoryCalloc(1, (*keyLen)); if ((*keyBuf) == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -169,11 +170,16 @@ static void doAssignGroupKeys(SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(&pCtx[i]); SColumnInfoData* pColInfoData = pCtx[i].input.pData[0]; + // todo OPT all/all not NULL if (!colDataIsNull(pColInfoData, totalRows, rowIndex, NULL)) { char* dest = GET_ROWCELL_INTERBUF(pEntryInfo); char* data = colDataGetData(pColInfoData, rowIndex); - memcpy(dest, data, pColInfoData->info.bytes); + if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) { + varDataCopy(dest, data); + } else { + memcpy(dest, data, pColInfoData->info.bytes); + } } else { // it is a NULL value pEntryInfo->isNullRes = 1; } @@ -326,14 +332,15 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx pInfo->pGroupCols = pGroupColList; pInfo->pCondition = pCondition; - initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, 4096, pResultBlock, pTaskInfo->id.str); - initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); int32_t code = initGroupOptrInfo(&pInfo->pGroupColVals, &pInfo->groupKeyLen, &pInfo->keyBuf, pGroupColList); if (code != TSDB_CODE_SUCCESS) { goto _error; } + initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, 4096, pResultBlock, pInfo->groupKeyLen, pTaskInfo->id.str); + initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); + pOperator->name = "GroupbyAggOperator"; pOperator->blockingOptr = true; pOperator->status = OP_NOT_OPENED; From 86a39034d3209ee4dbb7638f4135d9547572e0d6 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Mon, 11 Apr 2022 15:13:53 +0800 Subject: [PATCH 11/16] add explain case --- tests/script/{general/explain => tsim/query}/explain.sim | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/script/{general/explain => tsim/query}/explain.sim (100%) diff --git a/tests/script/general/explain/explain.sim b/tests/script/tsim/query/explain.sim similarity index 100% rename from tests/script/general/explain/explain.sim rename to tests/script/tsim/query/explain.sim From e158dbeed99f6c0685d71092b943488c17f095c8 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Mon, 11 Apr 2022 15:21:55 +0800 Subject: [PATCH 12/16] add case to CI --- tests/script/jenkins/basic.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 2d18167337..d3ae58a524 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -32,6 +32,7 @@ ./test.sh -f tsim/query/interval-offset.sim ./test.sh -f tsim/query/scalarFunction.sim ./test.sh -f tsim/query/charScalarFunction.sim +./test.sh -f tsim/query/explain.sim # ---- qnode ./test.sh -f tsim/qnode/basic1.sim From 6b681d79d4de328f3b4d110e39433a2aec5f5df4 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 11 Apr 2022 15:25:19 +0800 Subject: [PATCH 13/16] fix[query]:enable sum function to be applied to bool data type. --- source/libs/function/src/builtins.c | 2 +- source/libs/function/src/builtinsimpl.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index c1cdcbcb0c..0d0afd4011 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -479,7 +479,7 @@ int32_t stubCheckAndGetResultType(SFunctionNode* pFunc) { int32_t paraType = pParam->node.resType.type; int32_t resType = 0; - if (IS_SIGNED_NUMERIC_TYPE(paraType)) { + if (IS_SIGNED_NUMERIC_TYPE(paraType) || paraType == TSDB_DATA_TYPE_BOOL) { resType = TSDB_DATA_TYPE_BIGINT; } else if (IS_UNSIGNED_NUMERIC_TYPE(paraType)) { resType = TSDB_DATA_TYPE_UBIGINT; diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index bad40422c8..53b15a82af 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -138,8 +138,8 @@ int32_t sumFunction(SqlFunctionCtx *pCtx) { int32_t start = pInput->startRowIndex; int32_t numOfRows = pInput->numOfRows; - if (IS_SIGNED_NUMERIC_TYPE(type)) { - if (type == TSDB_DATA_TYPE_TINYINT) { + if (IS_SIGNED_NUMERIC_TYPE(type) || type == TSDB_DATA_TYPE_BOOL) { + if (type == TSDB_DATA_TYPE_TINYINT || type == TSDB_DATA_TYPE_BOOL) { LIST_ADD_N(pSumRes->isum, pCol, start, numOfRows, int8_t, numOfElem); } else if (type == TSDB_DATA_TYPE_SMALLINT) { LIST_ADD_N(pSumRes->isum, pCol, start, numOfRows, int16_t, numOfElem); From e4d53ef3c77245311a65b54d5de0a70b9830c28c Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Mon, 11 Apr 2022 15:57:34 +0800 Subject: [PATCH 14/16] fix hb bug --- source/common/src/tmsg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 5973a70b59..0edfcb3314 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -1960,7 +1960,7 @@ int32_t tDeserializeSUseDbBatchRsp(void *buf, int32_t bufLen, SUseDbBatchRsp *pR int32_t numOfBatch = taosArrayGetSize(pRsp->pArray); if (tDecodeI32(&decoder, &numOfBatch) < 0) return -1; - pRsp->pArray = taosArrayInit(numOfBatch, sizeof(SUseDbBatchRsp)); + pRsp->pArray = taosArrayInit(numOfBatch, sizeof(SUseDbRsp)); if (pRsp->pArray == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; From 3ff5d91d31c7fee71280ea19eca93cac48387171 Mon Sep 17 00:00:00 2001 From: plum-lihui Date: Mon, 11 Apr 2022 16:12:34 +0800 Subject: [PATCH 15/16] test:add session windows cases --- tests/script/tsim/query/session.sim | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/script/tsim/query/session.sim b/tests/script/tsim/query/session.sim index 3a57581668..2f85cc7723 100644 --- a/tests/script/tsim/query/session.sim +++ b/tests/script/tsim/query/session.sim @@ -77,6 +77,8 @@ sql INSERT INTO dev_002 VALUES('2020-05-13 10:00:00.51', 7) $loop_test = 0 loop_test_pos: +sql use $dbNamme + # session(ts,5a) print ====> select count(*) from dev_001 session(ts,5a) sql select _wstartts, count(*) from dev_001 session(ts,5a) @@ -301,12 +303,17 @@ sql create table dev_001 (ts timestamp ,i timestamp ,j int) sql insert into dev_001 values(1623046993681000,now,1)(1623046993681001,now+1s,2)(1623046993681002,now+2s,3)(1623046993681004,now+5s,4) print ====> select count(*) from dev_001 session(ts,1u) sql select _wstartts, count(*) from dev_001 session(ts,1u) -if $rows != 2 then +print rows: $rows +print $data00 $data01 $data02 $data03 +print $data10 $data11 $data12 $data13 +print $data20 $data21 $data22 $data23 +print $data30 $data31 $data32 $data33 +if $rows != 4 then print expect 2, actual: $rows return -1 endi -if $data01 != 3 then +if $data01 != 1 then return -1 endi From 0f83fd7c5903b7358c48511847c2e7bec1f296f8 Mon Sep 17 00:00:00 2001 From: plum-lihui Date: Mon, 11 Apr 2022 16:32:44 +0800 Subject: [PATCH 16/16] test: add session cases into CI --- tests/script/jenkins/basic.txt | 1 + tests/script/tsim/query/session.sim | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 761a8921d5..c6a69f7e06 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -32,6 +32,7 @@ ./test.sh -f tsim/query/interval-offset.sim ./test.sh -f tsim/query/scalarFunction.sim ./test.sh -f tsim/query/charScalarFunction.sim +./test.sh -f tsim/query/session.sim # ---- qnode ./test.sh -f tsim/qnode/basic1.sim diff --git a/tests/script/tsim/query/session.sim b/tests/script/tsim/query/session.sim index 2f85cc7723..282d83bc27 100644 --- a/tests/script/tsim/query/session.sim +++ b/tests/script/tsim/query/session.sim @@ -219,8 +219,8 @@ endi #endi -print ====> leastsquares not supported yet. -print ====> select count(*),first(tagtype),last(tagtype),avg(tagtype),sum(tagtype),min(tagtype),max(tagtype),leastsquares(tagtype, 1, 1),spread(tagtype),stddev(tagtype),percentile(tagtype,0) from dev_001 where ts <'2020-05-20 0:0:0' session(ts,1d) +#print ====> leastsquares not supported yet. +#print ====> select count(*),first(tagtype),last(tagtype),avg(tagtype),sum(tagtype),min(tagtype),max(tagtype),leastsquares(tagtype, 1, 1),spread(tagtype),stddev(tagtype),percentile(tagtype,0) from dev_001 where ts <'2020-05-20 0:0:0' session(ts,1d) #sql select count(*),first(tagtype),last(tagtype),avg(tagtype),sum(tagtype),min(tagtype),max(tagtype),leastsquares(tagtype, 1, 1),spread(tagtype),stddev(tagtype),percentile(tagtype,0) from dev_001 where ts <'2020-05-20 0:0:0' session(ts,1d) #if $rows != 2 then # return -1 @@ -287,14 +287,14 @@ print ====> select count(*),first(tagtype),last(tagtype),avg(tagtype),sum(tagtyp #endi print ================> syntax error check not active ================> reactive -#sql_error select * from dev_001 session(ts,1w) -#sql_error select count(*) from st session(ts,1w) -#sql_error select count(*) from dev_001 group by tagtype session(ts,1w) -#sql_error select count(*) from dev_001 session(ts,1n) -#sql_error select count(*) from dev_001 session(ts,1y) -#sql_error select count(*) from dev_001 session(ts,0s) -#sql_error select count(*) from dev_001 session(i,1y) -#sql_error select count(*) from dev_001 session(ts,1d) where ts <'2020-05-20 0:0:0' +sql_error select * from dev_001 session(ts,1w) +sql select count(*) from st session(ts,1w) +sql_error select count(*) from dev_001 group by tagtype session(ts,1w) +sql select count(*) from dev_001 session(ts,1n) +sql select count(*) from dev_001 session(ts,1y) +sql select count(*) from dev_001 session(ts,0s) +sql_error select count(*) from dev_001 session(i,1y) +sql_error select count(*) from dev_001 session(ts,1d) where ts <'2020-05-20 0:0:0' print ====> create database d1 precision 'us' sql create database d1 precision 'us' @@ -318,7 +318,7 @@ if $data01 != 1 then endi #sql_error select count(*) from dev_001 session(i,1s) -#sql create table secondts(ts timestamp,t2 timestamp,i int) +sql create table secondts(ts timestamp,t2 timestamp,i int) #sql_error select count(*) from secondts session(t2,2s) if $loop_test == 0 then