tdSql.execute(" create table ttb1 using st2 tags(1)")
tdSql.execute(" create table ttb2 using 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 ttb1 values({ts_value} , {i})")
tdSql.execute(f" insert into ttb2 values({ts_value} , {i})")
tdSql.query("select stateduration(tb1.num,'GT',1,1s) from tb1, tb2 where tb1.ts=tb2.ts ")
tdSql.checkRows(10)
tdSql.checkData(0,0,-1)
tdSql.checkData(1,0,-1)
tdSql.checkData(2,0,0)
tdSql.checkData(9,0,7)
tdSql.query("select stateduration(tb1.num,'GT',1,1s) from tb1, tb2 where tb1.ts=tb2.ts union all select stateduration(tb2.num,'GT',1,1s) from tb1, 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 stateduration(c1,'GT',1,1s) c1 from t1)")
tdSql.checkRows(12)
tdSql.checkData(0,0,None)
tdSql.checkData(1,0,-1)
tdSql.checkData(2,0,0)
tdSql.checkData(10,0,63072035)
tdSql.query("select sum(c1) from (select stateduration(c1,'GT',1,1d) c1 from t1)")
tdSql.checkRows(1)
tdSql.checkData(0,0,2893)
tdSql.query("select sum(c1) from (select distinct(c1) c1 from ct1) union all select sum(c1) from (select stateduration(c1,'GT',1,1s) c1 from ct1)")
tdSql.checkRows(2)
tdSql.query("select 1-abs(c1) from (select stateduration(c1,'GT',1,1s) c1 from t1)")
tdSql.checkRows(12)
tdSql.checkData(0,0,None)
tdSql.checkData(1,0,0.000000000)
tdSql.checkData(3,0,-86404.000000000)
# bug for stable
#partition by tbname
# tdSql.query(" select unique(c1) from stb1 partition by tbname ")
# tdSql.checkRows(21)
# tdSql.query(" select unique(c1) from stb1 partition by tbname ")
# tdSql.checkRows(21)
# group by
tdSql.error("select stateduration(c1,'GT',1,1s) from ct1 group by c1")
tdSql.error("select stateduration(c1,'GT',1,1s) 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.query("select stateduration(c1,'GT',1,1s) from t1")
tdSql.checkData(10,0,63072035)
tdSql.query("select stateduration(c1,'GT',1,1000s) from t1")
tdSql.checkData(10,0,int(63072035/1000))
tdSql.query("select stateduration(c1,'GT',1,1m) from t1")
tdSql.checkData(10,0,int(63072035/60))
tdSql.query("select stateduration(c1,'GT',1,1h) from t1")
tdSql.checkData(10,0,int(63072035/60/60))
tdSql.query("select stateduration(c1,'GT',1,1d) from t1")
tdSql.checkData(10,0,int(63072035/60/24/60))
tdSql.query("select stateduration(c1,'GT',1,1w) from t1")
tdSql.checkData(10,0,int(63072035/60/7/24/60))
defcheck_boundary_values(self):
tdSql.execute("drop database if exists bound_test")
tdSql.execute("create database if not exists bound_test")
tdSql.execute(" create table ttb1 using st2 tags(1)")
tdSql.execute(" create table ttb2 using 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 ttb1 values({ts_value} , {i})")
tdSql.execute(f" insert into ttb2 values({ts_value} , {i})")
tdSql.query("select statecount(tb1.num,'GT',1) from tb1, 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.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.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.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.checkRows(2)
tdSql.query("select 1-abs(c1) from (select statecount(c1,'GT',1) c1 from t1)")
tdSql.checkRows(12)
tdSql.checkData(0,0,None)
tdSql.checkData(1,0,0.000000000)
tdSql.checkData(3,0,-1.000000000)
# bug for stable
#partition by tbname
# tdSql.query(" select unique(c1) from stb1 partition by tbname ")
# tdSql.checkRows(21)
# tdSql.query(" select unique(c1) from stb1 partition by tbname ")
# tdSql.checkRows(21)
# group by
tdSql.query("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.query("select stateduration(c1,'GT',1,1s) from t1")
tdSql.checkData(10,0,63072035)
tdSql.query("select stateduration(c1,'GT',1,1000s) from t1")
tdSql.checkData(10,0,int(63072035/1000))
tdSql.query("select stateduration(c1,'GT',1,1m) from t1")
tdSql.checkData(10,0,int(63072035/60))
tdSql.query("select stateduration(c1,'GT',1,1h) from t1")
tdSql.checkData(10,0,int(63072035/60/60))
tdSql.query("select stateduration(c1,'GT',1,1d) from t1")
tdSql.checkData(10,0,int(63072035/60/24/60))
tdSql.query("select stateduration(c1,'GT',1,1w) from t1")
tdSql.checkData(10,0,int(63072035/60/7/24/60))
defcheck_boundary_values(self):
tdSql.execute("drop database if exists bound_test")
tdSql.execute("create database if not exists bound_test")