diff --git a/tests/script/general/parser/alter.sim b/tests/script/general/parser/alter.sim index 6c884973963200fe416fba5a428b7050aa2329c2..d1a4702a69dce22e7de0de005d912e7813648e01 100644 --- a/tests/script/general/parser/alter.sim +++ b/tests/script/general/parser/alter.sim @@ -20,8 +20,82 @@ $db = $dbPrefix . $i $mt = $mtPrefix . $i sql drop database if exists $db -sql create database $db +sql create database $db days 10 keep 20,20,20 sql use $db + +sql_error alter database $db keep "20" +sql_error alter database $db keep "20","20","20" +sql_error alter database $db keep 20,19 +sql_error alter database $db keep 20.0 +sql_error alter database $db keep 20.0,20.0,20.0 +sql_error alter database $db keep 0,0,0 +sql_error alter database $db keep -1,-1,-1 +sql_error alter database $db keep 9,20 +sql_error alter database $db keep 9,9,9 +sql_error alter database $db keep 20,20,19 +sql_error alter database $db keep 20,19,20 +sql_error alter database $db keep 20,19,19 +sql_error alter database $db keep 20,19,18 +sql_error alter database $db keep 20,20,20,20 +sql_error alter database $db keep 365001,365001,365001 +sql alter database $db keep 21 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 21,21,21 then + return -1 +endi +sql alter database $db keep 11,12 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 11,12,12 then + return -1 +endi +sql alter database $db keep 20,20,20 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 20,20,20 then + return -1 +endi +sql alter database $db keep 10,10,10 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 10,10,10 then + return -1 +endi +sql alter database $db keep 10,10,11 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 10,10,11 then + return -1 +endi +sql alter database $db keep 11,12,13 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 11,12,13 then + return -1 +endi +sql alter database $db keep 365000,365000,365000 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 365000,365000,365000 then + return -1 +endi + + ##### alter table test, simeplest case sql create table tb (ts timestamp, c1 int, c2 int, c3 int) sql insert into tb values (now, 1, 1, 1) diff --git a/tests/script/general/parser/alter__for_community_version.sim b/tests/script/general/parser/alter__for_community_version.sim new file mode 100644 index 0000000000000000000000000000000000000000..f55fb812a74eead44e54808b000a48c3db92b66d --- /dev/null +++ b/tests/script/general/parser/alter__for_community_version.sim @@ -0,0 +1,316 @@ +system sh/stop_dnodes.sh + +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c walLevel -v 1 +system sh/exec.sh -n dnode1 -s start +sleep 100 +sql connect + +$dbPrefix = m_alt_db +$tbPrefix = m_alt_tb +$mtPrefix = m_alt_mt +$tbNum = 10 +$rowNum = 5 +$totalNum = $tbNum * $rowNum +$ts0 = 1537146000000 +$delta = 600000 +print ========== alter.sim +$i = 0 +$db = $dbPrefix . $i +$mt = $mtPrefix . $i + +sql drop database if exists $db +sql create database $db days 10 keep 20 +sql use $db +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 20 then + return -1 +endi + +sql_error alter database $db keep "20" +sql_error alter database $db keep "20","20","20" +sql_error alter database $db keep 0 +sql_error alter database $db keep 20.0 +sql_error alter database $db keep 20.0,20.0,20.0 +sql_error alter database $db keep 0,0,0 +sql_error alter database $db keep 3 +sql_error alter database $db keep -1,-1,-1 +sql_error alter database $db keep 20,20 +sql_error alter database $db keep 9,9,9 +sql_error alter database $db keep 20,20,19 +sql_error alter database $db keep 20,19,20 +sql_error alter database $db keep 20,19,19 +sql_error alter database $db keep 20,19,18 +sql_error alter database $db keep 20,20,20,20 +sql_error alter database $db keep 365001,365001,365001 +sql_error alter database $db keep 365001 +sql alter database $db keep 20 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 20 then + return -1 +endi +sql alter database $db keep 10 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 10 then + return -1 +endi +sql alter database $db keep 11 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 11 then + return -1 +endi +sql alter database $db keep 13 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 13 then + return -1 +endi +sql alter database $db keep 365000 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 365000 then + return -1 +endi + + +##### alter table test, simeplest case +sql create table tb (ts timestamp, c1 int, c2 int, c3 int) +sql insert into tb values (now, 1, 1, 1) +sql select * from tb order by ts desc +if $rows != 1 then + return -1 +endi +sql alter table tb drop column c3 +sql select * from tb order by ts desc +if $data01 != 1 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data03 != null then + return -1 +endi +sql alter table tb add column c3 nchar(4) +sql select * from tb order by ts desc +if $rows != 1 then + return -1 +endi +if $data03 != NULL then + return -1 +endi +sql insert into tb values (now, 2, 2, 'taos') +sql select * from tb order by ts desc +if $rows != 2 then + return -1 +endi +print data03 = $data03 +if $data03 != taos then + print expect taos, actual: $data03 + return -1 +endi +sql drop table tb + +##### alter metric test, simplest case +sql create table mt (ts timestamp, c1 int, c2 int, c3 int) tags (t1 int) +sql create table tb using mt tags(1) +sql insert into tb values (now, 1, 1, 1) +sql alter table mt drop column c3 +sql select * from tb order by ts desc +if $data01 != 1 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data03 != null then + return -1 +endi + +sql alter table mt add column c3 nchar(4) +sql select * from tb order by ts desc +if $data03 != NULL then + return -1 +endi +sql insert into tb values (now, 2, 2, 'taos') +sql select * from tb order by ts desc +if $rows != 2 then + return -1 +endi +if $data03 != taos then + return -1 +endi +if $data13 != NULL then + return -1 +endi +sql drop table tb +sql drop table mt + +## [TBASE272] +sql create table tb (ts timestamp, c1 int, c2 int, c3 int) +sql insert into tb values (now, 1, 1, 1) +sql alter table tb drop column c3 +sql alter table tb add column c3 nchar(5) +sql insert into tb values(now, 2, 2, 'taos') +sql drop table tb +sql create table mt (ts timestamp, c1 int, c2 int, c3 int) tags (t1 int) +sql create table tb using mt tags(1) +sql insert into tb values (now, 1, 1, 1) +sql alter table mt drop column c3 +sql select * from tb order by ts desc +if $rows != 1 then + return -1 +endi +sql drop table tb +sql drop table mt + +sleep 100 +### ALTER TABLE WHILE STREAMING [TBASE271] +#sql create table tb1 (ts timestamp, c1 int, c2 nchar(5), c3 int) +#sql create table strm as select count(*), avg(c1), first(c2), sum(c3) from tb1 interval(2s) +#sql select * from strm +#if $rows != 0 then +# return -1 +#endi +##sleep 12000 +#sql insert into tb1 values (now, 1, 'taos', 1) +#sleep 20000 +#sql select * from strm +#print rows = $rows +#if $rows != 1 then +# return -1 +#endi +#if $data04 != 1 then +# return -1 +#endi +#sql alter table tb1 drop column c3 +#sleep 500 +#sql insert into tb1 values (now, 2, 'taos') +#sleep 30000 +#sql select * from strm +#if $rows != 2 then +# return -1 +#endi +#if $data04 != 1 then +# return -1 +#endi +#sql alter table tb1 add column c3 int +#sleep 500 +#sql insert into tb1 values (now, 3, 'taos', 3); +#sleep 100 +#sql select * from strm +#if $rows != 3 then +# return -1 +#endi +#if $data04 != 1 then +# return -1 +#endi + +## ALTER TABLE AND INSERT BY COLUMNS +sql create table mt (ts timestamp, c1 int, c2 int) tags(t1 int) +sql create table tb using mt tags(0) +sql insert into tb values (now-1m, 1, 1) +sql alter table mt drop column c2 +sql_error insert into tb (ts, c1, c2) values (now, 2, 2) +sql insert into tb (ts, c1) values (now, 2) +sql select * from tb order by ts desc +if $rows != 2 then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data02 != null then + return -1 +endi +sql alter table mt add column c2 int +sql insert into tb (ts, c2) values (now, 3) +sql select * from tb order by ts desc +if $data02 != 3 then + return -1 +endi + +## ALTER TABLE AND IMPORT +sql drop database $db +sql create database $db +sql use $db +sql create table mt (ts timestamp, c1 int, c2 nchar(7), c3 int) tags (t1 int) +sql create table tb using mt tags(1) +sleep 100 +sql insert into tb values ('2018-11-01 16:30:00.000', 1, 'insert', 1) +sql alter table mt drop column c3 + +sql insert into tb values ('2018-11-01 16:29:59.000', 1, 'insert') +sql import into tb values ('2018-11-01 16:29:59.000', 1, 'import') +sql select * from tb order by ts desc +if $data01 != 1 then + return -1 +endi +if $data02 != insert then + return -1 +endi +sql alter table mt add column c3 nchar(4) +sql select * from tb order by ts desc +if $data03 != NULL then + return -1 +endi + +print ============================>TD-3366 TD-3486 +sql insert into td_3366(ts, c3, c1) using mt(t1) tags(911) values('2018-1-1 11:11:11', 'new1', 12); +sql insert into td_3486(ts, c3, c1) using mt(t1) tags(-12) values('2018-1-1 11:11:11', 'new1', 12); +sql insert into ttxu(ts, c3, c1) using mt(t1) tags('-121') values('2018-1-1 11:11:11', 'new1', 12); + +sql insert into tb(ts, c1, c3) using mt(t1) tags(123) values('2018-11-01 16:29:58.000', 2, 'port') + +sql insert into tb values ('2018-11-01 16:29:58.000', 2, 'import', 3) +sql import into tb values ('2018-11-01 16:29:58.000', 2, 'import', 3) +sql import into tb values ('2018-11-01 16:39:58.000', 2, 'import', 3) +sql select * from tb order by ts desc +if $rows != 4 then + return -1 +endi + +if $data03 != 3 then + return -1 +endi + +##### ILLEGAL OPERATIONS + +# try dropping columns that are defined in metric +sql_error alter table tb drop column c1; + +# try dropping primary key +sql_error alter table mt drop column ts; + +# try modifying two columns in a single statement +sql_error alter table mt add column c5 nchar(3) c6 nchar(4) + +# duplicate columns +sql_error alter table mt add column c1 int + +# drop non-existing columns +sql_error alter table mt drop column c9 + +#sql drop database $db +#sql show databases +#if $rows != 0 then +# return -1 +#endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/alter_column.sim b/tests/script/general/parser/alter_column.sim new file mode 100644 index 0000000000000000000000000000000000000000..fe109352d12ba42a5c9fe318766764a850132abf --- /dev/null +++ b/tests/script/general/parser/alter_column.sim @@ -0,0 +1,118 @@ +system sh/stop_dnodes.sh + +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c walLevel -v 1 +system sh/exec.sh -n dnode1 -s start +sleep 100 +sql connect + +$dbPrefix = m_alt_db +$tbPrefix = m_alt_tb +$mtPrefix = m_alt_mt +$tbNum = 10 +$rowNum = 5 +$totalNum = $tbNum * $rowNum +$ts0 = 1537146000000 +$delta = 600000 +print ========== alter.sim +$i = 0 +$db = $dbPrefix . $i +$mt = $mtPrefix . $i + +sql drop database if exists $db +sql create database $db +sql use $db +##### alter table test, simeplest case +sql create table tb (ts timestamp, c1 int, c2 binary(10), c3 nchar(10)) +sql insert into tb values (now, 1, "1", "1") +sql alter table tb modify column c2 binary(20); +if $rows != 0 then + return -1 +endi +sql alter table tb modify column c3 nchar(20); +if $rows != 0 then + return -1 +endi + + +sql create stable stb (ts timestamp, c1 int, c2 binary(10), c3 nchar(10)) tags(id1 int, id2 binary(10), id3 nchar(10)) +sql create table tb1 using stb tags(1, "a", "b") +sql insert into tb1 values (now, 1, "1", "1") +sql alter stable stb modify column c2 binary(20); +if $rows != 0 then + return -1 +endi +sql alter table stb modify column c2 binary(30); +if $rows != 0 then + return -1 +endi +sql alter stable stb modify column c3 nchar(20); +if $rows != 0 then + return -1 +endi +sql alter table stb modify column c3 nchar(30); +if $rows != 0 then + return -1 +endi + +sql alter table stb modify tag id2 binary(11); +if $rows != 0 then + return -1 +endi +sql alter stable stb modify tag id2 binary(11); +if $rows != 0 then + return -1 +endi +sql alter table stb modify tag id3 nchar(11); +if $rows != 0 then + return -1 +endi +sql alter stable stb modify tag id3 nchar(11); +if $rows != 0 then + return -1 +endi + +##### ILLEGAL OPERATIONS + +# try dropping columns that are defined in metric +sql_error alter table tb modify column c1 binary(10); +sql_error alter table tb modify column c1 double; +sql_error alter table tb modify column c2 int; +sql_error alter table tb modify column c2 binary(10); +sql_error alter table tb modify column c2 binary(9); +sql_error alter table tb modify column c2 binary(-9); +sql_error alter table tb modify column c2 binary(0); +sql_error alter table tb modify column c2 binary(17000); +sql_error alter table tb modify column c2 nchar(30); +sql_error alter table tb modify column c3 double; +sql_error alter table tb modify column c3 nchar(10); +sql_error alter table tb modify column c3 nchar(0); +sql_error alter table tb modify column c3 nchar(-1); +sql_error alter table tb modify column c3 binary(80); +sql_error alter table tb modify column c3 nchar(17000); +sql_error alter table tb modify column c3 nchar(100), c2 binary(30); +sql_error alter table tb modify column c1 nchar(100), c2 binary(30); +sql_error alter stable tb modify column c2 binary(30); +sql_error alter table tb modify tag c2 binary(30); +sql_error alter table stb modify tag id2 binary(10); +sql_error alter table stb modify tag id2 nchar(30); +sql_error alter stable stb modify tag id2 binary(10); +sql_error alter stable stb modify tag id2 nchar(30); +sql_error alter table stb modify tag id3 nchar(10); +sql_error alter table stb modify tag id3 binary(30); +sql_error alter stable stb modify tag id3 nchar(10); +sql_error alter stable stb modify tag id3 binary(30); +sql_error alter stable stb modify tag id1 binary(30); +sql_error alter stable stb modify tag c1 binary(30); + + +sql_error alter table tb1 modify column c2 binary(30); +sql_error alter table tb1 modify column c3 nchar(30); +sql_error alter table tb1 modify tag id2 binary(30); +sql_error alter table tb1 modify tag id3 nchar(30); +sql_error alter stable tb1 modify tag id2 binary(30); +sql_error alter stable tb1 modify tag id3 nchar(30); +sql_error alter stable tb1 modify column c2 binary(30); + + +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/create_db.sim b/tests/script/general/parser/create_db.sim index 9ca84af136ad16735c9faf4f10ba913775f53103..7881060ad178fe3b3f7a9ea0530a1ac517264a3e 100644 --- a/tests/script/general/parser/create_db.sim +++ b/tests/script/general/parser/create_db.sim @@ -102,7 +102,7 @@ print create_db.sim case5: db_meta_data test # cfg params $replica = 1 # max=3 $days = 10 -$keep = 365 +$keep = 365,365,365 $rows_db = 1000 $cache = 16 # 16MB $ablocks = 100 @@ -150,6 +150,73 @@ sql_error create database $db day 3651 # keep [1, infinity] sql_error create database $db keep 0 +sql_error create database $db keep 0,0,0 +sql_error create database $db keep 3,3,3 +sql_error create database $db keep 11.0 +sql_error create database $db keep 11.0,11.0,11.0 +sql_error create database $db keep "11","11","11" +sql_error create database $db keep "11" +sql_error create database $db keep 13,12,11 +sql_error create database $db keep 11,12,11 +sql_error create database $db keep 12,11,12 +sql_error create database $db keep 8 +sql_error create database $db keep 12,11 +sql_error create database $db keep 365001,365001,365001 +sql create database dbk0 keep 19 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 19,19,19 then + return -1 +endi +sql drop database dbk0 +sql create database dbka keep 19,20 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 19,20,20 then + return -1 +endi +sql drop database dbka + +sql create database dbk1 keep 11,11,11 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 11,11,11 then + return -1 +endi +sql drop database dbk1 +sql create database dbk2 keep 11,12,13 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 11,12,13 then + return -1 +endi +sql drop database dbk2 +sql create database dbk3 keep 11,11,13 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 11,11,13 then + return -1 +endi +sql drop database dbk3 +sql create database dbk4 keep 11,13,13 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 11,13,13 then + return -1 +endi +sql drop database dbk4 #sql_error create database $db keep 3651 # rows [200, 10000] diff --git a/tests/script/general/parser/create_db__for_community_version.sim b/tests/script/general/parser/create_db__for_community_version.sim new file mode 100644 index 0000000000000000000000000000000000000000..406e69b0e6a025c5e733ab753510f65677e4b550 --- /dev/null +++ b/tests/script/general/parser/create_db__for_community_version.sim @@ -0,0 +1,238 @@ +system sh/stop_dnodes.sh + + +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c walLevel -v 1 +system sh/exec.sh -n dnode1 -s start + +sleep 100 +sql connect +print ======================== dnode1 start + +$dbPrefix = fi_in_db +$tbPrefix = fi_in_tb +$mtPrefix = fi_in_mt +$tbNum = 10 +$rowNum = 20 +$totalNum = 200 + +print excuting test script create_db.sim +print =============== set up +$i = 0 +$db = $dbPrefix . $i +$mt = $mtPrefix . $i + +sql_error createdatabase $db +sql create database $db +sql use $db +sql show databases + +if $rows != 1 then + return -1 +endi +if $data00 != $db then + return -1 +endi +sql drop database $db + +# case1: case_insensitivity test +print =========== create_db.sim case1: case insensitivity test +sql_error CREATEDATABASE $db +sql CREATE DATABASE $db +sql use $db +sql show databases + +if $rows != 1 then + return -1 +endi +if $data00 != $db then + return -1 +endi +sql drop database $db +print case_insensitivity test passed + +# case2: illegal_db_name test +print =========== create_db.sim case2: illegal_db_name test +$illegal_db1 = 1db +$illegal_db2 = d@b + +sql_error create database $illegal_db1 +sql_error create database $illegal_db2 +print illegal_db_name test passed + +# case3: chinese_char_in_db_name test +print ========== create_db.sim case3: chinese_char_in_db_name test +$CN_db1 = 数据库 +$CN_db2 = 数据库1 +$CN_db3 = db数据库1 +sql_error create database $CN_db1 +sql_error create database $CN_db2 +sql_error create database $CN_db3 +#sql show databases +#if $rows != 3 then +# return -1 +#endi +#if $data00 != $CN_db1 then +# return -1 +#endi +#if $data10 != $CN_db2 then +# return -1 +#endi +#if $data20 != $CN_db3 then +# return -1 +#endi +#sql drop database $CN_db1 +#sql drop database $CN_db2 +#sql drop database $CN_db3 +print case_chinese_char_in_db_name test passed + +# case4: db_already_exists +print create_db.sim case4: db_already_exists +sql create database db0 +sql create database db0 +sql show databases +if $rows != 1 then + return -1 +endi +sql drop database db0 +print db_already_exists test passed + +# case5: db_meta_data +print create_db.sim case5: db_meta_data test +# cfg params +$replica = 1 # max=3 +$days = 10 +$keep = 365 +$rows_db = 1000 +$cache = 16 # 16MB +$ablocks = 100 +$tblocks = 32 # max=512, automatically trimmed when exceeding +$ctime = 36000 # 10 hours +$wal = 1 # valid value is 1, 2 +$comp = 1 # max=32, automatically trimmed when exceeding + +sql create database $db replica $replica days $days keep $keep maxrows $rows_db cache $cache blocks 4 ctime $ctime wal $wal comp $comp +sql show databases +if $rows != 1 then + return -1 +endi +if $data00 != $db then + return -1 +endi +if $data04 != $replica then + return -1 +endi +if $data06 != $days then + return -1 +endi +if $data07 != 365 then + return -1 +endi +print data08 = $data07 +if $data08 != $cache then + print expect $cache, actual:$data08 + return -1 +endi +if $data09 != 4 then + return -1 +endi + +sql drop database $db + +## param range tests +# replica [1,3] +#sql_error create database $db replica 0 +sql_error create database $db replica 4 + +# day [1, 3650] +sql_error create database $db day 0 +sql_error create database $db day 3651 + +# keep [1, infinity] +sql_error create database $db keep 0 +sql_error create database $db keep 0,0,0 +sql_error create database $db keep 3,3,3 +sql_error create database $db keep 3 +sql_error create database $db keep 11.0 +sql_error create database $db keep 11.0,11.0,11.0 +sql_error create database $db keep "11","11","11" +sql_error create database $db keep "11" +sql_error create database $db keep 13,12,11 +sql_error create database $db keep 11,12,11 +sql_error create database $db keep 12,11,12 +sql_error create database $db keep 11,12,13 +sql_error create database $db keep 11,12,13,14 +sql_error create database $db keep 11,11 +sql_error create database $db keep 365001,365001,365001 +sql_error create database $db keep 365001 +sql create database dbk1 keep 11 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 11 then + return -1 +endi +sql drop database dbk1 +sql create database dbk2 keep 12 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 12 then + return -1 +endi +sql drop database dbk2 +sql create database dbk3 keep 11 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 11 then + return -1 +endi +sql drop database dbk3 +sql create database dbk4 keep 13 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 13 then + return -1 +endi +sql drop database dbk4 +#sql_error create database $db keep 3651 + +# rows [200, 10000] +sql_error create database $db maxrows 199 +#sql_error create database $db maxrows 10001 + +# cache [100, 10485760] +sql_error create database $db cache 0 +#sql_error create database $db cache 10485761 + + +# blocks [32, 4096 overwriten by 4096 if exceeds, Note added:2018-10-24] +#sql_error create database $db tblocks 31 +#sql_error create database $db tblocks 4097 + +# ctime [30, 40960] +sql_error create database $db ctime 29 +sql_error create database $db ctime 40961 + +# wal {0, 2} +#sql_error create database $db wal 0 +sql_error create database $db wal -1 +sql_error create database $db wal 3 + +# comp {0, 1, 2} +sql_error create database $db comp -1 +sql_error create database $db comp 3 + +sql_error drop database $db +sql show databases +if $rows != 0 then + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/create_mt.sim b/tests/script/general/parser/create_mt.sim index ae1629dce9861d7540bda4b6d4014e32ce2ce52d..c606ba99ecb5f9060de9bb8f52af916c2d2b96b6 100644 --- a/tests/script/general/parser/create_mt.sim +++ b/tests/script/general/parser/create_mt.sim @@ -99,7 +99,7 @@ $i_binary2 = varchar(20) # illegal string $i_bool = boolean $nchar = nchar # nchar with unspecified length print ========== create_mt.sim case4: illegal data types in tags test -sql_error create table $mt (ts timestamp, col int) tags (tag1 timestamp ) +##sql_error create table $mt (ts timestamp, col int) tags (tag1 timestamp ) sql_error create table $mt (ts timestamp, col int) tags (tag1 $i_ts ) sql_error create table $mt (ts timestamp, col int) tags (tag1 $i_binary ) sql_error create table $mt (ts timestamp, col int) tags (tag1 $i_bigint ) @@ -253,4 +253,4 @@ if $rows != 0 then return -1 endi -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/fill_us.sim b/tests/script/general/parser/fill_us.sim index 8cd2c333475a0d0140eb5c0c8ee0fa4186fccc97..762413d0a1e975c778ccd3d31e54e0f2d347cef2 100644 --- a/tests/script/general/parser/fill_us.sim +++ b/tests/script/general/parser/fill_us.sim @@ -959,14 +959,14 @@ endi if $data31 != 9.000000000 then return -1 endi -if $data41 != null then +if $data41 != NULL then print ===== $data41 return -1 endi if $data51 != 16.000000000 then return -1 endi -if $data61 != null then +if $data61 != NULL then print ===== $data61 return -1 endi diff --git a/tests/script/general/parser/first_last.sim b/tests/script/general/parser/first_last.sim index f47f67ddc668c94f423cb3a42d97be3d52c8dcda..09047b4528a68219f27fc3b2e913a62fd567cd42 100644 --- a/tests/script/general/parser/first_last.sim +++ b/tests/script/general/parser/first_last.sim @@ -124,4 +124,4 @@ if $rows != 10000 then return -1 endi -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/function.sim b/tests/script/general/parser/function.sim index ee5a750c88ede5e373c47796c1bc9d373f223e19..a485276e018e80c83ec6a1d34e4d597b85118a2a 100644 --- a/tests/script/general/parser/function.sim +++ b/tests/script/general/parser/function.sim @@ -814,3 +814,322 @@ if $data00 != 1 then endi print ====================> TODO stddev + normal column filter + + +print ====================> irate +sql_error select irate(f1) from st1; +sql select irate(f1) from st1 group by tbname; + +sql select irate(k) from t1 +if $rows != 1 then + return -1 +endi + +if $data00 != 0.000027778 then + return -1 +endi + +sql select irate(k) from t1 where ts>='2015-8-18 00:30:00.000' +if $rows != 1 then + return -1 +endi + +if $data00 != 0.000000000 then + print expect 0.000000000, actual $data00 + return -1 +endi + +sql select irate(k) from t1 where ts>='2015-8-18 00:06:00.000' and ts<='2015-8-18 00:12:000'; +if $rows != 1 then + return -1 +endi + +if $data00 != 0.005633334 then + return -1 +endi + +sql select irate(k) from t1 interval(10a) +if $rows != 6 then + return -1 +endi + +if $data01 != 0.000000000 then + return -1 +endi + +if $data11 != 0.000000000 then + return -1 +endi + +if $data51 != 0.000000000 then + return -1 +endi + +sql select count(*),irate(k) from t1 interval(10m) +if $rows != 4 then + return -1 +endi + +if $data00 != @15-08-18 00:00:00.000@ then + return -1 +endi + +if $data01 != 2 then + return -1 +endi + +if $data02 != 0.000144445 then + return -1 +endi + +if $data10 != @15-08-18 00:10:00.000@ then + return -1 +endi + +if $data11 != 2 then + return -1 +endi + +if $data12 != 0.000272222 then + return -1 +endi + +if $data20 != @15-08-18 00:20:00.000@ then + return -1 +endi + +if $data21 != 1 then + return -1 +endi + +if $data22 != 0.000000000 then + return -1 +endi + +if $data30 != @15-08-18 00:30:00.000@ then + return -1 +endi + +if $data31 != 1 then + return -1 +endi + +if $data32 != 0.000000000 then + return -1 +endi + +sql select count(*),irate(k) from t1 interval(10m) order by ts desc +if $rows != 4 then + return -1 +endi + +if $data30 != @15-08-18 00:00:00.000@ then + return -1 +endi + +if $data31 != 2 then + return -1 +endi + +if $data32 != 0.000144445 then + return -1 +endi + +print ===========================> derivative +sql drop table t1 +sql drop table tx; +sql drop table if exists m1; +sql drop table if exists tm0; +sql drop table if exists tm1; + +sql create table tm0(ts timestamp, k double) +sql insert into tm0 values('2015-08-18T00:00:00Z', 2.064) ('2015-08-18T00:06:00Z', 2.116) ('2015-08-18T00:12:00Z', 2.028) +sql insert into tm0 values('2015-08-18T00:18:00Z', 2.126) ('2015-08-18T00:24:00Z', 2.041) ('2015-08-18T00:30:00Z', 2.051) + +sql_error select derivative(ts) from tm0; +sql_error select derivative(k) from tm0; +sql_error select derivative(k, 0, 0) from tm0; +sql_error select derivative(k, 1, 911) from tm0; +sql_error select derivative(kx, 1s, 1) from tm0; +sql_error select derivative(k, -20s, 1) from tm0; +sql_error select derivative(k, 20a, 0) from tm0; +sql_error select derivative(k, 200a, 0) from tm0; +sql_error select derivative(k, 999a, 0) from tm0; +sql_error select derivative(k, 20s, -12) from tm0; + +sql select derivative(k, 1s, 0) from tm0 +if $rows != 5 then + return -1 +endi + +if $data00 != @15-08-18 08:06:00.000@ then + return -1 +endi + +if $data01 != 0.000144444 then + print expect 0.000144444, actual: $data01 + return -1 +endi + +if $data10 != @15-08-18 08:12:00.000@ then + return -1 +endi + +if $data11 != -0.000244444 then + return -1 +endi + +if $data20 != @15-08-18 08:18:00.000@ then + return -1 +endi + +if $data21 != 0.000272222 then + print expect 0.000272222, actual: $data21 + return -1 +endi + +if $data30 != @15-08-18 08:24:00.000@ then + return -1 +endi + +if $data31 != -0.000236111 then + print expect 0.000236111, actual: $data31 + return -1 +endi + +sql select derivative(k, 6m, 0) from tm0; +if $rows != 5 then + return -1 +endi + +if $data00 != @15-08-18 08:06:00.000@ then + return -1 +endi + +if $data01 != 0.052000000 then + print expect 0.052000000, actual: $data01 + return -1 +endi + +if $data10 != @15-08-18 08:12:00.000@ then + return -1 +endi + +if $data11 != -0.088000000 then + return -1 +endi + +if $data20 != @15-08-18 08:18:00.000@ then + return -1 +endi + +if $data21 != 0.098000000 then + return -1 +endi + +if $data30 != @15-08-18 08:24:00.000@ then + return -1 +endi + +if $data31 != -0.085000000 then + return -1 +endi + +sql select derivative(k, 12m, 0) from tm0; +if $rows != 5 then + return -1 +endi + +if $data00 != @15-08-18 08:06:00.000@ then + return -1 +endi + +if $data01 != 0.104000000 then + print expect 0.104000000, actual: $data01 + return -1 +endi + +sql select derivative(k, 6m, 1) from tm0; +if $rows != 3 then + return -1 +endi + +sql_error select derivative(k, 6m, 1) from tm0 interval(1s); +sql_error select derivative(k, 6m, 1) from tm0 session(ts, 1s); +sql_error select derivative(k, 6m, 1) from tm0 group by k; + +sql drop table if exists tm0 +sql drop table if exists m1 + +sql create table m1 (ts timestamp, k double ) tags(a int); +sql create table if not exists t0 using m1 tags(1); +sql create table if not exists t1 using m1 tags(2); + +sql insert into t0 values('2020-1-1 1:1:1', 1); +sql insert into t0 values('2020-1-1 1:1:3', 3); +sql insert into t0 values('2020-1-1 1:2:4', 4); +sql insert into t0 values('2020-1-1 1:2:5', 5); +sql insert into t0 values('2020-1-1 1:2:6', 6); +sql insert into t0 values('2020-1-1 1:3:7', 7); +sql insert into t0 values('2020-1-1 1:3:8', 8); +sql insert into t0 values('2020-1-1 1:3:9', 9); +sql insert into t0 values('2020-1-1 1:4:10', 10); + +sql insert into t1 values('2020-1-1 1:1:2', 2); +print ===========================>td-4739 +sql select diff(val) from (select derivative(k, 1s, 0) val from t1); +if $rows != 0 then + return -1 +endi + +sql insert into t1 values('2020-1-1 1:1:4', 20); +sql insert into t1 values('2020-1-1 1:1:6', 200); +sql insert into t1 values('2020-1-1 1:1:8', 2000); +sql insert into t1 values('2020-1-1 1:1:10', 20000); + +sql_error select derivative(k, 1s, 0) from m1; +sql_error select derivative(k, 1s, 0) from m1 group by a; +sql_error select derivative(f1, 1s, 0) from (select k from t1); + +sql select derivative(k, 1s, 0) from m1 group by tbname +if $rows != 12 then + return -1 +endi + +if $data00 != @20-01-01 01:01:03.000@ then + return -1 +endi + +if $data01 != 1.000000000 then + return -1 +endi + +if $data02 != @t0@ then + return -1 +endi + +if $data10 != @20-01-01 01:02:04.000@ then + return -1 +endi + +if $data11 != 0.016393443 then + return -1 +endi + +if $data12 != t0 then + return -1 +endi + +if $data90 != @20-01-01 01:01:06.000@ then + return -1 +endi + +if $data91 != 90.000000000 then + return -1 +endi + +if $data92 != t1 then + return -1 +endi + +sql select derivative(test_column_alias_name, 1s, 0) from (select avg(k) test_column_alias_name from t1 interval(1s)); diff --git a/tests/script/general/parser/gendata.sh b/tests/script/general/parser/gendata.sh index f56fdc34680f6fda559136a68f34ad38ed406bbd..b2074147ca0a0a4483d19192b45d875ad24a1541 100755 --- a/tests/script/general/parser/gendata.sh +++ b/tests/script/general/parser/gendata.sh @@ -4,3 +4,5 @@ Cur_Dir=$(pwd) echo $Cur_Dir echo "'2020-1-1 1:1:1','abc','device',123,'9876', 'abc', 'net', 'mno', 'province', 'city', 'al'" >> ~/data.sql +echo "'2020-1-2 1:1:1','abc','device',123,'9876', 'abc', 'net', 'mno', 'province', 'city', 'al'" >> ~/data.sql +echo "'2020-1-3 1:1:1','abc','device',123,'9876', 'abc', 'net', 'mno', 'province', 'city', 'al'" >> ~/data.sql diff --git a/tests/script/general/parser/groupby.sim b/tests/script/general/parser/groupby.sim index 124e76e85cb7451fe5f0850985c5b30f90587fee..1fe19714bbd516c2e8938ce1290f04f8d2053839 100644 --- a/tests/script/general/parser/groupby.sim +++ b/tests/script/general/parser/groupby.sim @@ -654,53 +654,142 @@ if $data31 != @20-03-27 05:10:19.000@ then return -1 endi -#sql select irate(c) from st where t1="1" and ts >= '2020-03-27 04:11:17.732' and ts < '2020-03-27 05:11:17.732' interval(1m) sliding(15s) group by tbname,t1,t2; -#if $rows != 40 then -# return -1 -#endi -# -#if $data01 != 1.000000000 then -# return -1 -#endi -#if $data02 != t1 then -# return -1 -#endi -#if $data03 != 1 then -# return -1 -#endi -#if $data04 != 1 then -# return -1 -#endi -# -#if $data11 != 1.000000000 then -# return -1 -#endi -#if $data12 != t1 then -# return -1 -#endi -#if $data13 != 1 then -# return -1 -#endi -#if $data14 != 1 then -# return -1 -#endi -# -#sql select irate(c) from st where t1="1" and ts >= '2020-03-27 04:11:17.732' and ts < '2020-03-27 05:11:17.732' interval(1m) sliding(15s) group by tbname,t1,t2 limit 1; -#if $rows != 2 then -# return -1 -#endi -# -#if $data11 != 1.000000000 then -# return -1 -#endi -#if $data12 != t2 then -# return -1 -#endi -#if $data13 != 1 then -# return -1 -#endi -#if $data14 != 2 then -# return -1 -#endi +print ===============> +sql select stddev(c),c from st where t2=1 or t2=2 group by c; +if $rows != 4 then + return -1 +endi + +if $data00 != 0.000000000 then + return -1 +endi + +if $data01 != 1 then + return -1 +endi + +if $data10 != 0.000000000 then + return -1 +endi + +if $data11 != 2 then + return -1 +endi + +if $data20 != 0.000000000 then + return -1 +endi + +if $data21 != 3 then + return -1 +endi + +if $data30 != 0.000000000 then + return -1 +endi + +if $data31 != 4 then + return -1 +endi + +sql_error select irate(c) from st where t1="1" and ts >= '2020-03-27 04:11:17.732' and ts < '2020-03-27 05:11:17.732' interval(1m) sliding(15s) group by tbname,c; +sql select irate(c) from st where t1="1" and ts >= '2020-03-27 04:11:17.732' and ts < '2020-03-27 05:11:17.732' interval(1m) sliding(15s) group by tbname,t1,t2; +if $rows != 40 then + return -1 +endi + +if $data01 != 1.000000000 then + return -1 +endi +if $data02 != t1 then + return -1 +endi +if $data03 != 1 then + return -1 +endi +if $data04 != 1 then + return -1 +endi + +if $data11 != 1.000000000 then + return -1 +endi +if $data12 != t1 then + return -1 +endi +if $data13 != 1 then + return -1 +endi +if $data14 != 1 then + return -1 +endi + +sql select irate(c) from st where t1="1" and ts >= '2020-03-27 04:11:17.732' and ts < '2020-03-27 05:11:17.732' interval(1m) sliding(15s) group by tbname,t1,t2 limit 1; +if $rows != 2 then + return -1 +endi + +if $data11 != 1.000000000 then + return -1 +endi +if $data12 != t2 then + return -1 +endi +if $data13 != 1 then + return -1 +endi +if $data14 != 2 then + return -1 +endi + +sql create table m1 (ts timestamp, k int, f1 int) tags(a int); +sql create table tm0 using m1 tags(0); +sql create table tm1 using m1 tags(1); + +sql insert into tm0 values('2020-1-1 1:1:1', 1, 10); +sql insert into tm0 values('2020-1-1 1:1:2', 1, 20); +sql insert into tm1 values('2020-2-1 1:1:1', 2, 10); +sql insert into tm1 values('2020-2-1 1:1:2', 2, 20); + +system sh/exec.sh -n dnode1 -s stop -x SIGINT +sleep 100 +system sh/exec.sh -n dnode1 -s start +sleep 100 + +sql connect +sleep 100 +sql use group_db0; + +print =========================>TD-4894 +sql select count(*),k from m1 group by k; +if $rows != 2 then + return -1 +endi + +if $data00 != 2 then + return -1 +endi + +if $data01 != 1 then + return -1 +endi + +if $data10 != 2 then + return -1 +endi + +if $data11 != 2 then + return -1 +endi + +sql_error select count(*) from m1 group by tbname,k,f1; +sql_error select count(*) from m1 group by tbname,k,a; +sql_error select count(*) from m1 group by k, tbname; +sql_error select count(*) from m1 group by k,f1; +sql_error select count(*) from tm0 group by tbname; +sql_error select count(*) from tm0 group by a; +sql_error select count(*) from tm0 group by k,f1; + +sql_error select count(*),f1 from m1 group by tbname,k; system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/having.sim b/tests/script/general/parser/having.sim index ddafdd73293d75bc99380969d98c7fb986420a38..a8d2102befeabf70d70e3a361ad5e933f021ce4a 100644 --- a/tests/script/general/parser/having.sim +++ b/tests/script/general/parser/having.sim @@ -1,6 +1,6 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 -c walLevel -v 0 +system sh/cfg.sh -n dnode1 -c walLevel -v 1 system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 2 system sh/exec.sh -n dnode1 -s start diff --git a/tests/script/general/parser/having_child.sim b/tests/script/general/parser/having_child.sim index a38db3fe44e8857ba646128a856371468d723b2b..0fe5448869a5720a62550a88981114e737e4965b 100644 --- a/tests/script/general/parser/having_child.sim +++ b/tests/script/general/parser/having_child.sim @@ -306,41 +306,11 @@ endi sql_error select avg(f1),count(f1),sum(f1),twa(f1) from tb1 group by tbname having twa(f1) > 0; -sql select avg(f1),count(f1),sum(f1),twa(f1) from tb1 group by f1 having twa(f1) > 3; -if $rows != 1 then - return -1 -endi -if $data00 != 4.000000000 then - return -1 -endi -if $data01 != 2 then - return -1 -endi -if $data02 != 8 then - return -1 -endi -if $data03 != 4.000000000 then - return -1 -endi +sql_error select avg(f1),count(f1),sum(f1),twa(f1) from tb1 group by f1 having twa(f1) > 3; sql_error select avg(f1),count(f1),sum(f1),twa(f1) from tb1 group by tbname having sum(f1) > 0; -sql select avg(f1),count(f1),sum(f1),twa(f1) from tb1 group by f1 having sum(f1) = 4; -if $rows != 1 then - return -1 -endi -if $data00 != 2.000000000 then - return -1 -endi -if $data01 != 2 then - return -1 -endi -if $data02 != 4 then - return -1 -endi -if $data03 != 2.000000000 then - return -1 -endi +sql_error select avg(f1),count(f1),sum(f1),twa(f1) from tb1 group by f1 having sum(f1) = 4; sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 0; if $rows != 4 then diff --git a/tests/script/general/parser/import_file.sim b/tests/script/general/parser/import_file.sim index e9f0f1ed085cc75238681dc08b9601a8d591f6c4..cf11194ba7c3b805725a665c6f92d6bb465b9e4e 100644 --- a/tests/script/general/parser/import_file.sim +++ b/tests/script/general/parser/import_file.sim @@ -15,6 +15,8 @@ $inFileName = '~/data.csv' $numOfRows = 10000 system general/parser/gendata.sh +sql create table stbx (ts TIMESTAMP, collect_area NCHAR(12), device_id BINARY(16), imsi BINARY(16), imei BINARY(16), mdn BINARY(10), net_type BINARY(4), mno NCHAR(4), province NCHAR(10), city NCHAR(16), alarm BINARY(2)) tags(a int, b binary(12)); + sql create table tbx (ts TIMESTAMP, collect_area NCHAR(12), device_id BINARY(16), imsi BINARY(16), imei BINARY(16), mdn BINARY(10), net_type BINARY(4), mno NCHAR(4), province NCHAR(10), city NCHAR(16), alarm BINARY(2)) print ====== create tables success, starting import data @@ -23,13 +25,48 @@ sql import into tbx file '~/data.sql' sql select count(*) from tbx if $rows != 1 then + print expect 1, actual: $rows + return -1 +endi + +if $data00 != 3 then + return -1 +endi + +sql drop table tbx; + +sql insert into tbx using stbx tags(1,'abc') file '~/data.sql'; +sql insert into tbx using stbx tags(1,'abc') file '~/data.sql'; + +sql select count(*) from tbx +if $rows != 1 then + return -1 +endi + +if $data00 != 3 then return -1 endi -#if $data00 != $numOfRows then -# print "expect: $numOfRows, act: $data00" -# return -1 -#endi +sql drop table tbx; +sql insert into tbx using stbx(b) tags('abcf') file '~/data.sql'; + +sql select ts,a,b from tbx; +if $rows != 3 then + return -1 +endi + +if $data00 != @20-01-01 01:01:01.000@ then + print expect 20-01-01 01:01:01.000 , actual: $data00 + return -1 +endi + +if $data01 != NULL then + return -1 +endi + +if $data02 != @abcf@ then + return -1 +endi system rm -f ~/data.sql diff --git a/tests/script/general/parser/join_multitables.sim b/tests/script/general/parser/join_multitables.sim index acb8be10e7cf0f4a3f70828b1054d9552ca864c4..d675499640b890398859243d49cfb04d9e1e7579 100644 --- a/tests/script/general/parser/join_multitables.sim +++ b/tests/script/general/parser/join_multitables.sim @@ -1811,10 +1811,6 @@ if $data09 != 3 then return -1 endi - - - - sql select st0.*,st1.* from st0, st1 where st1.id1=st0.id1 and st0.ts=st1.ts and st1.ts=st0.ts and st0.id1=st1.id1 order by st0.ts limit 5 offset 5 if $rows != 5 then return -1 @@ -2294,7 +2290,6 @@ if $data19 != 9925 then return -1 endi - sql_error select tb0_1.*, tb1_1.* from tb0_1, tb1_1 where tb0_1.f1=tb1_1.f1; sql_error select tb0_1.*, tb1_1.* from tb0_1, tb1_1 where tb0_1.ts=tb1_1.ts and tb0_1.id1=tb1_1.id2; sql_error select tb0_5.*, tb1_5.*,tb2_5.*,tb3_5.*,tb4_5.*,tb5_5.*, tb6_5.*,tb7_5.*,tb8_5.*,tb9_5.*,tba_5.* from tb0_5, tb1_5, tb2_5, tb3_5, tb4_5,tb5_5, tb6_5, tb7_5, tb8_5, tb9_5, tba_5 where tb9_5.ts=tb8_5.ts and tb8_5.ts=tb7_5.ts and tb7_5.ts=tb6_5.ts and tb6_5.ts=tb5_5.ts and tb5_5.ts=tb4_5.ts and tb4_5.ts=tb3_5.ts and tb3_5.ts=tb2_5.ts and tb2_5.ts=tb1_5.ts and tb1_5.ts=tb0_5.ts and tb0_5.ts=tba_5.ts; @@ -2317,10 +2312,4 @@ sql_error select last(*) from st0, st1 where st0.ts=st1.ts and st0.id1=st1.id1 g sql_error select st0.*,st1.*,st2.*,st3.*,st4.*,st5.*,st6.*,st7.*,st8.*,st9.* from st0,st1,st2,st3,st4,st5,st6,st7,st8,st9 where st0.ts=st2.ts and st0.ts=st4.ts and st0.ts=st6.ts and st0.ts=st8.ts and st1.ts=st3.ts and st3.ts=st5.ts and st5.ts=st7.ts and st7.ts=st9.ts and st0.id1=st2.id1 and st0.id1=st4.id1 and st0.id1=st6.id1 and st0.id1=st8.id1 and st1.id1=st3.id1 and st3.id1=st5.id1 and st5.id1=st7.id1 and st7.id1=st9.id1; sql_error select st0.*,st1.*,st2.*,st3.*,st4.*,st5.*,st6.*,st7.*,st8.*,st9.* from st0,st1,st2,st3,st4,st5,st6,st7,st8,st9,sta where st0.ts=st2.ts and st0.ts=st4.ts and st0.ts=st6.ts and st0.ts=st8.ts and st1.ts=st3.ts and st3.ts=st5.ts and st5.ts=st7.ts and st7.ts=st9.ts and st0.ts=st1.ts and st0.id1=st2.id1 and st0.id1=st4.id1 and st0.id1=st6.id1 and st0.id1=st8.id1 and st1.id1=st3.id1 and st3.id1=st5.id1 and st5.id1=st7.id1 and st7.id1=st9.id1 and st0.id1=st1.id1 and st0.id1=sta.id1 and st0.ts=sta.ts; - - - - - - system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/join_multivnode.sim b/tests/script/general/parser/join_multivnode.sim index c72b2c5b3e4018c892f1194671b0d577c053c7f5..61438241b0cb943cf9d1df09799076cf7dbadeab 100644 --- a/tests/script/general/parser/join_multivnode.sim +++ b/tests/script/general/parser/join_multivnode.sim @@ -367,4 +367,4 @@ if $data35 != 5 then return -1 endi -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/last_cache.sim b/tests/script/general/parser/last_cache.sim index 9d7da9ddbabbd668382740a230ecc9582c27fe84..9c414263ecc65cc11327bbcfc7a79131984393b9 100644 --- a/tests/script/general/parser/last_cache.sim +++ b/tests/script/general/parser/last_cache.sim @@ -1,6 +1,6 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 -c walLevel -v 0 +system sh/cfg.sh -n dnode1 -c walLevel -v 1 system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 system sh/exec.sh -n dnode1 -s start @@ -9,7 +9,7 @@ sql connect print ======================== dnode1 start $db = testdb - +sql drop database if exists $db sql create database $db cachelast 2 sql use $db diff --git a/tests/script/general/parser/lastrow.sim b/tests/script/general/parser/lastrow.sim index 2b8f294d5d058f4b7cc8c45380862180e35a5899..7cdd04e2ccdb93c7e1f84298101d74e7c3af061f 100644 --- a/tests/script/general/parser/lastrow.sim +++ b/tests/script/general/parser/lastrow.sim @@ -70,4 +70,21 @@ sleep 100 run general/parser/lastrow_query.sim -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file +print =================== last_row + nested query +sql use $db +sql create table lr_nested(ts timestamp, f int) +sql insert into lr_nested values(now, 1) +sql insert into lr_nested values(now+1s, null) +sql select last_row(*) from (select * from lr_nested) +if $rows != 1 then + return -1 +endi +if $data01 != NULL then + return -1 +endi +sql select last_row(*) from (select f from lr_nested) +if $rows != 1 then + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/nestquery.sim b/tests/script/general/parser/nestquery.sim index 3d13ff504db8e86ceaed368b237e0a834987e53e..fe12972bf698aae9f7469ee5768852cb342bc6c3 100644 --- a/tests/script/general/parser/nestquery.sim +++ b/tests/script/general/parser/nestquery.sim @@ -124,10 +124,215 @@ if $rows != 2 then return -1 endi +sql select * from (select count(*) a, tbname f1 from nest_mt0 group by tbname) t where t.a<0 and f1 = 'nest_tb0'; +if $rows != 0 then + return -1 +endi + +sql select * from (select count(*) a, tbname f1 from nest_mt0 group by tbname) t where t.a>0 and f1 = 'nest_tb0'; +if $rows != 1 then + return -1 +endi + +if $data00 != 10000 then + return -1 +endi + +if $data01 != @nest_tb0@ then + return -1 +endi + +if $data02 != @nest_tb0@ then + return -1 +endi print ===================> nest query interval +sql_error select ts, avg(c1) from (select ts, c1 from nest_tb0); + +sql select avg(c1) from (select * from nest_tb0) interval(3d) +if $rows != 3 then + return -1 +endi + +if $data00 != @20-09-14 00:00:00.000@ then + return -1 +endi + +if $data01 != 49.222222222 then + return -1 +endi + +if $data10 != @20-09-17 00:00:00.000@ then + print expect 20-09-17 00:00:00.000, actual: $data10 + return -1 +endi + +if $data11 != 49.685185185 then + return -1 +endi + +if $data20 != @20-09-20 00:00:00.000@ then + return -1 +endi + +if $data21 != 49.500000000 then + return -1 +endi + +sql_error select stddev(c1) from (select c1 from nest_tb0); +sql_error select percentile(c1, 20) from (select * from nest_tb0); +sql_error select interp(c1) from (select * from nest_tb0); +sql_error select derivative(val, 1s, 0) from (select c1 val from nest_tb0); +sql_error select twa(c1) from (select c1 from nest_tb0); +sql_error select irate(c1) from (select c1 from nest_tb0); +sql_error select diff(c1), twa(c1) from (select * from nest_tb0); +sql_error select irate(c1), interp(c1), twa(c1) from (select * from nest_tb0); + +sql select apercentile(c1, 50) from (select * from nest_tb0) interval(1d) +if $rows != 7 then + return -1 +endi + +if $data00 != @20-09-15 00:00:00.000@ then + return -1 +endi + +if $data01 != 47.571428571 then + return -1 +endi + +if $data10 != @20-09-16 00:00:00.000@ then + return -1 +endi + +if $data11 != 49.666666667 then + return -1 +endi + +if $data20 != @20-09-17 00:00:00.000@ then + return -1 +endi +if $data21 != 49.000000000 then + return -1 +endi +if $data30 != @20-09-18 00:00:00.000@ then + return -1 +endi + +if $data31 != 48.333333333 then + return -1 +endi + +sql select twa(c1) from (select * from nest_tb0); +if $rows != 1 then + return -1 +endi + +if $data00 != 49.500000000 then + return -1 +endi + +sql select leastsquares(c1, 1, 1) from (select * from nest_tb0); +if $rows != 1 then + return -1 +endi + +if $data00 != @{slop:0.000100, intercept:49.000000}@ then + return -1 +endi + +sql select irate(c1) from (select * from nest_tb0); +if $data00 != 0.016666667 then + return -1 +endi + +sql select derivative(c1, 1s, 0) from (select * from nest_tb0); +if $rows != 9999 then + return -1 +endi + +if $data00 != @20-09-15 00:01:00.000@ then + return -1 +endi + +if $data01 != 0.016666667 then + return -1 +endi + +if $data10 != @20-09-15 00:02:00.000@ then + return -1 +endi + +if $data11 != 0.016666667 then + return -1 +endi + +sql select diff(c1) from (select * from nest_tb0); +if $rows != 9999 then + return -1 +endi + +sql select avg(c1),sum(c2), max(c3), min(c4), count(*), first(c7), last(c7),spread(c6) from (select * from nest_tb0) interval(1d); +if $rows != 7 then + return -1 +endi + +if $data00 != @20-09-15 00:00:00.000@ then + return -1 +endi + +if $data01 != 48.666666667 then + print expect 48.666666667, actual: $data01 + return -1 +endi + +if $data02 != 70080.000000000 then + return -1 +endi + +if $data03 != 99 then + return -1 +endi + +if $data04 != 0 then + return -1 +endi + +if $data05 != 1440 then + return -1 +endi + +if $data06 != 0 then + print $data06 + return -1 +endi + +if $data07 != 1 then + return -1 +endi + +if $data08 != 99.000000000 then + print expect 99.000000000, actual: $data08 + return -1 +endi + +if $data10 != @20-09-16 00:00:00.000@ then + return -1 +endi + +if $data11 != 49.777777778 then + return -1 +endi + +if $data12 != 71680.000000000 then + return -1 +endi + +sql select top(x, 20) from (select c1 x from nest_tb0); + +sql select bottom(x, 20) from (select c1 x from nest_tb0) print ===================> complex query @@ -137,6 +342,9 @@ print ===================> group by + having +print =========================> ascending order/descending order + + print =========================> nest query join @@ -203,4 +411,43 @@ if $data03 != @20-09-15 00:00:00.000@ then return -1 endi +sql select diff(val) from (select c1 val from nest_tb0); +if $rows != 9999 then + return -1 +endi + +if $data00 != @70-01-01 08:00:00.000@ then + return -1 +endi + +if $data01 != 1 then + return -1 +endi + +sql_error select last_row(*) from (select * from nest_tb0) having c1 > 0 + +print ===========>td-4805 +sql_error select tbname, i from (select * from nest_tb0) group by i; + +sql select count(*),c1 from (select * from nest_tb0) where c1 < 2 group by c1; +if $rows != 2 then + return -1 +endi + +if $data00 != 100 then + return -1 +endi + +if $data01 != 0 then + return -1 +endi + +if $data10 != 100 then + return -1 +endi + +if $data11 != 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/general/parser/precision_ns.sim b/tests/script/general/parser/precision_ns.sim new file mode 100644 index 0000000000000000000000000000000000000000..3e9a2dd3ffdcd1f15e05c28273af9484e33840d4 --- /dev/null +++ b/tests/script/general/parser/precision_ns.sim @@ -0,0 +1,113 @@ +system sh/stop_dnodes.sh + +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c walLevel -v 1 +system sh/exec.sh -n dnode1 -s start +sleep 1000 +sql connect + +$dbPrefix = m_di_db_ns +$tbPrefix = m_di_tb +$mtPrefix = m_di_mt +$ntPrefix = m_di_nt +$tbNum = 2 +$rowNum = 200 +$futureTs = 300000000000 + +print =============== step1: create database and tables and insert data +$i = 0 +$db = $dbPrefix . $i +$mt = $mtPrefix . $i +$nt = $ntPrefix . $i + +sql drop database $db -x step1 +step1: +sql create database $db precision 'ns' +sql use $db +sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol int) + +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i + sql create table $tb using $mt tags( $i ) + + $x = 0 + while $x < $rowNum + $cc = $futureTs + $x * 100 + 43 + $ns = $cc . b + sql insert into $tb values (now + $ns , $x ) + $x = $x + 1 + endw + + $i = $i + 1 +endw + +sql create table $nt (ts timestamp, tbcol int) +$x = 0 +while $x < $rowNum + $cc = $futureTs + $x * 100 + 43 + $ns = $cc . b + sql insert into $nt values (now + $ns , $x ) + $x = $x + 1 +endw + +sleep 100 + +print =============== step2: select count(*) from tables +$i = 0 +$tb = $tbPrefix . $i + +sql select count(*) from $tb + +if $data00 != $rowNum then + print expect $rowNum, actual:$data00 + return -1 +endi + +$i = 0 +$mt = $mtPrefix . $i +sql select count(*) from $mt + +$mtRowNum = $tbNum * $rowNum +if $data00 != $mtRowNum then + print expect $mtRowNum, actual:$data00 + return -1 +endi + +$i = 0 +$nt = $ntPrefix . $i + +sql select count(*) from $nt + +if $data00 != $rowNum then + print expect $rowNum, actual:$data00 + return -1 +endi + +print =============== step3: check nano second timestamp +$i = 0 +$mt = $mtPrefix . $i +$tb = $tbPrefix . $i +sql insert into $tb values (now-43b , $x ) +sql select count(*) from $tb where tssafty check TD-4927 +sql select first(ts, c1) from sr_stb where ts<1 group by t1; +sql select first(ts, c1) from sr_stb where ts>0 and ts<1; \ No newline at end of file diff --git a/tests/script/general/parser/timestamp_query.sim b/tests/script/general/parser/timestamp_query.sim index 4e553c73f41cc9d28025c5de08935af02ee10335..3f6a1af4bc552d0bb54aedcb086e035c3b73bfd2 100644 --- a/tests/script/general/parser/timestamp_query.sim +++ b/tests/script/general/parser/timestamp_query.sim @@ -24,6 +24,8 @@ $tsu = $tsu + $ts0 print ==================>issue #3481, normal column not allowed, sql_error select ts,c1,min(c2) from ts_stb0 +print ==================>issue #4681, not equal operator on primary timestamp not allowed +sql_error select * from ts_stb0 where ts <> $ts0 ##### select from supertable $tb = $tbPrefix . 0 @@ -51,4 +53,4 @@ sql select first(c1), last(c1), (1537325400 - 1537146000)/(5*60) v from $tb wher if $data13 != 598.000000000 then print expect 598.000000000, actual $data03 return -1 -endi \ No newline at end of file +endi diff --git a/tests/script/general/parser/top_groupby.sim b/tests/script/general/parser/top_groupby.sim new file mode 100644 index 0000000000000000000000000000000000000000..5709f4d1d7210761292d59aefa8984dad2fd2f23 --- /dev/null +++ b/tests/script/general/parser/top_groupby.sim @@ -0,0 +1,52 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c walLevel -v 0 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 2 +system sh/exec.sh -n dnode1 -s start + +sleep 100 +sql connect +print ======================== dnode1 start + +$db = testdb + +sql create database $db +sql use $db + +sql create stable st2 (ts timestamp, f1 int, f2 float, f3 double, f4 bigint, f5 smallint, f6 tinyint, f7 bool, f8 binary(10), f9 nchar(10)) tags (id1 int, id2 float, id3 nchar(10), id4 double, id5 smallint, id6 bigint, id7 binary(10)) + +sql create table tb1 using st2 tags (1,1.0,"1",1.0,1,1,"1"); + +sql insert into tb1 values (now-200s,1,1.0,1.0,1,1,1,true,"1","1") +sql insert into tb1 values (now-100s,2,2.0,2.0,2,2,2,true,"2","2") +sql insert into tb1 values (now,3,3.0,3.0,3,3,3,true,"3","3") +sql insert into tb1 values (now+100s,4,4.0,4.0,4,4,4,true,"4","4") +sql insert into tb1 values (now+200s,4,4.0,4.0,4,4,4,true,"4","4") +sql insert into tb1 values (now+300s,4,4.0,4.0,4,4,4,true,"4","4") +sql insert into tb1 values (now+400s,4,4.0,4.0,4,4,4,true,"4","4") +sql insert into tb1 values (now+500s,4,4.0,4.0,4,4,4,true,"4","4") + +sql select top(f1, 2) from tb1 group by f1; + +if $rows != 5 then + return -1 +endi + +sql select bottom(f1, 2) from tb1 group by f1; + +if $rows != 5 then + return -1 +endi + +sql select top(f1, 100) from tb1 group by f1; + +if $rows != 8 then + return -1 +endi + +sql select bottom(f1, 100) from tb1 group by f1; + +if $rows != 8 then + return -1 +endi + diff --git a/tests/script/general/parser/topbot.sim b/tests/script/general/parser/topbot.sim index 5c61acb2ba246f1f0102ed01b90e0b164ebfa8dc..ddab1b3f83acfc4fc454740093c3e4e003bab3d4 100644 --- a/tests/script/general/parser/topbot.sim +++ b/tests/script/general/parser/topbot.sim @@ -175,7 +175,7 @@ if $data21 != 2.10000 then endi print =====================td-1302 case -sql create database t1 keep 36500; +sql create database t1 keep 36500 sql use t1; sql create table test(ts timestamp, k int); sql insert into test values(29999, 1)(70000, 2)(80000, 3) @@ -194,7 +194,7 @@ if $rows != 3 then endi print ==============>td-1308 -sql create database db keep 36500; +sql create database db keep 36500 sql use db; sql create table stb (ts timestamp, c1 int, c2 binary(10)) tags(t1 binary(10)); @@ -377,4 +377,4 @@ sql_error select * from ttm2 where k<>null sql_error select * from ttm2 where k like null sql_error select * from ttm2 where k td-4783,td-4792 +sql create table where_ts(ts timestamp, f int) +sql insert into where_ts values('2021-06-19 16:22:00', 1); +sql insert into where_ts values('2021-06-19 16:23:00', 2); +sql insert into where_ts values('2021-06-19 16:24:00', 3); +sql insert into where_ts values('2021-06-19 16:25:00', 1); +sql select * from (select * from where_ts) where ts<'2021-06-19 16:25:00' and ts>'2021-06-19 16:22:00' +if $rows != 2 then + return -1 +endi +print $data00, $data01 +if $data01 != 2 then + return -1 +endi +sql insert into where_ts values(now, 5); +sleep 10 +sql select * from (select * from where_ts) where ts