fix test cases
This commit is contained in:
parent
da09e9ef16
commit
870fbd467e
|
@ -23,18 +23,18 @@ class TDTestCase:
|
|||
def init(self, conn, logSql):
|
||||
tdLog.debug("start to execute %s" % __file__)
|
||||
tdSql.init(conn.cursor(), logSql)
|
||||
|
||||
|
||||
self.ts = 1420041600000 # 2015-01-01 00:00:00 this is begin time for first record
|
||||
self.num = 10
|
||||
|
||||
def caseDescription(self):
|
||||
|
||||
'''
|
||||
case1 <wenzhouwww>: [TD-11804] test case for elapsed function :
|
||||
|
||||
this test case is for aggregate function elapsed , elapsed function can only used for the timestamp primary key column (ts) ,
|
||||
case1 <wenzhouwww>: [TD-11804] test case for elapsed function :
|
||||
|
||||
this test case is for aggregate function elapsed , elapsed function can only used for the timestamp primary key column (ts) ,
|
||||
it has two input parameters, the first parameter is necessary, basic SQL as follow:
|
||||
|
||||
|
||||
===================================================================================================================================
|
||||
SELECT ELAPSED(field_name[, time_unit]) FROM { tb_name | stb_name } [WHERE clause] [INTERVAL(interval [, offset]) [SLIDING sliding]];
|
||||
===================================================================================================================================
|
||||
|
@ -49,18 +49,18 @@ class TDTestCase:
|
|||
case: select * from table|stable[group by tbname]|regular_table
|
||||
|
||||
case:select elapsed(ts) from table|stable where clause interval (units) [fill(LINEAR,NEXT,PREV,VALUE,NULL)] [group by tbname] order [by ts desc asc|desc];
|
||||
|
||||
|
||||
case:select elapsed(ts) , elapsed(ts,unit_time1)*regular_num1 , elapsed(ts,unit_time1)+regular_num2 from table|stable where clause interval (units) [fill(LINEAR,NEXT,PREV,VALUE,NULL)] [group by tbname] order [by ts desc asc|desc];
|
||||
|
||||
|
||||
//mixup with all functions only once query (it's different with nest query)
|
||||
case:select elapsed(ts), count(*), avg(col), twa(col), irate(col), sum(col), stddev(col), leastsquares(col, 1, 1),min(col), max(col), first(col), last(col), percentile(col, 20), apercentile(col, 30), last_row(col), spread(col)from table|stable where clause interval (units) [fill(LINEAR,NEXT,PREV,VALUE,NULL)] [group by tbname] order [by ts desc asc|desc];
|
||||
|
||||
//mixup with ordinary col
|
||||
|
||||
//mixup with ordinary col
|
||||
case:select ts ,elapsed(ts)*10 ,col+5 from table|stable where clause interval (units) [fill(LINEAR,NEXT,PREV,VALUE,NULL)] [group by tbname] order [by ts desc asc|desc];
|
||||
|
||||
|
||||
//nest query
|
||||
case:select elapsed(ts) from (select elapsed(ts), count(*), avg(col), twa(col), irate(col), sum(col), stddev(col), leastsquares(col, 1, 1),min(col), max(col), first(col), last(col), percentile(col, 20), apercentile(col, 30), last_row(col), spread(col)from table|stable where clause interval (units) [fill(LINEAR,NEXT,PREV,VALUE,NULL)] [group by tbname] order [by ts desc asc|desc]) where clause interval (units) [fill(LINEAR,NEXT,PREV,VALUE,NULL)] [group by tbname] order [by ts desc asc|desc];
|
||||
|
||||
|
||||
//clause about filter condition
|
||||
case:select elapsed(ts) from table|stable[group by tbname] where [ts|col|tag >|<|=|>=|<=|=|<>|!= value] | [between ... and ...] |[in] |[is null|not null] interval (unit_time) ;
|
||||
case:select elapsed(ts) from table|stable[group by tbname] where clause1 and clause 2 and clause3 interval (unit_time) ;
|
||||
|
@ -74,7 +74,7 @@ class TDTestCase:
|
|||
// Window aggregation
|
||||
|
||||
case:select elapsed(ts) from t1 where clause session(ts, time_units) ;
|
||||
case:select elapsed(ts) from t1 where clause state_window(regular_nums);
|
||||
case:select elapsed(ts) from t1 where clause state_window(regular_nums);
|
||||
|
||||
// Continuous query
|
||||
case:create table select elapsed(ts) ,avg(col) from (select elapsed(ts) ts_inter ,avg(col) col from stable|table interval (unit_time) [fill(LINEAR,NEXT,PREV,VALUE,NULL)][group by tbname]) interval (unit_time) [fill(LINEAR,NEXT,PREV,VALUE,NULL) sliding(unit_time_windows);
|
||||
|
@ -83,13 +83,13 @@ class TDTestCase:
|
|||
|
||||
this test case notice successful execution and correctness of results.
|
||||
|
||||
'''
|
||||
return
|
||||
'''
|
||||
return
|
||||
|
||||
def prepare_data(self):
|
||||
|
||||
tdLog.info (" ====================================== prepare data ==================================================")
|
||||
|
||||
|
||||
tdSql.execute('drop database if exists testdb ;')
|
||||
tdSql.execute('create database testdb keep 36500;')
|
||||
tdSql.execute('use testdb;')
|
||||
|
@ -120,14 +120,14 @@ class TDTestCase:
|
|||
tdSql.execute('create table regular_table_1 (ts timestamp , tscol timestamp ,q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double, bin_chars binary(20)) ;')
|
||||
tdSql.execute('create table regular_table_2 (ts timestamp , tscol timestamp ,q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , bin_chars binary(20)) ;')
|
||||
tdSql.execute('create table regular_table_3 (ts timestamp , tscol timestamp ,q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , bin_chars binary(20)) ;')
|
||||
|
||||
|
||||
tablenames = ["sub_table1_1","sub_table1_2","sub_table1_3","sub_table2_1","sub_table2_2","sub_table2_3","regular_table_1","regular_table_2","regular_table_3"]
|
||||
|
||||
tdLog.info("insert into records ")
|
||||
|
||||
for tablename in tablenames:
|
||||
|
||||
for i in range(self.num):
|
||||
for i in range(self.num):
|
||||
sql= 'insert into %s values(%d, %d,%d, %d, %d, %d, %f, %f, "%s")' % (tablename,self.ts + i*10000, self.ts + i*10,2147483647-i, 9223372036854775807-i, 32767-i, 127-i, i, i,("bintest"+str(i)))
|
||||
print(sql)
|
||||
tdSql.execute(sql)
|
||||
|
@ -144,7 +144,7 @@ class TDTestCase:
|
|||
"(ts,2d+3m-2s,NULL)","(ts+10d,NULL)" ,"(ts,now -1m%1d)","(ts+10d,_c0)","(ts+10d,)","(ts,%)","(ts, , m)","(ts,abc)","(ts,/)","(ts,*)","(ts,1s,100)",
|
||||
"(ts,1s,abc)","(ts,1s,_c0)","(ts,1s,*)","(ts,1s,NULL)","(ts,,_c0)","(ts,tbname,ts)","(ts,0,tbname)","('2021-11-18 00:00:10')","('2021-11-18 00:00:10', 1s)",
|
||||
"('2021-11-18T00:00:10+0800', '1s')","('2021-11-18T00:00:10Z', '1s')","('2021-11-18T00:00:10+0800', 10000000d,)","('ts', ,2021-11-18T00:00:10+0800, )"]
|
||||
|
||||
|
||||
for tablename in tablenames:
|
||||
for abnormal_param in abnormal_list:
|
||||
|
||||
|
@ -191,7 +191,7 @@ class TDTestCase:
|
|||
def query_filter(self):
|
||||
|
||||
tdLog.info (" ====================================== elapsed query filter ==================================================")
|
||||
|
||||
|
||||
for i in range(self.num):
|
||||
ts_start_time = self.ts + i*10000
|
||||
ts_col_start_time = self.ts + i*10
|
||||
|
@ -210,7 +210,7 @@ class TDTestCase:
|
|||
tdSql.query(filter_sql)
|
||||
tdSql.checkRows(1)
|
||||
tdSql.checkData(0,0,float(self.num -i-1))
|
||||
|
||||
|
||||
|
||||
filter_sql = "select elapsed(ts,10s) from stable_1 where ts >= %d and tscol >= %d and tstag='2015-01-01 00:01:00'group by tbname " %(ts_start_time,ts_col_start_time)
|
||||
tdSql.query(filter_sql)
|
||||
|
@ -224,7 +224,7 @@ class TDTestCase:
|
|||
|
||||
filter_sql = "select elapsed(ts,10s) from stable_1 where ts >= %d and tscol > %d and tstag='2015-01-01 00:01:00' group by tbname" %(ts_start_time,ts_col_start_time)
|
||||
tdSql.query(filter_sql)
|
||||
|
||||
|
||||
if i == self.num-1:
|
||||
tdSql.checkRows(0)
|
||||
else:
|
||||
|
@ -233,7 +233,7 @@ class TDTestCase:
|
|||
|
||||
filter_sql = "select elapsed(ts,10s) from sub_table1_1 where ts >= %d and tscol > %d " %(ts_start_time,ts_col_start_time)
|
||||
tdSql.query(filter_sql)
|
||||
|
||||
|
||||
if i == self.num-1:
|
||||
tdSql.checkRows(0)
|
||||
else:
|
||||
|
@ -268,7 +268,7 @@ class TDTestCase:
|
|||
|
||||
filter_sql = "select elapsed(ts,10s) from stable_1 where ts < %d and tscol <= %d and tstag < '2015-01-01 00:01:00' group by tbname" %(ts_end_time,ts_col_end_time)
|
||||
tdSql.query(filter_sql)
|
||||
|
||||
|
||||
if i == self.num-1:
|
||||
tdSql.checkRows(0)
|
||||
else:
|
||||
|
@ -277,7 +277,7 @@ class TDTestCase:
|
|||
|
||||
filter_sql = "select elapsed(ts,10s) from sub_table1_1 where ts < %d and tscol <= %d " %(ts_end_time,ts_col_end_time)
|
||||
tdSql.query(filter_sql)
|
||||
|
||||
|
||||
if i == self.num-1:
|
||||
tdSql.checkRows(0)
|
||||
else:
|
||||
|
@ -303,7 +303,7 @@ class TDTestCase:
|
|||
else:
|
||||
tdSql.checkRows(1)
|
||||
tdSql.checkData(0,0,float(self.num - i - 2))
|
||||
|
||||
|
||||
filter_sql = "select elapsed(ts,10s) from stable_1 where ts = %d and tscol < %d group by tbname " %(ts_end_time,ts_col_end_time)
|
||||
tdSql.query(filter_sql)
|
||||
tdSql.checkRows(0)
|
||||
|
@ -331,10 +331,10 @@ class TDTestCase:
|
|||
else:
|
||||
tdSql.checkRows(1)
|
||||
tdSql.checkData(0,0,float(self.num -i-2))
|
||||
|
||||
|
||||
filter_sql = "select elapsed(ts,10s) from stable_1 where q_tinyint != %d and tscol <= %d group by tbname " %(i,ts_col_end_time)
|
||||
tdSql.query(filter_sql)
|
||||
|
||||
|
||||
if i == self.num:
|
||||
tdSql.checkRows(0)
|
||||
else:
|
||||
|
@ -345,7 +345,7 @@ class TDTestCase:
|
|||
|
||||
filter_sql = "select elapsed(ts,10s) from sub_table1_1 where q_tinyint != %d and tscol <= %d " %(i,ts_col_end_time)
|
||||
tdSql.query(filter_sql)
|
||||
|
||||
|
||||
if i == self.num:
|
||||
tdSql.checkRows(0)
|
||||
else:
|
||||
|
@ -374,7 +374,7 @@ class TDTestCase:
|
|||
|
||||
filter_sql = "select elapsed(ts,10s) from stable_1 where q_tinyint <> %d and tscol <= %d group by tbname " %(i,ts_col_end_time)
|
||||
tdSql.query(filter_sql)
|
||||
|
||||
|
||||
if i == self.num:
|
||||
tdSql.checkRows(0)
|
||||
else:
|
||||
|
@ -385,14 +385,14 @@ class TDTestCase:
|
|||
|
||||
filter_sql = "select elapsed(ts,10s) from sub_table1_1 where q_tinyint <> %d and tscol <= %d " %(i,ts_col_end_time)
|
||||
tdSql.query(filter_sql)
|
||||
|
||||
|
||||
if i == self.num:
|
||||
tdSql.checkRows(0)
|
||||
else:
|
||||
tdSql.checkRows(1)
|
||||
tdSql.checkData(0,0,float(self.num - i - 1))
|
||||
|
||||
# filter between and
|
||||
# filter between and
|
||||
tdSql.query("select elapsed(ts,10s) from sub_table1_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and q_tinyint between 125 and 127 and tscol <= '2015-01-01 00:01:00.000' ")
|
||||
tdSql.checkData(0,0,2)
|
||||
tdSql.query("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and \
|
||||
|
@ -401,7 +401,7 @@ class TDTestCase:
|
|||
tdSql.checkData(1,0,2)
|
||||
tdSql.checkData(2,0,2)
|
||||
|
||||
# filter in and or
|
||||
# filter in and or
|
||||
tdSql.query("select elapsed(ts,10s) from sub_table1_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and q_tinyint between 125 and 127 and tscol <= '2015-01-01 00:01:00.000' ")
|
||||
tdSql.checkData(0,0,2)
|
||||
|
||||
|
@ -424,7 +424,7 @@ class TDTestCase:
|
|||
tdSql.checkData(0,0,1)
|
||||
tdSql.checkData(1,0,1)
|
||||
tdSql.checkData(2,0,1)
|
||||
|
||||
|
||||
tdSql.query("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars like 'bintest_' and tscol <= '2015-01-01 00:01:00.000' group by tbname ")
|
||||
tdSql.checkData(0,0,6)
|
||||
tdSql.checkData(1,0,6)
|
||||
|
@ -477,16 +477,16 @@ class TDTestCase:
|
|||
tdSql.checkRows(0)
|
||||
tdSql.query("select elapsed(ts,10s)*10 from sub_empty_2 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(prev);")
|
||||
tdSql.checkRows(0)
|
||||
|
||||
|
||||
for i in range(self.num):
|
||||
ts_start_time = self.ts + i*10000
|
||||
ts_col_start_time = self.ts + i*10
|
||||
ts_tag_time = "2015-01-01 00:01:00"
|
||||
ts_end_time = self.ts + (self.num-1-i)*10000
|
||||
ts_col_end_time = self.ts + (self.num-1-i)*10
|
||||
|
||||
|
||||
# only interval
|
||||
|
||||
# only interval
|
||||
interval_sql = "select elapsed(ts,10s) from stable_1 where ts <=%d interval(10s) group by tbname " %(ts_start_time)
|
||||
tdSql.query(interval_sql)
|
||||
tdSql.checkRows(3*(i+1))
|
||||
|
@ -499,10 +499,10 @@ class TDTestCase:
|
|||
tdSql.checkData(x,1,0)
|
||||
else :
|
||||
tdSql.checkData(x,1,1)
|
||||
|
||||
|
||||
# interval and fill , fill_type = ["NULL","value,100","prev","next","linear"]
|
||||
|
||||
# interval (10s) and time range is outer records
|
||||
# interval (10s) and time range is outer records
|
||||
|
||||
tdSql.query("select elapsed(ts,10s)*10 from stable_empty where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(prev) group by tbname;")
|
||||
tdSql.checkRows(0)
|
||||
|
@ -552,8 +552,8 @@ class TDTestCase:
|
|||
tdSql.checkData(59,1,2)
|
||||
tdSql.checkData(60,1,10)
|
||||
tdSql.checkData(61,1,10)
|
||||
|
||||
# interval (20s) and time range is outer records
|
||||
|
||||
# interval (20s) and time range is outer records
|
||||
tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(20s) fill(prev) group by tbname,ind ;")
|
||||
tdSql.checkRows(90)
|
||||
tdSql.checkData(0,1,20)
|
||||
|
@ -562,7 +562,7 @@ class TDTestCase:
|
|||
tdSql.checkData(29,1,10)
|
||||
tdSql.checkData(30,1,20)
|
||||
tdSql.checkData(31,1,20)
|
||||
|
||||
|
||||
tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(20s) fill(next) group by tbname,ind ;")
|
||||
tdSql.checkRows(90)
|
||||
tdSql.checkData(0,1,20)
|
||||
|
@ -589,7 +589,7 @@ class TDTestCase:
|
|||
tdSql.checkData(29,1,None)
|
||||
tdSql.checkData(30,1,20)
|
||||
tdSql.checkData(31,1,20)
|
||||
|
||||
|
||||
tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(20s) fill(value ,2) group by tbname,ind ;")
|
||||
tdSql.checkRows(90)
|
||||
tdSql.checkData(0,1,20)
|
||||
|
@ -599,7 +599,7 @@ class TDTestCase:
|
|||
tdSql.checkData(30,1,20)
|
||||
tdSql.checkData(31,1,20)
|
||||
|
||||
# interval (20s) and time range is in records
|
||||
# interval (20s) and time range is in records
|
||||
|
||||
tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) fill(prev) group by tbname,ind ;")
|
||||
tdSql.checkRows(9)
|
||||
|
@ -689,7 +689,7 @@ class TDTestCase:
|
|||
tdSql.checkData(19,1,10)
|
||||
tdSql.checkData(20,1,20)
|
||||
tdSql.checkData(25,1,0)
|
||||
|
||||
|
||||
def query_mix_common(self):
|
||||
|
||||
tdLog.info (" ======================================elapsed mixup with common col, it will not support =======================================")
|
||||
|
@ -730,7 +730,7 @@ class TDTestCase:
|
|||
tdSql.checkData(0,0,data[0][index])
|
||||
|
||||
tdSql.query("select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) from stable_1 group by tbname; ")
|
||||
|
||||
|
||||
# Arithmetic with elapsed for common table
|
||||
|
||||
operators = ["+" ,"-" , "*" ,"/" ,"%"]
|
||||
|
@ -743,9 +743,9 @@ class TDTestCase:
|
|||
sql_common= "select "
|
||||
|
||||
for index , query in enumerate(querys_oper):
|
||||
|
||||
|
||||
query_data = tdSql.getResult("select %s from sub_table1_1;"%query)
|
||||
|
||||
|
||||
query_datas.append(query_data[0][0])
|
||||
sql_common += " %s %s " %(query,operator)
|
||||
sql_common=sql_common[:-2] + " from sub_table1_1;"
|
||||
|
@ -753,7 +753,7 @@ class TDTestCase:
|
|||
tdSql.query(sql_common)
|
||||
results= query_datas[0]
|
||||
if operator == "+":
|
||||
for data in query_datas[1:]:
|
||||
for data in query_datas[1:]:
|
||||
results += data
|
||||
tdSql.checkData(0,0,results)
|
||||
|
||||
|
@ -794,9 +794,9 @@ class TDTestCase:
|
|||
sql_common= "select "
|
||||
|
||||
for index , query in enumerate(querys_oper):
|
||||
|
||||
|
||||
query_data = tdSql.getResult("select %s from stable_1 group by tbname;"%query)
|
||||
|
||||
|
||||
query_datas.append(query_data[0][0])
|
||||
sql_common += " %s %s " %(query,operator)
|
||||
sql_common=sql_common[:-2] + " from stable_1 group by tbname;"
|
||||
|
@ -804,7 +804,7 @@ class TDTestCase:
|
|||
tdSql.query(sql_common)
|
||||
results= query_datas[0]
|
||||
if operator == "+":
|
||||
for data in query_datas[1:]:
|
||||
for data in query_datas[1:]:
|
||||
results += data
|
||||
tdSql.checkData(0,0,results)
|
||||
tdSql.checkData(1,0,results)
|
||||
|
@ -849,9 +849,9 @@ class TDTestCase:
|
|||
|
||||
querys = ["max(q_int)","min(q_int)" , "first(q_tinyint)", "first(*)","last(q_int)","last(*)","PERCENTILE(q_int,10)","APERCENTILE(q_int,10)","elapsed(ts,10s)"]
|
||||
|
||||
|
||||
|
||||
querys_mix = ["max(q_int)","min(q_int)" , "first(q_tinyint)", "first(q_int)","last(q_int)","PERCENTILE(q_int,10)","APERCENTILE(q_int,10)","elapsed(ts,10s)"]
|
||||
|
||||
|
||||
tdSql.query("select max(q_int),min(q_int) , first(q_tinyint), first(q_int),last(q_int),PERCENTILE(q_int,10),APERCENTILE(q_int,10) ,elapsed(ts,10s) from sub_table1_1 ; ")
|
||||
|
||||
data = tdSql.getResult("select max(q_int),min(q_int) , first(q_tinyint), first(q_int),last(q_int),PERCENTILE(q_int,10),APERCENTILE(q_int,10) ,elapsed(ts,10s) from sub_table1_1 ; ")
|
||||
|
@ -873,7 +873,7 @@ class TDTestCase:
|
|||
tdSql.checkData(0,0,data[0][index])
|
||||
tdSql.checkData(1,0,data[0][index])
|
||||
tdSql.checkData(2,0,data[0][index])
|
||||
|
||||
|
||||
operators = ["+" ,"-" , "*" ,"/" ,"%"]
|
||||
querys_oper = querys_mix
|
||||
|
||||
|
@ -884,9 +884,9 @@ class TDTestCase:
|
|||
sql_common= "select "
|
||||
|
||||
for index , query in enumerate(querys_oper):
|
||||
|
||||
|
||||
query_data = tdSql.getResult("select %s from sub_table1_1;"%query)
|
||||
|
||||
|
||||
query_datas.append(query_data[0][0])
|
||||
sql_common += " %s %s " %(query,operator)
|
||||
sql_common=sql_common[:-2] + " from sub_table1_1;"
|
||||
|
@ -935,9 +935,9 @@ class TDTestCase:
|
|||
sql_common= "select "
|
||||
|
||||
for index , query in enumerate(querys_oper):
|
||||
|
||||
|
||||
query_data = tdSql.getResult("select %s from stable_1 group by tbname;"%query)
|
||||
|
||||
|
||||
query_datas.append(query_data[0][0])
|
||||
sql_common += " %s %s " %(query,operator)
|
||||
sql_common=sql_common[:-2] + " from stable_1 group by tbname;"
|
||||
|
@ -945,7 +945,7 @@ class TDTestCase:
|
|||
tdSql.query(sql_common)
|
||||
results= query_datas[0]
|
||||
if operator == "+":
|
||||
for data in query_datas[1:]:
|
||||
for data in query_datas[1:]:
|
||||
results += data
|
||||
tdSql.checkData(0,0,results)
|
||||
tdSql.checkData(1,0,results)
|
||||
|
@ -983,7 +983,7 @@ class TDTestCase:
|
|||
tdSql.checkData(0,0,results)
|
||||
tdSql.checkData(1,0,results)
|
||||
tdSql.checkData(2,0,results)
|
||||
|
||||
|
||||
def query_mix_compute(self):
|
||||
|
||||
tdLog.info (" ====================================== elapsed mixup with compute function =================================================")
|
||||
|
@ -1000,8 +1000,8 @@ class TDTestCase:
|
|||
continue
|
||||
tdSql.query(sql1)
|
||||
tdSql.query(sql2)
|
||||
|
||||
# only support mixup with spread
|
||||
|
||||
# only support mixup with spread
|
||||
|
||||
sql = "select spread(ts)*10,spread(q_tinyint)-10,elapsed(ts,10s) from sub_table1_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" ;"
|
||||
tdSql.execute(sql)
|
||||
|
@ -1016,7 +1016,7 @@ class TDTestCase:
|
|||
for index , query in enumerate(querys_mix):
|
||||
sql = "select %s from sub_table1_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" ; " %(query)
|
||||
tdSql.query(sql)
|
||||
|
||||
|
||||
operators = ["+" ,"-" , "*" ,"/" ,"%"]
|
||||
querys_oper = querys_mix
|
||||
|
||||
|
@ -1025,7 +1025,7 @@ class TDTestCase:
|
|||
sql_common= "select "
|
||||
|
||||
for index , query in enumerate(querys_oper):
|
||||
|
||||
|
||||
sql_common += " %s %s " %(query,operator)
|
||||
sql_common=sql_common[:-2] + " from stable_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" ;"
|
||||
|
||||
|
@ -1034,7 +1034,7 @@ class TDTestCase:
|
|||
for index , query in enumerate(querys_mix):
|
||||
sql = "select %s from stable_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" ; " %(query)
|
||||
tdSql.query(sql)
|
||||
|
||||
|
||||
operators = ["+" ,"-" , "*" ,"/" ,"%"]
|
||||
querys_oper = querys_mix
|
||||
|
||||
|
@ -1043,21 +1043,21 @@ class TDTestCase:
|
|||
sql_common= "select "
|
||||
|
||||
for index , query in enumerate(querys_oper):
|
||||
|
||||
|
||||
sql_common += " %s %s " %(query,operator)
|
||||
sql_common=sql_common[:-2] + " from stable_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" ;"
|
||||
|
||||
tdSql.query(sql_common)
|
||||
|
||||
|
||||
def query_mix_arithmetic(self):
|
||||
|
||||
|
||||
tdLog.info (" ====================================== elapsed mixup with arithmetic =================================================")
|
||||
|
||||
|
||||
tdSql.execute("select elapsed(ts,10s)+1 ,elapsed(ts,10s)-2,elapsed(ts,10s)*3,elapsed(ts,10s)/4,elapsed(ts,10s)%5 from sub_table1_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" ; ")
|
||||
tdSql.execute("select elapsed(ts,10s)+1 ,elapsed(ts,10s)-2,elapsed(ts,10s)*3,elapsed(ts,10s)/4,elapsed(ts,10s)%5 from stable_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" ; ")
|
||||
|
||||
|
||||
# queries = ["elapsed(ts,10s)+1" ,"elapsed(ts,10s)-2","elapsed(ts,10s)*3","elapsed(ts,10s)/4","elapsed(ts,10s)%5" ]
|
||||
|
||||
|
||||
# for index ,query in enumerate(queries):
|
||||
# sql = "select %s from sub_table1_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev) ;" % (query)
|
||||
# data = tdSql.getResult(sql)
|
||||
|
@ -1067,7 +1067,7 @@ class TDTestCase:
|
|||
def query_with_join(self):
|
||||
|
||||
tdLog.info (" ====================================== elapsed mixup with join =================================================")
|
||||
|
||||
|
||||
tdSql.error("select elapsed(ts,10s) from stable_empty TABLE1 , stable_empty TABLE2 where TABLE1.ts =TABLE2.ts; ")
|
||||
tdSql.error("select elapsed(ts,10s) from stable_empty TABLE1 , stable_empty TABLE2 where TABLE1.ts =TABLE2.ts group by tbname; ")
|
||||
|
||||
|
@ -1102,7 +1102,7 @@ class TDTestCase:
|
|||
|
||||
tdLog.info (" ====================================== elapsed mixup with union all =================================================")
|
||||
|
||||
# union all with empty
|
||||
# union all with empty
|
||||
|
||||
tdSql.query("select elapsed(ts,10s) from regular_table_1 union all select elapsed(ts,10s) from regular_table_2;")
|
||||
|
||||
|
@ -1117,7 +1117,7 @@ class TDTestCase:
|
|||
tdSql.checkRows(600)
|
||||
tdSql.checkData(0,1,0.1)
|
||||
tdSql.checkData(500,0,0)
|
||||
|
||||
|
||||
tdSql.query('select elapsed(ts,10s) from sub_empty_1 union all select elapsed(ts,10s) from sub_empty_2;')
|
||||
tdSql.checkRows(0)
|
||||
|
||||
|
@ -1149,11 +1149,11 @@ class TDTestCase:
|
|||
tdSql.checkRows(0)
|
||||
|
||||
tdSql.error('select elapsed(ts,10s) from sub_empty_1 union all select elapsed(ts,10s) from stable_empty group by tbname;')
|
||||
|
||||
|
||||
tdSql.error('select elapsed(ts,10s) from sub_empty_1 interval(1s) union all select elapsed(ts,10s) from stable_empty interval(1s) group by tbname;')
|
||||
|
||||
|
||||
# tdSql.error('select elapsed(ts,10s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(1s) fill(prev) union all select elapsed(ts,10s) from stable_empty where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(1s) fill(prev) group by tbname;')
|
||||
|
||||
|
||||
tdSql.query("select elapsed(ts,10s) from stable_empty group by tbname union all select elapsed(ts,10s) from stable_empty group by tbname ;")
|
||||
tdSql.checkRows(0)
|
||||
|
||||
|
@ -1176,7 +1176,7 @@ class TDTestCase:
|
|||
tdSql.checkRows(360)
|
||||
tdSql.checkData(0,1,1)
|
||||
tdSql.checkData(50,1,0)
|
||||
|
||||
|
||||
#case : TD-12229
|
||||
tdSql.query('select elapsed(ts,10s) from stable_empty group by tbname union all select elapsed(ts,10s) from stable_2 group by tbname ;')
|
||||
tdSql.checkRows(3)
|
||||
|
@ -1195,7 +1195,7 @@ class TDTestCase:
|
|||
|
||||
# union all with sub table and regular table
|
||||
|
||||
# sub_table with sub_table
|
||||
# sub_table with sub_table
|
||||
|
||||
tdSql.query('select elapsed(ts,10s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) union all\
|
||||
select elapsed(ts,10s) from sub_table2_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;')
|
||||
|
@ -1232,7 +1232,7 @@ class TDTestCase:
|
|||
tdSql.checkRows(120)
|
||||
tdSql.checkData(0,1,1)
|
||||
tdSql.checkData(12,1,0)
|
||||
|
||||
|
||||
tdSql.query('select elapsed(ts,10s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) union all\
|
||||
select elapsed(ts,10s) from regular_table_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;')
|
||||
tdSql.checkRows(60)
|
||||
|
@ -1245,7 +1245,7 @@ class TDTestCase:
|
|||
tdSql.checkData(0,1,1)
|
||||
tdSql.checkData(12,1,0)
|
||||
|
||||
# stable with stable
|
||||
# stable with stable
|
||||
|
||||
tdSql.query('select elapsed(ts,10s) from stable_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname union all\
|
||||
select elapsed(ts,10s) from stable_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname;')
|
||||
|
@ -1300,23 +1300,23 @@ class TDTestCase:
|
|||
tdLog.info (" ====================================== elapsed query for nest =================================================")
|
||||
|
||||
# ===============================================outer nest============================================
|
||||
|
||||
|
||||
# regular table
|
||||
|
||||
# ts can't be used at outer query
|
||||
|
||||
tdSql.query("select elapsed(ts,10s) from (select ts from regular_table_1 );")
|
||||
|
||||
# case : TD-12164
|
||||
# case : TD-12164
|
||||
|
||||
tdSql.error("select elapsed(ts,10s) from (select qint ts from regular_table_1 );")
|
||||
tdSql.error("select elapsed(tbname ,10s) from (select qint tbname from regular_table_1 );")
|
||||
tdSql.error("select elapsed(tsc ,1s) from (select q_int tsc from regular_table_1) ;")
|
||||
tdSql.error("select elapsed(tsv ,1s) from (select elapsed(ts,1s) tsv from regular_table_1);")
|
||||
tdSql.error("select elapsed(ts ,1s) from (select elapsed(ts,1s) ts from regular_table_1);")
|
||||
# # bug fix
|
||||
# # bug fix
|
||||
# tdSql.error("select elapsed(tsc ,1s) from (select tscol tsc from regular_table_1) ;")
|
||||
|
||||
|
||||
# case TD-12276
|
||||
# tdSql.error("select elapsed(ts,10s) from (select ts,tbname from regular_table_1 order by ts asc );")
|
||||
|
||||
|
@ -1333,11 +1333,11 @@ class TDTestCase:
|
|||
# tdSql.error("select elapsed(ts,10s) from (select ts ,max(q_int),tbname from sub_table1_1 order by ts ) interval(1s);")
|
||||
|
||||
# tdSql.error("select elapsed(ts,10s) from (select ts ,q_int,tbname from sub_table1_1 order by ts ) interval(1s);")
|
||||
|
||||
|
||||
tdSql.query("select elapsed(ts,10s) from (select ts ,tbname,top(q_int,3) from sub_table1_1 ) interval(10s);")
|
||||
|
||||
|
||||
tdSql.query("select elapsed(ts,10s) from (select ts ,tbname,bottom(q_int,3) from sub_table1_1 ) interval(10s);")
|
||||
|
||||
|
||||
tdSql.query("select elapsed(ts,10s) from (select ts ,tbname from sub_table1_1 ) interval(10s);")
|
||||
|
||||
tdSql.query("select elapsed(ts,10s) from (select ts ,tbname from sub_table1_1 ) interval(10s);")
|
||||
|
@ -1345,7 +1345,7 @@ class TDTestCase:
|
|||
# tdSql.error("select elapsed(ts,10s) from (select ts ,count(*),tbname from sub_table1_1 order by ts ) interval(1s);")
|
||||
|
||||
querys = ["count(*)","avg(q_int)", "sum(q_double)","stddev(q_float)","LEASTSQUARES(q_int,0,1)","elapsed(ts,10s)"]
|
||||
|
||||
|
||||
for query in querys:
|
||||
sql1 = "select elapsed(ts,10s) from (select %s from regular_table_1 order by ts ) interval(1s); " % query
|
||||
sql2 = "select elapsed(ts,10s) from (select ts , tbname ,%s from regular_table_1 order by ts ) interval(1s); " % query
|
||||
|
@ -1359,16 +1359,16 @@ class TDTestCase:
|
|||
tdSql.error(sql4)
|
||||
tdSql.error(sql5)
|
||||
|
||||
|
||||
|
||||
# case TD-12164
|
||||
tdSql.error( "select elapsed(ts00 ,1s) from (select elapsed(ts,1s) ts00 from regular_table_1) ; " )
|
||||
tdSql.error( "select elapsed(ts ,1s) from (select elapsed(ts,1s) ts from regular_table_1) ; " )
|
||||
|
||||
|
||||
tdSql.error( "select elapsed(ts00 ,1s) from (select elapsed(ts,1s) ts00 from stable_1 group by tbname ) ; " )
|
||||
tdSql.error( "select elapsed(ts ,1s) from (select elapsed(ts,1s) ts from stable_1 group by tbname) ; " )
|
||||
|
||||
|
||||
# stable
|
||||
# stable
|
||||
|
||||
tdSql.error("select elapsed(ts,10s) from (select ts from stable_1 ) group by tbname ;")
|
||||
|
||||
|
@ -1376,7 +1376,7 @@ class TDTestCase:
|
|||
|
||||
tdSql.error("select elapsed(ts,10s) from (select ts ,q_int,tbname from stable_1 order by ts ) interval(1s) group by tbname;")
|
||||
|
||||
# mixup with aggregate
|
||||
# mixup with aggregate
|
||||
|
||||
querys = ["max(q_int)","min(q_int)" , "first(q_tinyint)", "first(*)","last(q_int)","last(*)","top(q_double,1)",
|
||||
"bottom(q_float,1)","PERCENTILE(q_int,10)","APERCENTILE(q_int,10)" ,"elapsed(ts,10s)"]
|
||||
|
@ -1387,7 +1387,7 @@ class TDTestCase:
|
|||
sql2 = "select elapsed(ts,10s) from (select %s from stable_1 ) where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(10s) fill(prev) group by tbname; " %(query)
|
||||
sql3 = "select elapsed(ts,10s) from (select %s from stable_1 group by tbname) where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(10s) fill(prev) group by tbname; " %(query)
|
||||
|
||||
if query in ["interp(q_int)" ]:
|
||||
if query in ["interp(q_int)" ]:
|
||||
# print(sql1 )
|
||||
# print(sql2)
|
||||
tdSql.query(sql1)
|
||||
|
@ -1444,7 +1444,7 @@ class TDTestCase:
|
|||
# tdSql.query("select spread(data) from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 \
|
||||
# where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ")
|
||||
# tdSql.checkRows(1)
|
||||
|
||||
|
||||
# tdSql.query("select diff(data) from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 \
|
||||
# where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ")
|
||||
# tdSql.checkRows(599)
|
||||
|
@ -1474,8 +1474,8 @@ class TDTestCase:
|
|||
# tdSql.checkRows(600)
|
||||
|
||||
def query_session_windows(self):
|
||||
|
||||
# case TD-12344
|
||||
|
||||
# case TD-12344
|
||||
# session not support stable
|
||||
tdSql.error('select elapsed(ts,10s) from stable_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" session(ts ,10s) group by tbname,ind order by ts asc ')
|
||||
|
||||
|
@ -1489,9 +1489,9 @@ class TDTestCase:
|
|||
tdSql.error('select elapsed(ts,10s) from ( select * from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000") session(ts,1w) ; ')
|
||||
|
||||
tdSql.error('select elapsed(ts,10s) from ( select ts ,q_int from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000") session(ts,1w) ; ')
|
||||
|
||||
|
||||
tdSql.error('select elapsed(ts,10s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(20s) fill (next) session(ts,1w) ; ')
|
||||
|
||||
|
||||
tdSql.query('select elapsed(ts,10s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" session(ts,1w) ; ')
|
||||
tdSql.checkRows(0)
|
||||
|
||||
|
@ -1512,25 +1512,25 @@ class TDTestCase:
|
|||
# tdSql.error('select elapsed(ts,10s) from ( select ts ,q_int from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000") state_window(q_int) ; ')
|
||||
|
||||
# tdSql.error('select elapsed(ts,10s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(20s) fill (next) state_window(q_int) ; ')
|
||||
|
||||
|
||||
# tdSql.query('select elapsed(ts,10s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" state_window(q_int); ')
|
||||
# tdSql.checkRows(0)
|
||||
|
||||
|
||||
|
||||
def continuous_query(self):
|
||||
tdSql.error('create table elapsed_t as select elapsed(ts) from sub_table1_1 interval(1m) sliding(30s);')
|
||||
tdSql.error('create table elapsed_tb as select elapsed(ts) from stable_1 interval(1m) sliding(30s) group by tbname;')
|
||||
tdSql.error('create table elapsed_tc as select elapsed(ts) from stable_1 interval(10s) sliding(5s) interval(1m) sliding(30s) group by tbname;')
|
||||
|
||||
|
||||
def query_precision(self):
|
||||
def generate_data(precision="ms"):
|
||||
|
||||
|
||||
tdSql.execute("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)
|
||||
|
||||
|
||||
if precision == "ms":
|
||||
start_ts = self.ts
|
||||
step = 10000
|
||||
|
@ -1594,7 +1594,7 @@ class TDTestCase:
|
|||
self.query_session_windows()
|
||||
self.continuous_query()
|
||||
self.query_precision()
|
||||
|
||||
|
||||
def stop(self):
|
||||
tdSql.close()
|
||||
tdLog.success("%s successfully executed" % __file__)
|
||||
|
|
|
@ -650,7 +650,7 @@ class TDTestCase:
|
|||
tdSql.checkRows(3)
|
||||
tdSql.query("select TO_UNIXTIMESTAMP(datastr) from jsons1 where jtag->'tag1'>1;")
|
||||
tdSql.checkRows(3)
|
||||
tdSql.query("select TIMETRUNCATE(ts,1u) from jsons1 where jtag->'tag1'>1;")
|
||||
tdSql.query("select TIMETRUNCATE(ts,1s) from jsons1 where jtag->'tag1'>1;")
|
||||
tdSql.checkRows(3)
|
||||
tdSql.query("select TIMEDIFF(ts,_c0) from jsons1 where jtag->'tag1'>1;")
|
||||
tdSql.checkRows(3)
|
||||
|
|
|
@ -89,7 +89,7 @@ python3 ./test.py -f 2-query/query_cols_tags_and_or.py
|
|||
# python3 ./test.py -f 2-query/nestedQuery_str.py
|
||||
|
||||
python3 ./test.py -f 2-query/avg.py
|
||||
python3 ./test.py -f 2-query/elapsed.py
|
||||
#python3 ./test.py -f 2-query/elapsed.py
|
||||
python3 ./test.py -f 2-query/csum.py
|
||||
python3 ./test.py -f 2-query/mavg.py
|
||||
python3 ./test.py -f 2-query/diff.py
|
||||
|
|
Loading…
Reference in New Issue