tdSql.execute(" create table ttb1 using st2 tags(1)")
tdSql.execute(" create table ttb2 using st2 tags(2)")
tdSql.execute(f"create stable {dbname}.st2 (ts timestamp , num int) tags(ind int)")
tdSql.execute(f"create table {dbname}.ttb1 using {dbname}.st2 tags(1)")
tdSql.execute(f"create table {dbname}.ttb2 using {dbname}.st2 tags(2)")
start_ts=1622369635000# 2021-05-30 18:13:55
foriinrange(10):
ts_value=start_ts+i*1000
tdSql.execute(f" insert into tb1 values({ts_value} , {i})")
tdSql.execute(f" insert into tb2 values({ts_value} , {i})")
tdSql.execute(f" insert into {dbname}.tb1 values({ts_value} , {i})")
tdSql.execute(f" insert into {dbname}.tb2 values({ts_value} , {i})")
tdSql.execute(f" insert into ttb1 values({ts_value} , {i})")
tdSql.execute(f" insert into ttb2 values({ts_value} , {i})")
tdSql.execute(f" insert into {dbname}.ttb1 values({ts_value} , {i})")
tdSql.execute(f" insert into {dbname}.ttb2 values({ts_value} , {i})")
tdSql.query("select statecount(tb1.num,'GT',1) from tb1, tb2 where tb1.ts=tb2.ts ")
tdSql.query(f"select statecount(tb1.num,'GT',1) from {dbname}.tb1 tb1, {dbname}.tb2 tb2 where tb1.ts=tb2.ts ")
tdSql.checkRows(10)
tdSql.checkData(0,0,-1)
tdSql.checkData(1,0,-1)
tdSql.checkData(2,0,1)
tdSql.checkData(9,0,8)
tdSql.query("select statecount(tb1.num,'GT',1) from tb1, tb2 where tb1.ts=tb2.ts union all select statecount(tb2.num,'GT',1) from tb1, tb2 where tb1.ts=tb2.ts ")
tdSql.query(f"select statecount(tb1.num,'GT',1) from {dbname}.tb1 tb1, {dbname}.tb2 tb2 where tb1.ts=tb2.ts union all select statecount(tb2.num,'GT',1) from {dbname}.tb1 tb1, {dbname}.tb2 tb2 where tb1.ts=tb2.ts ")
tdSql.checkRows(20)
# nest query
# tdSql.query("select unique(c1) from (select c1 from ct1)")
tdSql.query("select c1 from (select statecount(c1,'GT',1) c1 from t1)")
# tdSql.query(f"select unique(c1) from (select c1 from {dbname}.ct1)")
tdSql.query(f"select c1 from (select statecount(c1,'GT',1) c1 from {dbname}.t1)")
tdSql.checkRows(12)
tdSql.checkData(0,0,None)
tdSql.checkData(1,0,-1)
tdSql.checkData(2,0,1)
tdSql.checkData(10,0,8)
tdSql.query("select sum(c1) from (select statecount(c1,'GT',1) c1 from t1)")
tdSql.query(f"select sum(c1) from (select statecount(c1,'GT',1) c1 from {dbname}.t1)")
tdSql.checkRows(1)
tdSql.checkData(0,0,35)
tdSql.query("select sum(c1) from (select distinct(c1) c1 from ct1) union all select sum(c1) from (select statecount(c1,'GT',1) c1 from ct1)")
tdSql.query(f"select sum(c1) from (select distinct(c1) c1 from {dbname}.ct1) union all select sum(c1) from (select statecount(c1,'GT',1) c1 from {dbname}.ct1)")
tdSql.checkRows(2)
tdSql.query("select 1-abs(c1) from (select statecount(c1,'GT',1) c1 from t1)")
tdSql.query(f"select 1-abs(c1) from (select statecount(c1,'GT',1) c1 from {dbname}.t1)")
tdSql.checkRows(12)
tdSql.checkData(0,0,None)
tdSql.checkData(1,0,0.000000000)
...
...
@@ -365,43 +360,41 @@ class TDTestCase:
# bug for stable
#partition by tbname
# tdSql.query(" select unique(c1) from stb1 partition by tbname ")
# tdSql.query(f"select unique(c1) from {dbname}.stb1 partition by tbname ")
# tdSql.checkRows(21)
# tdSql.query(" select unique(c1) from stb1 partition by tbname ")
# tdSql.query(f"select unique(c1) from {dbname}.stb1 partition by tbname ")
# tdSql.checkRows(21)
# group by
tdSql.error("select statecount(c1,'GT',1) from ct1 group by c1")
tdSql.error("select statecount(c1,'GT',1) from ct1 group by tbname")
# super table
defcheck_unit_time(self):
tdSql.execute(" use db ")
tdSql.error("select stateduration(c1,'GT',1,1b) from ct1")
tdSql.error("select stateduration(c1,'GT',1,1u) from ct1")
tdSql.error("select stateduration(c1,'GT',1,1000s) from t1")
tdSql.error("select stateduration(c1,'GT',1,10m) from t1")
tdSql.error("select stateduration(c1,'GT',1,10d) from t1")
tdSql.query("select stateduration(c1,'GT',1,1s) from t1")
tdSql.error(f"select statecount(c1,'GT',1) from {dbname}.ct1 group by c1")
tdSql.error(f"select statecount(c1,'GT',1) from {dbname}.ct1 group by tbname")
defcheck_unit_time(self,dbname="db"):
tdSql.error(f"select stateduration(c1,'GT',1,1b) from {dbname}.ct1")
tdSql.error(f"select stateduration(c1,'GT',1,1u) from {dbname}.ct1")
tdSql.error(f"select stateduration(c1,'GT',1,1000s) from {dbname}.t1")
tdSql.error(f"select stateduration(c1,'GT',1,10m) from {dbname}.t1")
tdSql.error(f"select stateduration(c1,'GT',1,10d) from {dbname}.t1")
tdSql.query(f"select stateduration(c1,'GT',1,1s) from {dbname}.t1")
tdSql.checkData(10,0,63072035)
tdSql.query("select stateduration(c1,'GT',1,1m) from t1")
tdSql.query(f"select stateduration(c1,'GT',1,1m) from {dbname}.t1")
tdSql.checkData(10,0,int(63072035/60))
tdSql.query("select stateduration(c1,'GT',1,1h) from t1")
tdSql.query(f"select stateduration(c1,'GT',1,1h) from {dbname}.t1")
tdSql.checkData(10,0,int(63072035/60/60))
tdSql.query("select stateduration(c1,'GT',1,1d) from t1")
tdSql.query(f"select stateduration(c1,'GT',1,1d) from {dbname}.t1")
tdSql.checkData(10,0,int(63072035/60/24/60))
tdSql.query("select stateduration(c1,'GT',1,1w) from t1")
tdSql.query(f"select stateduration(c1,'GT',1,1w) from {dbname}.t1")
tdSql.checkData(10,0,int(63072035/60/7/24/60))
defquery_precision(self):
defgenerate_data(precision="ms"):
tdSql.execute("create database if not exists db_%s precision '%s';"%(precision,precision))
dbname=f"db_{precision}"
tdSql.execute(f"create database if not exists db_%s precision '%s';"%(precision,precision))
tdSql.execute("use db_%s;"%precision)
tdSql.execute("create stable db_%s.st (ts timestamp , id int) tags(ind int);"%precision)
tdSql.execute("create table db_%s.tb1 using st tags(1);"%precision)
tdSql.execute("create table db_%s.tb2 using st tags(2);"%precision)
tdSql.execute(f"create stable db_%s.st (ts timestamp , id int) tags(ind int);"%precision)
tdSql.execute(f"create table db_%s.tb1 using {dbname}.st tags(1);"%precision)
tdSql.execute(f"create table db_%s.tb2 using {dbname}.st tags(2);"%precision)
ifprecision=="ms":
start_ts=self.ts
...
...
@@ -432,55 +425,54 @@ class TDTestCase:
ifpres=="ms":
ifunitin["1u","1b"]:
tdSql.error("select stateduration(id,'GT',1,%s) from db_%s.tb1 "%(unit,pres))
tdSql.error(f"select stateduration(id,'GT',1,%s) from db_%s.tb1 "%(unit,pres))
pass
else:
tdSql.query("select stateduration(id,'GT',1,%s) from db_%s.tb1 "%(unit,pres))
tdSql.query(f"select stateduration(id,'GT',1,%s) from db_%s.tb1 "%(unit,pres))
elifpres=="us"andunitin["1b"]:
ifunitin["1b"]:
tdSql.error("select stateduration(id,'GT',1,%s) from db_%s.tb1 "%(unit,pres))
tdSql.error(f"select stateduration(id,'GT',1,%s) from db_%s.tb1 "%(unit,pres))
pass
else:
tdSql.query("select stateduration(id,'GT',1,%s) from db_%s.tb1 "%(unit,pres))
tdSql.query(f"select stateduration(id,'GT',1,%s) from db_%s.tb1 "%(unit,pres))
else:
tdSql.query("select stateduration(id,'GT',1,%s) from db_%s.tb1 "%(unit,pres))
tdSql.query(f"select stateduration(id,'GT',1,%s) from db_%s.tb1 "%(unit,pres))
tdSql.query("select c1, tan(10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) from ct1")# bigint to double data overflow
tdSql.query(f"select c1, tan(10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) from {dbname}.ct1")# bigint to double data overflow
defabs_func_filter(self):
tdSql.execute("use db")
tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(tan(c1)-0.5) from ct4 where c1>5 ")
defabs_func_filter(self,dbname="db"):
tdSql.query(f"select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(tan(c1)-0.5) from {dbname}.ct4 where c1>5 ")
tdSql.checkRows(3)
tdSql.checkData(0,0,8)
tdSql.checkData(0,1,8.000000000)
...
...
@@ -378,7 +374,7 @@ class TDTestCase:
tdSql.checkData(0,3,7.900000000)
tdSql.checkData(0,4,-7.000000000)
tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(tan(c1)-0.5) from ct4 where c1=5 ")
tdSql.query(f"select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(tan(c1)-0.5) from {dbname}.ct4 where c1=5 ")
tdSql.checkRows(1)
tdSql.checkData(0,0,5)
tdSql.checkData(0,1,5.000000000)
...
...
@@ -386,7 +382,7 @@ class TDTestCase:
tdSql.checkData(0,3,4.900000000)
tdSql.checkData(0,4,-3.000000000)
tdSql.query("select c1,c2 , abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(tan(c1)-0.5) from ct4 where c1>tan(c1) limit 1 ")
tdSql.query(f"select c1,c2 , abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(tan(c1)-0.5) from {dbname}.ct4 where c1>tan(c1) limit 1 ")
self.check_result_auto_tan("select abs(c1), abs(c2), abs(c3) , abs(c4), abs(c5) from sub1_bound ","select tan(abs(c1)), tan(abs(c2)) ,tan(abs(c3)), tan(abs(c4)), tan(abs(c5)) from sub1_bound")
self.check_result_auto_tan("select c1, c2, c3 , c3, c2 ,c1 from sub1_bound ","select tan(c1), tan(c2) ,tan(c3), tan(c3), tan(c2) ,tan(c1) from sub1_bound")
self.check_result_auto_tan(f"select abs(c1), abs(c2), abs(c3) , abs(c4), abs(c5) from {dbname}.sub1_bound ",f"select tan(abs(c1)), tan(abs(c2)) ,tan(abs(c3)), tan(abs(c4)), tan(abs(c5)) from {dbname}.sub1_bound")
self.check_result_auto_tan(f"select c1, c2, c3 , c3, c2 ,c1 from {dbname}.sub1_bound ",f"select tan(c1), tan(c2) ,tan(c3), tan(c3), tan(c2) ,tan(c1) from {dbname}.sub1_bound")
self.check_result_auto_tan(f"select abs(abs(abs(abs(abs(abs(abs(abs(abs(c1))))))))) nest_col_func from {dbname}.sub1_bound",f"select tan(abs(c1)) from {dbname}.sub1_bound")
self.check_result_auto_tan("select abs(abs(abs(abs(abs(abs(abs(abs(abs(c1))))))))) nest_col_func from sub1_bound","select tan(abs(c1)) from sub1_bound")
tdSql.execute(f'create table {dbname}.tb1 using {dbname}.st tags (1)')
tdSql.execute(f'create table {dbname}.tb2 using {dbname}.st tags (2)')
tdSql.execute(f'create table {dbname}.tb3 using {dbname}.st tags (3)')
tdSql.execute(f'insert into {dbname}.tb1 values (now()-40s, {PI/2}, {PI/2})')
tdSql.execute(f'insert into {dbname}.tb1 values (now()-30s, {PI}, {PI})')
tdSql.execute(f'insert into {dbname}.tb1 values (now()-20s, {PI*1.5}, {PI*1.5})')
tdSql.execute(f'insert into {dbname}.tb1 values (now()-10s, {PI*2}, {PI*2})')
tdSql.execute(f'insert into {dbname}.tb1 values (now(), {PI*2.5}, {PI*2.5})')
tdSql.execute(f'insert into {dbname}.tb2 values (now()-40s, {PI/2}, {PI/2})')
tdSql.execute(f'insert into {dbname}.tb2 values (now()-30s, {PI}, {PI})')
tdSql.execute(f'insert into {dbname}.tb2 values (now()-20s, {PI*1.5}, {PI*1.5})')
tdSql.execute(f'insert into {dbname}.tb2 values (now()-10s, {PI*2}, {PI*2})')
tdSql.execute(f'insert into {dbname}.tb2 values (now(), {PI*2.5}, {PI*2.5})')
foriinrange(100):
tdSql.execute('insert into tb3 values (now()+{}s, {}, {})'.format(i,PI*(5+i)/2,PI*(5+i)/2))
tdSql.execute(f'insert into tb3 values (now()+{i}s, {PI*(5+i)/2}, {PI*(5+i)/2})')
self.check_result_auto_tan("select num1,num2 from tb3;","select tan(num1),tan(num2) from tb3")
self.check_result_auto_tan(f"select num1,num2 from {dbname}.tb3;",f"select tan(num1),tan(num2) from {dbname}.tb3")
defsupport_super_table_test(self):
tdSql.execute(" use db ")
self.check_result_auto_tan(" select c5 from stb1 order by ts ","select tan(c5) from stb1 order by ts")
self.check_result_auto_tan(" select c5 from stb1 order by tbname ","select tan(c5) from stb1 order by tbname")
self.check_result_auto_tan(" select c5 from stb1 where c1 > 0 order by tbname ","select tan(c5) from stb1 where c1 > 0 order by tbname")
self.check_result_auto_tan(" select c5 from stb1 where c1 > 0 order by tbname ","select tan(c5) from stb1 where c1 > 0 order by tbname")
defsupport_super_table_test(self,dbname="db"):
self.check_result_auto_tan(f"select c5 from {dbname}.stb1 order by ts ",f"select tan(c5) from {dbname}.stb1 order by ts")
self.check_result_auto_tan(f"select c5 from {dbname}.stb1 order by tbname ",f"select tan(c5) from {dbname}.stb1 order by tbname")
self.check_result_auto_tan(f"select c5 from {dbname}.stb1 where c1 > 0 order by tbname ",f"select tan(c5) from {dbname}.stb1 where c1 > 0 order by tbname")
self.check_result_auto_tan(f"select c5 from {dbname}.stb1 where c1 > 0 order by tbname ",f"select tan(c5) from {dbname}.stb1 where c1 > 0 order by tbname")
self.check_result_auto_tan(" select t1,c5 from stb1 order by ts ","select tan(t1), tan(c5) from stb1 order by ts")
self.check_result_auto_tan(" select t1,c5 from stb1 order by tbname ","select tan(t1) ,tan(c5) from stb1 order by tbname")
self.check_result_auto_tan(" select t1,c5 from stb1 where c1 > 0 order by tbname ","select tan(t1) ,tan(c5) from stb1 where c1 > 0 order by tbname")
self.check_result_auto_tan(" select t1,c5 from stb1 where c1 > 0 order by tbname ","select tan(t1) , tan(c5) from stb1 where c1 > 0 order by tbname")
self.check_result_auto_tan(f"select t1,c5 from {dbname}.stb1 order by ts ",f"select tan(t1), tan(c5) from {dbname}.stb1 order by ts")
self.check_result_auto_tan(f"select t1,c5 from {dbname}.stb1 order by tbname ",f"select tan(t1) ,tan(c5) from {dbname}.stb1 order by tbname")
self.check_result_auto_tan(f"select t1,c5 from {dbname}.stb1 where c1 > 0 order by tbname ",f"select tan(t1) ,tan(c5) from {dbname}.stb1 where c1 > 0 order by tbname")
self.check_result_auto_tan(f"select t1,c5 from {dbname}.stb1 where c1 > 0 order by tbname ",f"select tan(t1) , tan(c5) from {dbname}.stb1 where c1 > 0 order by tbname")