tdSql.execute("create table t1(ts timestamp, i int, b bigint, f float, d double, bin binary(10), s smallint, t tinyint, bl bool, n nchar(10), ts1 timestamp)")
foriinrange(1,1001):
hs,ms=self.genTime(i)
ifi<500:
ret=tdSql.execute("insert into t1(ts, i, b) values (\"2021-11-22 %s:%s:00\", %d, 1)"%(hs,ms,i))
else:
ret=tdSql.execute("insert into t1(ts, i, b) values (\"2021-11-22 %s:%s:00\", %d, 0)"%(hs,ms,i))
tdSql.query("select count(*) from t1")
tdSql.checkEqual(int(tdSql.getData(0,0)),1000)
# empty normal table
tdSql.execute("create table t2(ts timestamp, i int, b bigint, f float, d double, bin binary(10), s smallint, t tinyint, bl bool, n nchar(10), ts1 timestamp)")
tdSql.execute("create table t1 (ts timestamp, f float)")
tdSql.execute("insert into t1 values('2021-11-18 00:00:00.000000100', 1)"
"('2021-11-18 00:00:00.000000200', 2)"
"('2021-11-18 00:00:00.000000300', 3)"
"('2021-11-18 00:00:00.000000500', 4)")
# super table
tdSql.execute("use wxy_db")
tdSql.execute("create stable st1(ts timestamp, i int, b bigint, f float, d double, bin binary(10), s smallint, t tinyint, bl bool, n nchar(10), ts1 timestamp) tags(id int)")
tdSql.execute("create table st1s1 using st1 tags(1)")
tdSql.execute("create table st1s2 using st1 tags(2)")
foriinrange(1,1001):
hs,ms=self.genTime(i)
if0==i%2:
ret=tdSql.execute("insert into st1s1(ts, i) values (\"2021-11-22 %s:%s:00\", %d)"%(hs,ms,i))
else:
ret=tdSql.execute("insert into st1s2(ts, i) values (\"2021-11-22 %s:%s:00\", %d)"%(hs,ms,i))
tdSql.query("select count(*) from st1s1")
tdSql.checkEqual(int(tdSql.getData(0,0)),500)
tdSql.query("select count(*) from st1s2")
tdSql.checkEqual(int(tdSql.getData(0,0)),500)
# empty super table
tdSql.execute("create stable st2(ts timestamp, i int, b bigint, f float, d double, bin binary(10), s smallint, t tinyint, bl bool, n nchar(10), ts1 timestamp) tags(id int)")
tdSql.execute("create table st2s1 using st1 tags(1)")
tdSql.execute("create table st2s2 using st1 tags(2)")
tdSql.execute("create stable st3(ts timestamp, i int, b bigint, f float, d double, bin binary(10), s smallint, t tinyint, bl bool, n nchar(10), ts1 timestamp) tags(id int)")
"where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00'")
tdSql.checkRows(1)
tdSql.checkCols(5)
tdSql.checkEqual(int(tdSql.getData(0,2)),0)
tdSql.query("select elapsed(ts) from st1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00' group by tbname")
tdSql.checkRows(2)
tdSql.checkCols(2)# append tbname
tdSql.query("select elapsed(ts, 10m) from st1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00' group by tbname")
tdSql.checkEqual(int(tdSql.getData(0,0)),99)
tdSql.checkEqual(int(tdSql.getData(1,0)),99)
tdSql.query("select elapsed(ts), elapsed(ts, 10m), elapsed(ts, 100m) from st1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00' group by tbname")
subtableDesc=self.splitStableResult(sql+" order by ts desc",elapsedCol,tbnameCol)
forkvinsubtableAsc.items():
descValue=subtableDesc.get(kv[0])
ifNone==descValue:
tdLog.exit("%s failed: subtable %s not exists"%(sql))
else:
self.doOrderbyCheck(kv[1],descValue)
# Orderby clause only changes the output order and has no effect on the calculation results.
deforderbyTest(self):
tdSql.execute("use wxy_db")
self.orderbyCheck("select elapsed(ts) from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00'",0)
self.orderbyCheck("select elapsed(ts) from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00' interval(40s)",1)
self.orderbyCheck("select elapsed(ts) from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00' interval(1m)",1)
self.orderbyCheck("select elapsed(ts) from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00' interval(10m)",1)
self.orderbyCheck("select elapsed(ts) from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00' interval(150m)",1)
self.orderbyCheck("select elapsed(ts) from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00' interval(222m)",1)
self.orderbyCheck("select elapsed(ts) from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00' interval(1000m)",1)
self.orderbyForStableCheck("select elapsed(ts) from st1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00' group by tbname",0,1)
self.orderbyForStableCheck("select elapsed(ts) from st1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00' interval(40s) group by tbname",1,2)
self.orderbyForStableCheck("select elapsed(ts) from st1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00' interval(1m) group by tbname",1,2)
self.orderbyForStableCheck("select elapsed(ts) from st1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00' interval(10m) group by tbname",1,2)
self.orderbyForStableCheck("select elapsed(ts) from st1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00' interval(150m) group by tbname",1,2)
self.orderbyForStableCheck("select elapsed(ts) from st1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00' interval(222m) group by tbname",1,2)
self.orderbyForStableCheck("select elapsed(ts) from st1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00' interval(1000m) group by tbname",1,2)