homework-jianmu/tests/script/tsim/view/query_view.sim

133 lines
3.2 KiB
Plaintext

sql connect
sql use testa;
sql create view view1 as select * from sta1;
sql select * from view1 order by ts;
if $rows != 4 then
return -1
endi
if $data00 != @23-10-16 09:10:11.000@ then
return -1
endi
if $data01 != 100111 then
return -1
endi
sql create or replace view view1 as select 1, 2;
sql select * from view1;
if $rows != 1 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data01 != 2 then
return -1
endi
sql create or replace view view1 as select tbname as a, f from sta1;
sql select cast(avg(f) as int) b from view1 group by a having avg(f) > 100111 order by b;
if $rows != 3 then
return -1
endi
if $data00 != 100112 then
return -1
endi
if $data10 != 100113 then
return -1
endi
if $data20 != 100114 then
return -1
endi
#sql create or replace view view1 as select tbname, avg(f) from sta1 partition by tbname;
#sql select * from view1 partition by view1.tbname;
sql create or replace view view1 as select * from sta1;
sql create or replace view testb.view2 as select * from testb.stb1;
sql_error select avg(t1.f), avg(t2.f) from view1 t1, view2 t2 where t1.ts = t2.ts and t1.f < 100114;
sql select avg(t1.f), avg(t2.f) from view1 t1, testb.view2 t2 where t1.ts = t2.ts and t1.f < 100114;
if $rows != 1 then
return -1
endi
if $data00 != 100112.000000000 then
print $data00
return -1
endi
if $data01 != 110112.000000000 then
return -1
endi
sql drop view testb.view2;
sql create or replace view view2 as select * from st2;
sql select avg(view1.f), avg(view2.f) from view1, view2 where view1.ts = view2.ts and view1.f < 100114;
if $rows != 1 then
return -1
endi
if $data00 != 100112.000000000 then
print $data00
return -1
endi
if $data01 != 100222.000000000 then
return -1
endi
sql drop view view1;
sql drop view view2;
sql create view view1 as select * from sta1;
sql create view view2 as select * from st2;
sql create view view3 as select a.ts ts, a.f af, b.f bf from view1 a join view2 b on a.ts = b.ts;
sql create view view3a as select a.ts ts, a.f, b.f from view1 a join view2 b on a.ts = b.ts;
sql create view view4 as select _wstart, avg(bf) - avg(af) as b from view3 interval(1s);
sql_error create view view4a as select _wstart, avg(b.f) - avg(a.f) as b from view3 interval(1s);
sql create view view5 as select count(*),avg(b) from view4 interval(1s) having avg(b) > 0;
sql select * from view5;
if $rows != 4 then
return -1
endi
if $data00 != 1 then
print $data00
return -1
endi
if $data01 != 110.000000000 then
return -1
endi
sql drop view view1;
sql drop view view2;
sql drop view view3;
sql drop view view3a;
sql drop view view4;
sql drop view view5;
sql use information_schema;
sql create view view1 as select * from ins_views;
sql select * from view1;
if $rows != 1 then
return -1
endi
sql drop view view1;
sql use testa;
sql create view information_schema.view1 as select * from information_schema.ins_views;
sql select * from information_schema.view1;
if $rows != 1 then
return -1
endi
sql drop view information_schema.view1;
sql use testa;
sql create view view1 as select * from st2;
sql use testb;
sql select f from testa.view1 order by f;
if $rows != 4 then
return -1
endi
if $data00 != 100221 then
print $data00
return -1
endi
if $data10 != 100222 then
return -1
endi
sql drop view testa.view1;