TDengine/tests/script/tsim/analytics/basic0.sim

271 lines
11 KiB
Text

system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/exec.sh -n dnode1 -s start
sql connect
print =============== failed to create anode on '127.0.0.1:1101'
sql_error create anode '127.0.0.1:1101'
sql show anodes
if $rows != 0 then
return -1
endi
sql_error drop anode 1
print ================ create anode
sql create anode '192.168.1.116:6050'
sql show anodes
if $rows != 1 then
return -1
endi
print =============== show info
sql show anodes full
if $rows != 13 then
print expect 13 , actual $rows
return -1
endi
print =============== create database
sql create database d0 vgroups 1
sql select * from information_schema.ins_databases
if $rows != 3 then
return -1
endi
print $data00 $data01 $data02
sql use d0
print =============== create super table, include column type for count/sum/min/max/first
sql create table if not exists stb (ts timestamp, c1 int, c2 float, c3 double, c4 tinyint, c5 bigint, c6 varchar(12)) tags (t1 int unsigned)
sql show stables
if $rows != 1 then
return -1
endi
print =============== create child table
sql create table ct1 using stb tags(1000)
print ==================== insert data
# input_list = [5, 14, 15, 15, 14, 19, 17, 16, 20, 22, 8, 21, 28, 11, 9, 29, 40]
sql insert into ct1(ts, c1, c2, c3, c4, c5, c6) values(now-1a, 5, 5, 5, 5, 5, 'a')(now+1a, 14, 14, 14, 14, 14, 'a')(now+2a, 15, 15, 15, 15, 15, 'a')
sql insert into ct1 values(now+3a, 15, 15, 15, 15, 15, 'a')(now+4a, 14, 14, 14, 14, 14, 'a')(now+5a, 19, 19, 19, 19, 19, 'a')(now+6a, 17, 17, 17, 17, 17, 'a')
sql insert into ct1 values(now+7a, 16, 16, 16, 16, 16, 'a')
print ==================== not enough rows
sql_error select forecast(c6, 'algo=holtwinters, rows=10') from ct1;
sql insert into ct1 values(now+8a, 20, 20, 20, 20, 20, 'a')(now+9a, 22, 22, 22, 22, 22, 'a')
sql insert into ct1 values(now+10a, 8, 8, 8, 8, 8, 'a')(now+11a, 21, 21, 21, 21, 21, 'a')(now+12a, 28, 28, 28, 28, 28, 'a')(now+13a, 11, 11, 11, 11, 11, 'a')(now+14a, 9, 9, 9, 9, 9, 'a')
sql insert into ct1 values(now+15a, 29, 29, 29, 29, 29, 'a')(now+16a, 40, 40, 40, 40, 40, 'a')
sql select count(*) from ct1
if $data00 != 17 then
print expect 17 , actual $data00
return -1
endi
sql select count(*) from ct1 anomaly_window(c1, 'algo=iqr')
if $data00 != 1 then
return -1
endi
print ================= too many rows error
sql_error select forecast(c6, 'algo=holtwinters, rows=1025') from ct1;
print ================= try every loaded anomaly detection algorithm
sql select count(*) from ct1 anomaly_window(c1, 'algo=iqr');
sql select count(*) from ct1 anomaly_window(c1, 'algo=ksigma');
sql select count(*) from ct1 anomaly_window(c1, 'algo=lof');
sql select count(*) from ct1 anomaly_window(c1, 'algo=shesd');
sql select count(*) from ct1 anomaly_window(c1, 'algo=grubbs');
print ================= try every column type of column
sql select count(*) from ct1 anomaly_window(c1, 'algo=ksigma,k=2');
sql select count(*) from ct1 anomaly_window(c2, 'algo=ksigma,k=2');
sql select count(*) from ct1 anomaly_window(c3, 'algo=ksigma,k=2');
sql select count(*) from ct1 anomaly_window(c4, 'algo=ksigma,k=2');
sql select count(*) from ct1 anomaly_window(c5, 'algo=ksigma,k=2');
print =================== invalid column type
sql_error select count(*) from ct1 anomaly_window(c6, 'algo=ksigma,k=2');
sql_error select forecast(c6, 'algo=holtwinters,conf=0.5,wncheck=1,period=0') from ct1
print ==================== invalid timeout parameter, will reset the parameters.
sql select forecast(c1, 'algo=holtwinters, timeout=6000') from ct1;
sql select forecast(c1, 'algo=holtwinters, timeout=0') from ct1;
print =========================== valid timeout
sql select forecast(c1, 'algo=holtwinters, timeout=120') from ct1;
#sql_error select _frowts, _flow, _fhigh, forecast(c1, 'algo=holtwinters,conf=0,wncheck=1,period=0') from ct1
#sql_error select _frowts, _flow, _fhigh, forecast(c1, 'algo=holtwinters,conf=1.1,wncheck=1,period=0') from ct1
#sql_error select _frowts, _flow, _fhigh, forecast(c1, 'algo=holtwinters1,conf=50,wncheck=1,period=0') from ct1
sql_error select forecast(c1, 'conf=0.5 ,algo = arima, rows=0') from ct1
sql_error select forecast(c1, 'conf=0.5 ,algo = arima, rows=-10') from ct1
sql_error select forecast(c1, 'conf=0.5 ,algo = arima, every=0') from ct1
#sql_error select forecast(c1, 'conf=0.5 ,algo = arima') from ct1
sql select _frowts, _flow, _fhigh, forecast(c1, 'algo=holtwinters, conf=0.5 ') from ct1
sql select _frowts, _flow, _fhigh, forecast(c1, ' algo=holtwinters , conf=0.5 ') from ct1
sql select _frowts, _flow, _fhigh, forecast(c1, ' algo = holtwinters , conf = 0.5 ') from ct1
sql select _frowts, _flow, _fhigh, forecast(c1, 'conf=0.5 ,algo = holtwinters, ') from ct1
sql select _frowts, _flow, _fhigh, forecast(c1, 'conf=0.5 ,algo = holtwinters, ,') from ct1
sql select _frowts, _flow, _fhigh, forecast(c1, 'conf=0.5 ,algo = holtwinters, , ,') from ct1
sql select _frowts, _flow, _fhigh, forecast(c1, 'conf=0.5 ,algo = holtwinters, a =') from ct1
sql_error select _frowts, _flow, _fhigh, forecast(c1, 'conf=0.5 ,algo = holtwinters, = a ,') from ct1
print =================== valid column type
sql select forecast(c1, 'conf=0.5 ,algo = arima') from ct1
sql select forecast(c1, 'conf=0.5 ,algo = arima, rows=1') from ct1
sql select forecast(c2, 'conf=0.5 ,algo = arima, rows=1') from ct1
sql select forecast(c3, 'conf=0.5 ,algo = arima, rows=1') from ct1
sql select forecast(c4, 'conf=0.5 ,algo = arima, rows=1') from ct1
sql select forecast(c5, 'conf=0.5 ,algo = arima, rows=1') from ct1
sql select forecast(c5, 'conf=0.5 ,algo = arima, rows=1') from ct1
sql select _frowts, _flow, _fhigh, forecast(c1, 'algo=holtwinters,conf=0.5,wncheck=1,period=0,start=1700000000000,every=2') from ct1
if $rows != 10 then
return -1
endi
if $data03 != @28.784811943@ then
print expect 28.784811943 get $data03
return -1
endi
if $data00 != @23-11-15 06:13:20.000@ then
print expect 23-11-15 06:13:20.000 , actual $data00
return -1
endi
if $data10 != @23-11-15 06:13:20.002@ then
print expect 23-11-15 06:13:20.002 , actual $data10
return -1
endi
if $data20 != @23-11-15 06:13:20.004@ then
return -1
endi
print test the every option and rows option
sql select _frowts, _flow, _fhigh, forecast(c1, 'algo=holtwinters,conf=0.5,wncheck=1,period=0,start=1700000000000,every=100,rows=5') from ct1
if $rows != 5 then
return -1
endi
if $data00 != @23-11-15 06:13:20.000@ then
return -1
endi
if $data10 != @23-11-15 06:13:20.100@ then
return -1
endi
print ==================== forecast on table with primary key
sql create table if not exists pkstb (ts timestamp, c1 int primary key, c2 float, c3 int) tags (t1 int unsigned)
sql create table pk_stb_ct1 using pkstb tags(1);
sql create table pk_stb_ct2 using pkstb tags(2);
sql create table pk_stb_ct3 using pkstb tags(3);
sql insert into pk_stb_ct1 values(now, 1, 1.0, 10)
sql insert into pk_stb_ct1 values(now+1s, 1, 2.0, 11)
sql insert into pk_stb_ct1 values(now+2s, 1, 3.0, 12)
sql insert into pk_stb_ct1 values(now+3s, 1, 4.0, 13)
sql insert into pk_stb_ct1 values(now+4s, 1, 5.0, 14)
sql insert into pk_stb_ct1 values(now+5s, 1, 6.0, 15)
sql insert into pk_stb_ct1 values(now+6s, 1, 7.0, 16)
sql insert into pk_stb_ct1 values(now+7s, 1, 8.0, 17)
sql insert into pk_stb_ct1 values(now+8s, 1, 9.0, 18)
sql insert into pk_stb_ct1 values(now+9s, 1, 10.0, 19)
sql insert into pk_stb_ct1 values(now+10s, 1, 11.0, 20)
sql insert into pk_stb_ct1 values(now+11s, 1, 12.0, 21)
sql select forecast(c2) from pk_stb_ct1;
sql select forecast(c2, 'algo=arima') from pk_stb_ct1;
sql_error select forecast(c2, c3) from pk_stb_ct1;
sql_error select forecast(c2, c3, 'algo=arima') from pk_stb_ct1;
print ==================== co-variate query test and future co-variate query test
sql select forecast(c2, c3, c1, 'algo=moirai') from pk_stb_ct1;
sql select forecast(c2, c2, c3, 'algo=moirai') from pk_stb_ct1;
sql select forecast(c2, c2, c2, c2, 'algo=moirai') from pk_stb_ct1;
sql select forecast(c2, c2, c2, c2, 'algo=holtwinters') from pk_stb_ct1;
# not exist column
sql_error select forecast(c2, c3, c1, c4, 'algo=moirai') from pk_stb_ct1;
# not support algorithm
sql_error select forecast(c2, c3, c1, 'algo=holtwinters') from pk_stb_ct1;
#rows not match
sql_error select forecast(c2, c3, c1, 'algo=moirai,dynamic_real_1=[1 1 1 1], rows=22') from pk_stb_ct1;
# missing columns in future dynamic real parameter
sql_error select forecast(c2, c3, c1, 'algo=moirai, dynamic_real_100=[1 1 1],rows=3,dynamic_real_100_col=c4') from pk_stb_ct1;
# name mismatch
sql_error select forecast(c2, c3, c1, 'algo=moirai, dynamic_real_100=[1 1 1],rows=3,dynamic_real_100_col=c2') from pk_stb_ct1;
# name mismatch
sql_error select forecast(c2, c3, c1, 'algo=moirai, dynamic_real_100=[1 1 1],rows=3,dynamic_real_1_col=c1') from pk_stb_ct1;
# invalid input - 1
sql_error select forecast(c2, c3, c1, 'algo=moirai, dynamic_real_100=(1 1 1),rows=3,dynamic_real_1_col=c1') from pk_stb_ct1;
# invalid input - 2
sql_error select forecast(c2, c3, c1, 'algo=moirai, dynamic_real_100=[1, 1, 1],rows=3,dynamic_real_1_col=c1') from pk_stb_ct1;
# invalid input - 3
sql_error select forecast(c2, c3, c1, 'algo=moirai, dynamic_real_100=["abc"],rows=1,dynamic_real_1_col=c1') from pk_stb_ct1;
sql_error select forecast(c2, c3, c1, 'algo=moirai, dynamic_real_100=[1 110 31.92],rows=abc,dynamic_real_x_col=c1') from pk_stb_ct1;
print ============== future dynamic real column test
sql select forecast(c2, c3, c1, 'algo=moirai, dynamic_real_100=[1 1 1],rows=3,dynamic_real_100_col=c3') from pk_stb_ct1;
if $rows != 3 then
return -1
endi
print ============== too long parameter test
sql select forecast(c2, c3, c1, 'algo=moirai, dynamic_real_100=[10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000],rows=100,dynamic_real_100_col=c3') from pk_stb_ct1;
if $rows != 100 then
return -1
endi
sql drop anode 1
sql show anodes
if $rows != 0 then
return -1
endi
sleep 1000
print ===================== query without anodes
sql_error select forecast(c5, 'conf=0.5 ,algo = arima, rows=1') from ct1
sql_error select count(*) from ct1 anomaly_window(c1, 'algo=iqr');
_OVER:
system sh/exec.sh -n dnode1 -s stop -x SIGINT
print =============== check
$null=
system_content sh/checkValgrind.sh -n dnode1
print cmd return result ----> [ $system_content ]
if $system_content > 0 then
return -1
endi
if $system_content == $null then
return -1
endi