add case to support rest API

This commit is contained in:
cpwu 2022-08-19 17:46:24 +08:00
parent 8ae2907dcb
commit bea875aea7
19 changed files with 635 additions and 753 deletions

View File

@ -311,7 +311,7 @@ class TDSql:
tdLog.exit("%s(%d) failed: sql:%s, col_name_list:%s != expect_col_name_list:%s" % args) tdLog.exit("%s(%d) failed: sql:%s, col_name_list:%s != expect_col_name_list:%s" % args)
def __check_equal(self, elm, expect_elm): def __check_equal(self, elm, expect_elm):
if not type(elm) in(list, tuple) and elm == expect_elm: if elm == expect_elm:
return True return True
if type(elm) in(list, tuple) and type(expect_elm) in(list, tuple): if type(elm) in(list, tuple) and type(expect_elm) in(list, tuple):
if len(elm) != len(expect_elm): if len(elm) != len(expect_elm):

View File

@ -193,43 +193,38 @@ class TDTestCase:
# case17: only support normal table join # case17: only support normal table join
case17 = { case17 = {
"col": "t1.c1", "col": "table1.c1 ",
"table_expr": "t1, t2", "table_expr": "db.t1 as table1, db.t2 as table2",
"condition": "where t1.ts=t2.ts" "condition": "where table1.ts=table2.ts"
} }
self.checkdiff(**case17) self.checkdiff(**case17)
# case18~19: with group by # case18~19: with group by , function diff not support group by
# case18 = {
# "table_expr": "db.t1",
# "condition": "group by c6"
# }
# self.checkdiff(**case18)
case19 = { case19 = {
"table_expr": "db.stb1", "table_expr": "db.stb1 where tbname =='t0' ",
"condition": "partition by tbname order by tbname" # partition by tbname "condition": "partition by tbname order by tbname" # partition by tbname
} }
self.checkdiff(**case19) self.checkdiff(**case19)
# # case20~21: with order by # case20~21: with order by , Not a single-group group function
# case20 = {"condition": "order by ts"}
# self.checkdiff(**case20)
# # case22: with union # case22: with union
# case22 = { # case22 = {
# "condition": "union all select diff(c1) from t2" # "condition": "union all select diff(c1) from db.t2 "
# } # }
# self.checkdiff(**case22) # self.checkdiff(**case22)
tdSql.query("select count(c1) from db.t1 union all select count(c1) from db.t2")
# case23: with limit/slimit # case23: with limit/slimit
case23 = { case23 = {
"condition": "limit 1" "condition": "limit 1"
} }
self.checkdiff(**case23) self.checkdiff(**case23)
# case24 = { case24 = {
# "table_expr": "db.stb1", "table_expr": "db.stb1",
# "condition": "group by tbname slimit 1 soffset 1" "condition": "partition by tbname order by tbname slimit 1 soffset 1"
# } }
# self.checkdiff(**case24) self.checkdiff(**case24)
pass pass
@ -284,9 +279,9 @@ class TDTestCase:
tdSql.query(self.diff_query_form(alias=", c2")) # mix with other 1 tdSql.query(self.diff_query_form(alias=", c2")) # mix with other 1
# tdSql.error(self.diff_query_form(table_expr="db.stb1")) # select stb directly # tdSql.error(self.diff_query_form(table_expr="db.stb1")) # select stb directly
stb_join = { stb_join = {
"col": "stb1.c1", "col": "stable1.c1",
"table_expr": "stb1, stb2", "table_expr": "db.stb1 as stable1, db.stb2 as stable2",
"condition": "where stb1.ts=stb2.ts and stb1.st1=stb2.st2 order by stb1.ts" "condition": "where stable1.ts=stable2.ts and stable1.st1=stable2.st2 order by stable1.ts"
} }
tdSql.query(self.diff_query_form(**stb_join)) # stb join tdSql.query(self.diff_query_form(**stb_join)) # stb join
interval_sql = { interval_sql = {
@ -315,20 +310,20 @@ class TDTestCase:
for i in range(tbnum): for i in range(tbnum):
for j in range(data_row): for j in range(data_row):
tdSql.execute( tdSql.execute(
f"insert into t{i} values (" f"insert into db.t{i} values ("
f"{basetime + (j+1)*10}, {random.randint(-200, -1)}, {random.uniform(200, -1)}, {basetime + random.randint(-200, -1)}, " f"{basetime + (j+1)*10}, {random.randint(-200, -1)}, {random.uniform(200, -1)}, {basetime + random.randint(-200, -1)}, "
f"'binary_{j}', {random.uniform(-200, -1)}, {random.choice([0,1])}, {random.randint(-200,-1)}, " f"'binary_{j}', {random.uniform(-200, -1)}, {random.choice([0,1])}, {random.randint(-200,-1)}, "
f"{random.randint(-200, -1)}, {random.randint(-127, -1)}, 'nchar_{j}' )" f"{random.randint(-200, -1)}, {random.randint(-127, -1)}, 'nchar_{j}' )"
) )
tdSql.execute( tdSql.execute(
f"insert into t{i} values (" f"insert into db.t{i} values ("
f"{basetime - (j+1) * 10}, {random.randint(1, 200)}, {random.uniform(1, 200)}, {basetime - random.randint(1, 200)}, " f"{basetime - (j+1) * 10}, {random.randint(1, 200)}, {random.uniform(1, 200)}, {basetime - random.randint(1, 200)}, "
f"'binary_{j}_1', {random.uniform(1, 200)}, {random.choice([0, 1])}, {random.randint(1,200)}, " f"'binary_{j}_1', {random.uniform(1, 200)}, {random.choice([0, 1])}, {random.randint(1,200)}, "
f"{random.randint(1,200)}, {random.randint(1,127)}, 'nchar_{j}_1' )" f"{random.randint(1,200)}, {random.randint(1,127)}, 'nchar_{j}_1' )"
) )
tdSql.execute( tdSql.execute(
f"insert into tt{i} values ( {basetime-(j+1) * 10}, {random.randint(1, 200)} )" f"insert into db.tt{i} values ( {basetime-(j+1) * 10}, {random.randint(1, 200)} )"
) )
pass pass
@ -349,8 +344,8 @@ class TDTestCase:
"create stable db.stb2 (ts timestamp, c1 int) tags(st2 int)" "create stable db.stb2 (ts timestamp, c1 int) tags(st2 int)"
) )
for i in range(tbnum): for i in range(tbnum):
tdSql.execute(f"create table t{i} using db.stb1 tags({i})") tdSql.execute(f"create table db.t{i} using db.stb1 tags({i})")
tdSql.execute(f"create table tt{i} using db.stb2 tags({i})") tdSql.execute(f"create table db.tt{i} using db.stb2 tags({i})")
pass pass
def diff_support_stable(self): def diff_support_stable(self):
@ -398,8 +393,8 @@ class TDTestCase:
tdLog.printNoPrefix("######## insert only NULL test:") tdLog.printNoPrefix("######## insert only NULL test:")
for i in range(tbnum): for i in range(tbnum):
tdSql.execute(f"insert into t{i}(ts) values ({nowtime - 5})") tdSql.execute(f"insert into db.t{i}(ts) values ({nowtime - 5})")
tdSql.execute(f"insert into t{i}(ts) values ({nowtime + 5})") tdSql.execute(f"insert into db.t{i}(ts) values ({nowtime + 5})")
self.diff_current_query() self.diff_current_query()
self.diff_error_query() self.diff_error_query()
@ -430,9 +425,9 @@ class TDTestCase:
tdLog.printNoPrefix("######## insert data mix with NULL test:") tdLog.printNoPrefix("######## insert data mix with NULL test:")
for i in range(tbnum): for i in range(tbnum):
tdSql.execute(f"insert into t{i}(ts) values ({nowtime})") tdSql.execute(f"insert into db.t{i}(ts) values ({nowtime})")
tdSql.execute(f"insert into t{i}(ts) values ({nowtime-(per_table_rows+3)*10})") tdSql.execute(f"insert into db.t{i}(ts) values ({nowtime-(per_table_rows+3)*10})")
tdSql.execute(f"insert into t{i}(ts) values ({nowtime+(per_table_rows+3)*10})") tdSql.execute(f"insert into db.t{i}(ts) values ({nowtime+(per_table_rows+3)*10})")
self.diff_current_query() self.diff_current_query()
self.diff_error_query() self.diff_error_query()

View File

@ -52,12 +52,12 @@ class TDTestCase:
return query_condition return query_condition
def __join_condition(self, tb_list, filter=PRIMARY_COL, INNER=False): def __join_condition(self, tb_list, filter=PRIMARY_COL, INNER=False, alias_tb1="tb1", alias_tb2="tb2"):
table_reference = tb_list[0] table_reference = tb_list[0]
join_condition = table_reference join_condition = table_reference
join = "inner join" if INNER else "join" join = "inner join" if INNER else "join"
for i in range(len(tb_list[1:])): for i in range(len(tb_list[1:])):
join_condition += f" {join} {tb_list[i+1]} on {table_reference}.{filter}={tb_list[i+1]}.{filter}" join_condition += f" as {alias_tb1} {join} {tb_list[i+1]} as {alias_tb2} on {alias_tb1}.{filter}={alias_tb2}.{filter}"
return join_condition return join_condition

View File

@ -65,8 +65,7 @@ class TDTestCase:
''' '''
) )
def check_result_auto_log(self ,base , origin_query , log_query):
def check_result_auto_log(self ,origin_query , log_query):
log_result = tdSql.getResult(log_query) log_result = tdSql.getResult(log_query)
origin_result = tdSql.getResult(origin_query) origin_result = tdSql.getResult(origin_query)
@ -76,112 +75,29 @@ class TDTestCase:
for row in origin_result: for row in origin_result:
row_check = [] row_check = []
for elem in row: for elem in row:
if base ==1:
elem = None
else:
if elem == None: if elem == None:
elem = None elem = None
elif elem >0: elif elem ==1:
elem = 0.0
elif elem >0 and elem !=1 :
if base==None :
elem = math.log(elem ) elem = math.log(elem )
else:
print(base , elem)
elem = math.log(elem , base)
elif elem <=0: elif elem <=0:
elem = None elem = None
row_check.append(elem) row_check.append(elem)
auto_result.append(row_check) auto_result.append(row_check)
check_status = True tdSql.query(log_query)
for row_index , row in enumerate(log_result): for row_index , row in enumerate(log_result):
for col_index , elem in enumerate(row): for col_index , elem in enumerate(row):
if auto_result[row_index][col_index] != elem: tdSql.checkData(row_index , col_index ,auto_result[row_index][col_index])
check_status = False
if not check_status:
tdLog.notice("log function value has not as expected , sql is \"%s\" "%log_query )
sys.exit(1)
else:
tdLog.info("log value check pass , it work as expected ,sql is \"%s\" "%log_query )
def check_result_auto_log2(self ,origin_query , log_query):
log_result = tdSql.getResult(log_query)
origin_result = tdSql.getResult(origin_query)
auto_result =[]
for row in origin_result:
row_check = []
for elem in row:
if elem == None:
elem = None
elif elem >0:
elem = math.log(elem,2)
elif elem <=0:
elem = None
row_check.append(elem)
auto_result.append(row_check)
check_status = True
for row_index , row in enumerate(log_result):
for col_index , elem in enumerate(row):
if auto_result[row_index][col_index] != elem:
check_status = False
if not check_status:
tdLog.notice("log function value has not as expected , sql is \"%s\" "%log_query )
sys.exit(1)
else:
tdLog.info("log value check pass , it work as expected ,sql is \"%s\" "%log_query )
def check_result_auto_log1(self ,origin_query , log_query):
log_result = tdSql.getResult(log_query)
origin_result = tdSql.getResult(origin_query)
auto_result =[]
for row in origin_result:
row_check = []
for elem in row:
if elem == None:
elem = None
elif elem >0:
elem = None
elif elem <=0:
elem = None
row_check.append(elem)
auto_result.append(row_check)
check_status = True
for row_index , row in enumerate(log_result):
for col_index , elem in enumerate(row):
if auto_result[row_index][col_index] != elem:
check_status = False
if not check_status:
tdLog.notice("log function value has not as expected , sql is \"%s\" "%log_query )
sys.exit(1)
else:
tdLog.info("log value check pass , it work as expected ,sql is \"%s\" "%log_query )
def check_result_auto_log__10(self ,origin_query , log_query):
log_result = tdSql.getResult(log_query)
origin_result = tdSql.getResult(origin_query)
auto_result =[]
for row in origin_result:
row_check = []
for elem in row:
if elem == None:
elem = None
elif elem >0:
elem = None
elif elem <=0:
elem = None
row_check.append(elem)
auto_result.append(row_check)
check_status = True
for row_index , row in enumerate(log_result):
for col_index , elem in enumerate(row):
if auto_result[row_index][col_index] != elem:
check_status = False
if not check_status:
tdLog.notice("log function value has not as expected , sql is \"%s\" "%log_query )
sys.exit(1)
else:
tdLog.info("log value check pass , it work as expected ,sql is \"%s\" "%log_query )
def test_errors(self, dbname="db"): def test_errors(self, dbname="db"):
error_sql_lists = [ error_sql_lists = [
@ -328,10 +244,10 @@ class TDTestCase:
tdSql.checkData(3 , 0, 1.098612289) tdSql.checkData(3 , 0, 1.098612289)
tdSql.checkData(4 , 0, 1.386294361) tdSql.checkData(4 , 0, 1.386294361)
self.check_result_auto_log( f"select c1, c2, c3 , c4, c5 from {dbname}.t1", f"select log(c1), log(c2) ,log(c3), log(c4), log(c5) from {dbname}.t1") self.check_result_auto_log( None , f"select c1, c2, c3 , c4, c5 from {dbname}.t1", f"select log(c1), log(c2) ,log(c3), log(c4), log(c5) from {dbname}.t1")
self.check_result_auto_log2( f"select c1, c2, c3 , c4, c5 from {dbname}.t1", f"select log(c1 ,2), log(c2 ,2) ,log(c3, 2), log(c4 ,2), log(c5 ,2) from {dbname}.t1") self.check_result_auto_log( 2 , f"select c1, c2, c3 , c4, c5 from {dbname}.t1", f"select log(c1 ,2), log(c2 ,2) ,log(c3, 2), log(c4 ,2), log(c5 ,2) from {dbname}.t1")
self.check_result_auto_log__10( f"select c1, c2, c3 , c4, c5 from {dbname}.t1", f"select log(c1 ,1), log(c2 ,1) ,log(c3, 1), log(c4 ,1), log(c5 ,1) from {dbname}.t1") self.check_result_auto_log( 1, f"select c1, c2, c3 , c4, c5 from {dbname}.t1", f"select log(c1 ,1), log(c2 ,1) ,log(c3, 1), log(c4 ,1), log(c5 ,1) from {dbname}.t1")
self.check_result_auto_log__10( f"select c1, c2, c3 , c4, c5 from {dbname}.t1", f"select log(c1 ,-10), log(c2 ,-10) ,log(c3, -10), log(c4 ,-10), log(c5 ,-10) from {dbname}.t1") self.check_result_auto_log( 10 ,f"select c1, c2, c3 , c4, c5 from {dbname}.t1", f"select log(c1 ,10), log(c2 ,10) ,log(c3, 10), log(c4 ,10), log(c5 ,10) from {dbname}.t1")
# used for sub table # used for sub table
tdSql.query(f"select c1 ,log(c1 ,3) from {dbname}.ct1") tdSql.query(f"select c1 ,log(c1 ,3) from {dbname}.ct1")
@ -349,9 +265,9 @@ class TDTestCase:
tdSql.checkData(3 , 2, 0.147315235) tdSql.checkData(3 , 2, 0.147315235)
tdSql.checkData(4 , 2, None) tdSql.checkData(4 , 2, None)
self.check_result_auto_log( f"select c1, c2, c3 , c4, c5 from {dbname}.ct1", f"select log(c1), log(c2) ,log(c3), log(c4), log(c5) from {dbname}.ct1") self.check_result_auto_log( None ,f"select c1, c2, c3 , c4, c5 from {dbname}.ct1", f"select log(c1), log(c2) ,log(c3), log(c4), log(c5) from {dbname}.ct1")
self.check_result_auto_log2( f"select c1, c2, c3 , c4, c5 from {dbname}.ct1", f"select log(c1,2), log(c2,2) ,log(c3,2), log(c4,2), log(c5,2) from {dbname}.ct1") self.check_result_auto_log( 2, f"select c1, c2, c3 , c4, c5 from {dbname}.ct1", f"select log(c1,2), log(c2,2) ,log(c3,2), log(c4,2), log(c5,2) from {dbname}.ct1")
self.check_result_auto_log__10( f"select c1, c2, c3 , c4, c5 from {dbname}.ct1", f"select log(c1,-10), log(c2,-10) ,log(c3,-10), log(c4,-10), log(c5,-10) from {dbname}.ct1") self.check_result_auto_log( 10 , f"select c1, c2, c3 , c4, c5 from {dbname}.ct1", f"select log(c1,10), log(c2,10) ,log(c3,10), log(c4,10), log(c5,10) from {dbname}.ct1")
# nest query for log functions # nest query for log functions
tdSql.query(f"select c1 , log(c1,3) ,log(log(c1,3),3) , log(log(log(c1,3),3),3) from {dbname}.ct1;") tdSql.query(f"select c1 , log(c1,3) ,log(log(c1,3),3) , log(log(log(c1,3),3),3) from {dbname}.ct1;")
@ -585,15 +501,15 @@ class TDTestCase:
tdSql.error( tdSql.error(
f"insert into {dbname}.sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" f"insert into {dbname}.sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
) )
self.check_result_auto_log( f"select c1, c2, c3 , c4, c5 ,c6 from {dbname}.sub1_bound ", f"select log(c1), log(c2) ,log(c3), log(c4), log(c5) ,log(c6) from {dbname}.sub1_bound") self.check_result_auto_log(None , f"select c1, c2, c3 , c4, c5 ,c6 from {dbname}.sub1_bound ", f"select log(c1), log(c2) ,log(c3), log(c4), log(c5) ,log(c6) from {dbname}.sub1_bound")
self.check_result_auto_log2( f"select c1, c2, c3 , c4, c5 ,c6 from {dbname}.sub1_bound ", f"select log(c1,2), log(c2,2) ,log(c3,2), log(c4,2), log(c5,2) ,log(c6,2) from {dbname}.sub1_bound") self.check_result_auto_log( 2 , f"select c1, c2, c3 , c4, c5 ,c6 from {dbname}.sub1_bound ", f"select log(c1,2), log(c2,2) ,log(c3,2), log(c4,2), log(c5,2) ,log(c6,2) from {dbname}.sub1_bound")
self.check_result_auto_log__10( f"select c1, c2, c3 , c4, c5 ,c6 from {dbname}.sub1_bound ", f"select log(c1,-10), log(c2,-10) ,log(c3,-10), log(c4,-10), log(c5,-10) ,log(c6,-10) from {dbname}.sub1_bound") self.check_result_auto_log( 10 , f"select c1, c2, c3 , c4, c5 ,c6 from {dbname}.sub1_bound ", f"select log(c1,10), log(c2,10) ,log(c3,10), log(c4,10), log(c5,10) ,log(c6,10) from {dbname}.sub1_bound")
self.check_result_auto_log2( f"select c1, c2, c3 , c3, c2 ,c1 from {dbname}.sub1_bound ", f"select log(c1,2), log(c2,2) ,log(c3,2), log(c3,2), log(c2,2) ,log(c1,2) from {dbname}.sub1_bound") self.check_result_auto_log( 2 , f"select c1, c2, c3 , c3, c2 ,c1 from {dbname}.sub1_bound ", f"select log(c1,2), log(c2,2) ,log(c3,2), log(c3,2), log(c2,2) ,log(c1,2) from {dbname}.sub1_bound")
self.check_result_auto_log( f"select c1, c2, c3 , c3, c2 ,c1 from {dbname}.sub1_bound ", f"select log(c1), log(c2) ,log(c3), log(c3), log(c2) ,log(c1) from {dbname}.sub1_bound") self.check_result_auto_log( None , f"select c1, c2, c3 , c3, c2 ,c1 from {dbname}.sub1_bound ", f"select log(c1), log(c2) ,log(c3), log(c3), log(c2) ,log(c1) from {dbname}.sub1_bound")
self.check_result_auto_log2(f"select abs(abs(abs(abs(abs(abs(abs(abs(abs(c1))))))))) nest_col_func from {dbname}.sub1_bound" , f"select log(abs(c1) ,2) from {dbname}.sub1_bound" ) self.check_result_auto_log(2 , f"select abs(abs(abs(abs(abs(abs(abs(abs(abs(c1))))))))) nest_col_func from {dbname}.sub1_bound" , f"select log(abs(c1) ,2) from {dbname}.sub1_bound" )
# check basic elem for table per row # check basic elem for table per row
tdSql.query(f"select log(abs(c1),2) ,log(abs(c2),2) , log(abs(c3),2) , log(abs(c4),2), log(abs(c5),2), log(abs(c6),2) from {dbname}.sub1_bound ") tdSql.query(f"select log(abs(c1),2) ,log(abs(c2),2) , log(abs(c3),2) , log(abs(c4),2), log(abs(c5),2), log(abs(c6),2) from {dbname}.sub1_bound ")
@ -647,15 +563,15 @@ class TDTestCase:
def support_super_table_test(self, dbname="db"): def support_super_table_test(self, dbname="db"):
self.check_result_auto_log2( f"select c5 from {dbname}.stb1 order by ts " , f"select log(c5,2) from {dbname}.stb1 order by ts" ) self.check_result_auto_log( 2 , f"select c5 from {dbname}.stb1 order by ts " , f"select log(c5,2) from {dbname}.stb1 order by ts" )
self.check_result_auto_log2( f"select c5 from {dbname}.stb1 order by tbname " , f"select log(c5,2) from {dbname}.stb1 order by tbname" ) self.check_result_auto_log( 2 ,f"select c5 from {dbname}.stb1 order by tbname " , f"select log(c5,2) from {dbname}.stb1 order by tbname" )
self.check_result_auto_log2( f"select c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select log(c5,2) from {dbname}.stb1 where c1 > 0 order by tbname" ) self.check_result_auto_log( 2 ,f"select c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select log(c5,2) from {dbname}.stb1 where c1 > 0 order by tbname" )
self.check_result_auto_log2( f"select c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select log(c5,2) from {dbname}.stb1 where c1 > 0 order by tbname" ) self.check_result_auto_log( 2 , f"select c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select log(c5,2) from {dbname}.stb1 where c1 > 0 order by tbname" )
self.check_result_auto_log2( f"select t1,c5 from {dbname}.stb1 order by ts " , f"select log(t1,2), log(c5,2) from {dbname}.stb1 order by ts" ) self.check_result_auto_log( 2 , f"select t1,c5 from {dbname}.stb1 order by ts " , f"select log(t1,2), log(c5,2) from {dbname}.stb1 order by ts" )
self.check_result_auto_log2( f"select t1,c5 from {dbname}.stb1 order by tbname " , f"select log(t1,2) ,log(c5,2) from {dbname}.stb1 order by tbname" ) self.check_result_auto_log( 2 , f"select t1,c5 from {dbname}.stb1 order by tbname " , f"select log(t1,2) ,log(c5,2) from {dbname}.stb1 order by tbname" )
self.check_result_auto_log2( f"select t1,c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select log(t1,2) ,log(c5,2) from {dbname}.stb1 where c1 > 0 order by tbname" ) self.check_result_auto_log( 2 , f"select t1,c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select log(t1,2) ,log(c5,2) from {dbname}.stb1 where c1 > 0 order by tbname" )
self.check_result_auto_log2( f"select t1,c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select log(t1,2) , log(c5,2) from {dbname}.stb1 where c1 > 0 order by tbname" ) self.check_result_auto_log( 2 ,f"select t1,c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select log(t1,2) , log(c5,2) from {dbname}.stb1 where c1 > 0 order by tbname" )
def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring
tdSql.prepare() tdSql.prepare()

View File

@ -96,16 +96,16 @@ class TDTestCase:
return sqls return sqls
def __test_current(self): def __test_current(self, dbname="db"):
tdLog.printNoPrefix("==========current sql condition check , must return query ok==========") tdLog.printNoPrefix("==========current sql condition check , must return query ok==========")
tbname = ["ct1", "ct2", "ct4", "t1", "stb1"] tbname = [f"{dbname}.ct1", f"{dbname}.ct2", f"{dbname}.ct4", f"{dbname}.t1", f"{dbname}.stb1"]
for tb in tbname: for tb in tbname:
self.__lower_current_check(tb) self.__lower_current_check(tb)
tdLog.printNoPrefix(f"==========current sql condition check in {tb} over==========") tdLog.printNoPrefix(f"==========current sql condition check in {tb} over==========")
def __test_error(self): def __test_error(self, dbname="db"):
tdLog.printNoPrefix("==========err sql condition check , must return error==========") tdLog.printNoPrefix("==========err sql condition check , must return error==========")
tbname = ["ct1", "ct2", "ct4", "t1", "stb1"] tbname = [f"{dbname}.ct1", f"{dbname}.ct2", f"{dbname}.ct4", f"{dbname}.t1", f"{dbname}.stb1"]
for tb in tbname: for tb in tbname:
for errsql in self.__lower_err_check(tb): for errsql in self.__lower_err_check(tb):
@ -113,22 +113,20 @@ class TDTestCase:
tdLog.printNoPrefix(f"==========err sql condition check in {tb} over==========") tdLog.printNoPrefix(f"==========err sql condition check in {tb} over==========")
def all_test(self): def all_test(self, dbname="db"):
self.__test_current() self.__test_current(dbname)
self.__test_error() self.__test_error(dbname)
def __create_tb(self, dbname="db"):
def __create_tb(self):
tdSql.prepare()
tdLog.printNoPrefix("==========step1:create table") tdLog.printNoPrefix("==========step1:create table")
create_stb_sql = f'''create table stb1( create_stb_sql = f'''create table {dbname}.stb1(
ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint,
{FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool,
{BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp
) tags (t1 int) ) tags (tag1 int)
''' '''
create_ntb_sql = f'''create table t1( create_ntb_sql = f'''create table {dbname}.t1(
ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint,
{FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool,
{BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp
@ -138,78 +136,78 @@ class TDTestCase:
tdSql.execute(create_ntb_sql) tdSql.execute(create_ntb_sql)
for i in range(4): for i in range(4):
tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( {i+1} )')
def __insert_data(self, rows): def __insert_data(self, rows, dbname="db"):
now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000)
for i in range(rows): for i in range(rows):
tdSql.execute( tdSql.execute(
f"insert into ct1 values ( { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" f"insert into {dbname}.ct1 values ( { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )"
) )
tdSql.execute( tdSql.execute(
f"insert into ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" f"insert into {dbname}.ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )"
) )
tdSql.execute( tdSql.execute(
f"insert into ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" f"insert into {dbname}.ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )"
) )
tdSql.execute( tdSql.execute(
f'''insert into ct1 values f'''insert into {dbname}.ct1 values
( { now_time - rows * 5 }, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', { now_time + 8 } ) ( { now_time - rows * 5 }, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar_测试_0', { now_time + 8 } )
( { now_time + 10000 }, { rows }, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', { now_time + 9 } ) ( { now_time + 10000 }, { rows }, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar_测试_9', { now_time + 9 } )
''' '''
) )
tdSql.execute( tdSql.execute(
f'''insert into ct4 values f'''insert into {dbname}.ct4 values
( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
( { now_time - rows * 3888000000 + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 3888000000 + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
( (
{ now_time + 5184000000}, {pow(2,31)-pow(2,15)}, {pow(2,63)-pow(2,30)}, 32767, 127, { now_time + 5184000000}, {pow(2,31)-pow(2,15)}, {pow(2,63)-pow(2,30)}, 32767, 127,
{ 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_limit-1", { now_time - 86400000} { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_测试_limit-1", { now_time - 86400000}
) )
( (
{ now_time + 2592000000 }, {pow(2,31)-pow(2,16)}, {pow(2,63)-pow(2,31)}, 32766, 126, { now_time + 2592000000 }, {pow(2,31)-pow(2,16)}, {pow(2,63)-pow(2,31)}, 32766, 126,
{ 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_limit-2", { now_time - 172800000} { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_测试_limit-2", { now_time - 172800000}
) )
''' '''
) )
tdSql.execute( tdSql.execute(
f'''insert into ct2 values f'''insert into {dbname}.ct2 values
( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
( { now_time - rows * 3888000000 + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 3888000000 + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
( (
{ now_time + 5184000000 }, { -1 * pow(2,31) + pow(2,15) }, { -1 * pow(2,63) + pow(2,30) }, -32766, -126, { now_time + 5184000000 }, { -1 * pow(2,31) + pow(2,15) }, { -1 * pow(2,63) + pow(2,30) }, -32766, -126,
{ -1 * 3.2 * pow(10,38) }, { -1.2 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_limit-1", { now_time - 86400000 } { -1 * 3.2 * pow(10,38) }, { -1.2 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_测试_limit-1", { now_time - 86400000 }
) )
( (
{ now_time + 2592000000 }, { -1 * pow(2,31) + pow(2,16) }, { -1 * pow(2,63) + pow(2,31) }, -32767, -127, { now_time + 2592000000 }, { -1 * pow(2,31) + pow(2,16) }, { -1 * pow(2,63) + pow(2,31) }, -32767, -127,
{ - 3.3 * pow(10,38) }, { -1.3 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_limit-2", { now_time - 172800000 } { - 3.3 * pow(10,38) }, { -1.3 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_测试_limit-2", { now_time - 172800000 }
) )
''' '''
) )
for i in range(rows): for i in range(rows):
insert_data = f'''insert into t1 values insert_data = f'''insert into {dbname}.t1 values
( { now_time - i * 3600000 }, {i}, {i * 11111}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}, ( { now_time - i * 3600000 }, {i}, {i * 11111}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2},
"binary_{i}", "nchar_{i}", { now_time - 1000 * i } ) "binary_{i}", "nchar_测试_{i}", { now_time - 1000 * i } )
''' '''
tdSql.execute(insert_data) tdSql.execute(insert_data)
tdSql.execute( tdSql.execute(
f'''insert into t1 values f'''insert into {dbname}.t1 values
( { now_time + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
( { now_time - (( rows // 2 ) * 60 + 30) * 60000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - (( rows // 2 ) * 60 + 30) * 60000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
( { now_time - rows * 3600000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 3600000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
( { now_time + 7200000 }, { pow(2,31) - pow(2,15) }, { pow(2,63) - pow(2,30) }, 32767, 127, ( { now_time + 7200000 }, { pow(2,31) - pow(2,15) }, { pow(2,63) - pow(2,30) }, 32767, 127,
{ 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 },
"binary_limit-1", "nchar_limit-1", { now_time - 86400000 } "binary_limit-1", "nchar_测试_limit-1", { now_time - 86400000 }
) )
( (
{ now_time + 3600000 } , { pow(2,31) - pow(2,16) }, { pow(2,63) - pow(2,31) }, 32766, 126, { now_time + 3600000 } , { pow(2,31) - pow(2,16) }, { pow(2,63) - pow(2,31) }, 32766, 126,
{ 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 },
"binary_limit-2", "nchar_limit-2", { now_time - 172800000 } "binary_limit-2", "nchar_测试_limit-2", { now_time - 172800000 }
) )
''' '''
) )
@ -227,10 +225,7 @@ class TDTestCase:
tdLog.printNoPrefix("==========step3:all check") tdLog.printNoPrefix("==========step3:all check")
self.all_test() self.all_test()
tdDnodes.stop(1) tdSql.execute("flush database db")
tdDnodes.start(1)
tdSql.execute("use db")
tdLog.printNoPrefix("==========step4:after wal, all check again ") tdLog.printNoPrefix("==========step4:after wal, all check again ")
self.all_test() self.all_test()

View File

@ -307,7 +307,7 @@ class TDTestCase:
pass pass
def mavg_current_query(self) : def mavg_current_query(self, dbname="db") :
# table schema :ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool # table schema :ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool
# c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16) # c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
@ -325,17 +325,17 @@ class TDTestCase:
case6 = {"col": "c9"} case6 = {"col": "c9"}
self.checkmavg(**case6) self.checkmavg(**case6)
# # case7~8: nested query # case7~8: nested query
# case7 = {"table_expr": f"(select c1 from {dbname}.stb1)"} case7 = {"table_expr": f"(select c1 from {dbname}.stb1)"}
# self.checkmavg(**case7) self.checkmavg(**case7)
# case8 = {"table_expr": f"(select mavg(c1, 1) c1 from {dbname}.stb1 group by tbname)"} # case8 = {"table_expr": f"(select _c0, mavg(c1, 1) c1 from {dbname}.stb1 group by tbname)"}
# self.checkmavg(**case8) # self.checkmavg(**case8)
# case9~10: mix with tbname/ts/tag/col # case9~10: mix with tbname/ts/tag/col
# case9 = {"alias": ", tbname"} case9 = {"alias": ", tbname"}
# self.checkmavg(**case9) self.checkmavg(**case9)
# case10 = {"alias": ", _c0"} case10 = {"alias": ", _c0"}
# self.checkmavg(**case10) self.checkmavg(**case10)
# case11 = {"alias": ", st1"} # case11 = {"alias": ", st1"}
# self.checkmavg(**case11) # self.checkmavg(**case11)
# case12 = {"alias": ", c1"} # case12 = {"alias": ", c1"}
@ -356,7 +356,7 @@ class TDTestCase:
# case17: only support normal table join # case17: only support normal table join
case17 = { case17 = {
"col": "t1.c1", "col": "t1.c1",
"table_expr": "t1, t2", "table_expr": f"{dbname}.t1 t1, {dbname}.t2 t2",
"condition": "where t1.ts=t2.ts" "condition": "where t1.ts=t2.ts"
} }
self.checkmavg(**case17) self.checkmavg(**case17)
@ -367,14 +367,14 @@ class TDTestCase:
# } # }
# self.checkmavg(**case19) # self.checkmavg(**case19)
# case20~21: with order by # # case20~21: with order by
# case20 = {"condition": "order by ts"} # case20 = {"condition": "order by ts"}
# self.checkmavg(**case20) # self.checkmavg(**case20)
#case21 = { case21 = {
# "table_expr": f"{dbname}.stb1", "table_expr": f"{dbname}.stb1",
# "condition": "group by tbname order by tbname" "condition": "group by tbname order by tbname"
#} }
#self.checkmavg(**case21) self.checkmavg(**case21)
# # case22: with union # # case22: with union
# case22 = { # case22 = {
@ -398,7 +398,7 @@ class TDTestCase:
pass pass
def mavg_error_query(self) -> None : def mavg_error_query(self, dbname="db") -> None :
# unusual test # unusual test
# form test # form test
@ -419,9 +419,9 @@ class TDTestCase:
err8 = {"table_expr": ""} err8 = {"table_expr": ""}
self.checkmavg(**err8) # no table_expr self.checkmavg(**err8) # no table_expr
# err9 = {"col": "st1"} err9 = {"col": "st1"}
# self.checkmavg(**err9) # col: tag # self.checkmavg(**err9) # col: tag
# err10 = {"col": 1} err10 = {"col": 1}
# self.checkmavg(**err10) # col: value # self.checkmavg(**err10) # col: value
err11 = {"col": "NULL"} err11 = {"col": "NULL"}
self.checkmavg(**err11) # col: NULL self.checkmavg(**err11) # col: NULL
@ -496,7 +496,7 @@ class TDTestCase:
# "condition": "where stb1.ts=stb2.ts and stb1.st1=stb2.st2 order by stb1.ts" # "condition": "where stb1.ts=stb2.ts and stb1.st1=stb2.st2 order by stb1.ts"
# } # }
# self.checkmavg(**err44) # stb join # self.checkmavg(**err44) # stb join
tdSql.query("select mavg( stb1.c1 , 1 ) from stb1, stb2 where stb1.ts=stb2.ts and stb1.st1=stb2.st2 order by stb1.ts;") tdSql.query(f"select mavg( stb1.c1 , 1 ) from {dbname}.stb1 stb1, {dbname}.stb2 stb2 where stb1.ts=stb2.ts and stb1.st1=stb2.st2 order by stb1.ts;")
err45 = { err45 = {
"condition": "where ts>0 and ts < now interval(1h) fill(next)" "condition": "where ts>0 and ts < now interval(1h) fill(next)"
} }

View File

@ -24,9 +24,6 @@ from util.dnodes import tdDnodes
from util.dnodes import * from util.dnodes import *
class TDTestCase: class TDTestCase:
updatecfgDict = {'maxSQLLength':1048576,'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 ,
"jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143,
"wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143}
def init(self, conn, logSql): def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__) tdLog.debug("start to execute %s" % __file__)

View File

@ -67,6 +67,7 @@ class TDTestCase:
def check_result_auto_sin(self ,origin_query , pow_query): def check_result_auto_sin(self ,origin_query , pow_query):
pow_result = tdSql.getResult(pow_query) pow_result = tdSql.getResult(pow_query)
origin_result = tdSql.getResult(origin_query) origin_result = tdSql.getResult(origin_query)
auto_result =[] auto_result =[]
@ -80,23 +81,11 @@ class TDTestCase:
elem = math.sin(elem) elem = math.sin(elem)
row_check.append(elem) row_check.append(elem)
auto_result.append(row_check) auto_result.append(row_check)
tdSql.query(pow_query)
check_status = True
for row_index , row in enumerate(pow_result): for row_index , row in enumerate(pow_result):
for col_index , elem in enumerate(row): for col_index , elem in enumerate(row):
if auto_result[row_index][col_index] is None and elem: tdSql.checkData(row_index ,col_index ,auto_result[row_index][col_index])
check_status = False
elif auto_result[row_index][col_index] is not None and (auto_result[row_index][col_index] - elem > 0.00000001):
print("====,auto_result[row_index][col_index]:",auto_result[row_index][col_index], "elem:", elem)
check_status = False
else:
pass
if not check_status:
tdLog.notice("sin function value has not as expected , sql is \"%s\" "%pow_query )
sys.exit(1)
else:
tdLog.info("sin value check pass , it work as expected ,sql is \"%s\" "%pow_query )
def test_errors(self, dbname="db"): def test_errors(self, dbname="db"):
error_sql_lists = [ error_sql_lists = [
@ -393,7 +382,7 @@ class TDTestCase:
tdSql.checkData(0,4,-0.100000000) tdSql.checkData(0,4,-0.100000000)
tdSql.checkData(0,5,0.000000000) tdSql.checkData(0,5,0.000000000)
def check_boundary_values(self, dbname="db"): def check_boundary_values(self, dbname="testdb"):
PI=3.1415926 PI=3.1415926
@ -418,7 +407,7 @@ class TDTestCase:
tdSql.error( tdSql.error(
f"insert into {dbname}.sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" f"insert into {dbname}.sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
) )
self.check_result_auto_sin( f"select abs(c1), abs(c2), abs(c3) , abs(c4), abs(c5) from {dbname}.sub1_bound ", f"select sin(abs(c1)), sin(abs(c2)) ,sin(abs(c3)), sin(abs(c4)), sin(abs(c5)) from {dbname}.sub1_bound") self.check_result_auto_sin( f"select abs(c1), abs(c2), abs(c3) , abs(c4) from {dbname}.sub1_bound ", f"select sin(abs(c1)), sin(abs(c2)) ,sin(abs(c3)), sin(abs(c4)) from {dbname}.sub1_bound")
self.check_result_auto_sin( f"select c1, c2, c3 , c3, c2 ,c1 from {dbname}.sub1_bound ", f"select sin(c1), sin(c2) ,sin(c3), sin(c3), sin(c2) ,sin(c1) from {dbname}.sub1_bound") self.check_result_auto_sin( f"select c1, c2, c3 , c3, c2 ,c1 from {dbname}.sub1_bound ", f"select sin(c1), sin(c2) ,sin(c3), sin(c3), sin(c2) ,sin(c1) from {dbname}.sub1_bound")
@ -449,24 +438,21 @@ class TDTestCase:
tdSql.checkData(0,2,math.sin(32767.000000000)) tdSql.checkData(0,2,math.sin(32767.000000000))
tdSql.checkData(0,3,math.sin(63.500000000)) tdSql.checkData(0,3,math.sin(63.500000000))
tdSql.execute("create stable {dbname}.st (ts timestamp, num1 float, num2 double) tags (t1 int);") tdSql.execute(f"create stable {dbname}.st (ts timestamp, num1 float, num2 double) tags (t1 int);")
tdSql.execute(f'create table {dbname}.tb1 using {dbname}.st tags (1)') 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}.tb2 using {dbname}.st tags (2)')
tdSql.execute(f'create table {dbname}.tb3 using {dbname}.st tags (3)') tdSql.execute(f'create table {dbname}.tb3 using {dbname}.st tags (3)')
tdSql.execute('insert into {dbname}.tb1 values (now()-40s, {}, {})'.format(PI/2 ,PI/2 )) tdSql.execute(f'insert into {dbname}.tb1 values (now()-40s, {PI/2}, {PI/2})')
tdSql.execute('insert into {dbname}.tb1 values (now()-30s, {}, {})'.format(PI ,PI )) tdSql.execute(f'insert into {dbname}.tb1 values (now()-30s, {PI}, {PI})')
tdSql.execute('insert into {dbname}.tb1 values (now()-20s, {}, {})'.format(PI*1.5 ,PI*1.5)) tdSql.execute(f'insert into {dbname}.tb1 values (now()-20s, {PI*1.5}, {PI*1.5})')
tdSql.execute('insert into {dbname}.tb1 values (now()-10s, {}, {})'.format(PI*2 ,PI*2)) tdSql.execute(f'insert into {dbname}.tb1 values (now()-10s, {PI*2}, {PI*2})')
tdSql.execute('insert into {dbname}.tb1 values (now(), {}, {})'.format(PI*2.5 ,PI*2.5)) tdSql.execute(f'insert into {dbname}.tb1 values (now(), {PI*2.5}, {PI*2.5})')
tdSql.execute('insert into {dbname}.tb2 values (now()-40s, {}, {})'.format(PI/2 ,PI/2 )) tdSql.execute(f'insert into {dbname}.tb2 values (now()-40s, {PI/2}, {PI/2})')
tdSql.execute('insert into {dbname}.tb2 values (now()-30s, {}, {})'.format(PI ,PI )) tdSql.execute(f'insert into {dbname}.tb2 values (now()-30s, {PI}, {PI})')
tdSql.execute('insert into {dbname}.tb2 values (now()-20s, {}, {})'.format(PI*1.5 ,PI*1.5)) tdSql.execute(f'insert into {dbname}.tb2 values (now()-20s, {PI*1.5}, {PI*1.5})')
tdSql.execute('insert into {dbname}.tb2 values (now()-10s, {}, {})'.format(PI*2 ,PI*2)) tdSql.execute(f'insert into {dbname}.tb2 values (now()-10s, {PI*2}, {PI*2})')
tdSql.execute('insert into {dbname}.tb2 values (now(), {}, {})'.format(PI*2.5 ,PI*2.5)) tdSql.execute(f'insert into {dbname}.tb2 values (now(), {PI*2.5}, {PI*2.5})')
for i in range(100):
tdSql.execute('insert into {dbname}.tb3 values (now()+{}s, {}, {})'.format(i,PI*(5+i)/2 ,PI*(5+i)/2))
self.check_result_auto_sin(f"select num1,num2 from {dbname}.tb3;" , f"select sin(num1),sin(num2) from {dbname}.tb3") self.check_result_auto_sin(f"select num1,num2 from {dbname}.tb3;" , f"select sin(num1),sin(num2) from {dbname}.tb3")
@ -500,18 +486,19 @@ class TDTestCase:
self.basic_sin_function() self.basic_sin_function()
tdLog.printNoPrefix("==========step5: big number sin query ============") tdLog.printNoPrefix("==========step5: sin filter query ============")
self.abs_func_filter()
tdLog.printNoPrefix("==========step6: big number sin query ============")
self.test_big_number() self.test_big_number()
tdLog.printNoPrefix("==========step6: sin boundary query ============") tdLog.printNoPrefix("==========step7: sin boundary query ============")
self.check_boundary_values() self.check_boundary_values()
tdLog.printNoPrefix("==========step7: sin filter query ============")
self.abs_func_filter()
tdLog.printNoPrefix("==========step8: check sin result of stable query ============") tdLog.printNoPrefix("==========step8: check sin result of stable query ============")

View File

@ -83,21 +83,11 @@ class TDTestCase:
row_check.append(elem) row_check.append(elem)
auto_result.append(row_check) auto_result.append(row_check)
check_status = True tdSql.query(pow_query)
for row_index , row in enumerate(pow_result): for row_index , row in enumerate(pow_result):
for col_index , elem in enumerate(row): for col_index , elem in enumerate(row):
if auto_result[row_index][col_index] == None and not (auto_result[row_index][col_index] == None and elem == None): tdSql.checkData(row_index ,col_index ,auto_result[row_index][col_index])
check_status = False
elif auto_result[row_index][col_index] != None and (auto_result[row_index][col_index] - elem > 0.00000001):
check_status = False
else:
pass
if not check_status:
tdLog.notice("sqrt function value has not as expected , sql is \"%s\" "%pow_query )
sys.exit(1)
else:
tdLog.info("sqrt value check pass , it work as expected ,sql is \"%s\" "%pow_query )
def test_errors(self, dbname="db"): def test_errors(self, dbname="db"):
error_sql_lists = [ error_sql_lists = [
@ -452,19 +442,19 @@ class TDTestCase:
) )
tdSql.execute(f'create table {dbname}.sub1_bound using {dbname}.stb_bound tags ( 1 )') tdSql.execute(f'create table {dbname}.sub1_bound using {dbname}.stb_bound tags ( 1 )')
tdSql.execute( tdSql.execute(
f"insert into sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" f"insert into {dbname}.sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
) )
tdSql.execute( tdSql.execute(
f"insert into sub1_bound values ( now()-1s, -2147483647, -9223372036854775807, -32767, -127, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" f"insert into {dbname}.sub1_bound values ( now()-1s, -2147483647, -9223372036854775807, -32767, -127, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
) )
tdSql.execute( tdSql.execute(
f"insert into sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" f"insert into {dbname}.sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
) )
tdSql.execute( tdSql.execute(
f"insert into sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" f"insert into {dbname}.sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
) )
tdSql.error( tdSql.error(
f"insert into sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" f"insert into {dbname}.sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
) )
self.check_result_auto_sqrt( f"select abs(c1), abs(c2), abs(c3) , abs(c4), abs(c5) from {dbname}.sub1_bound ", f"select sqrt(abs(c1)), sqrt(abs(c2)) ,sqrt(abs(c3)), sqrt(abs(c4)), sqrt(abs(c5)) from {dbname}.sub1_bound") self.check_result_auto_sqrt( f"select abs(c1), abs(c2), abs(c3) , abs(c4), abs(c5) from {dbname}.sub1_bound ", f"select sqrt(abs(c1)), sqrt(abs(c2)) ,sqrt(abs(c3)), sqrt(abs(c4)), sqrt(abs(c5)) from {dbname}.sub1_bound")

View File

@ -59,7 +59,7 @@ class TDTestCase:
( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now()+6a ) ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now()+6a )
( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" )
( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" )
( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) ( '2022-12-31 01:01:36.000', 9, -99999, -999, -99, -9.99, -99999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" )
( '2023-02-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( '2023-02-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
''' '''
) )
@ -80,22 +80,10 @@ class TDTestCase:
elem = math.tan(elem) elem = math.tan(elem)
row_check.append(elem) row_check.append(elem)
auto_result.append(row_check) auto_result.append(row_check)
tdSql.query(pow_query)
check_status = True
for row_index , row in enumerate(pow_result): for row_index , row in enumerate(pow_result):
for col_index , elem in enumerate(row): for col_index , elem in enumerate(row):
if auto_result[row_index][col_index] == None and not (auto_result[row_index][col_index] == None and elem == None): tdSql.checkData(row_index , col_index ,auto_result[row_index][col_index] )
check_status = False
elif auto_result[row_index][col_index] != None and (auto_result[row_index][col_index] - elem > 0.00000001):
check_status = False
else:
pass
if not check_status:
tdLog.notice("tan function value has not as expected , sql is \"%s\" "%pow_query )
sys.exit(1)
else:
tdLog.info("tan value check pass , it work as expected ,sql is \"%s\" "%pow_query )
def test_errors(self, dbname="db"): def test_errors(self, dbname="db"):
error_sql_lists = [ error_sql_lists = [
@ -244,7 +232,7 @@ class TDTestCase:
tdSql.checkData(3, 4, 33) tdSql.checkData(3, 4, 33)
tdSql.checkData(5, 5, None) tdSql.checkData(5, 5, None)
self.check_result_auto_tan( f"select abs(c1), abs(c2), abs(c3) , abs(c4), abs(c5) from {dbname}.t1", f"select tan(abs(c1)), tan(abs(c2)) ,tan(abs(c3)), tan(abs(c4)), tan(abs(c5)) from {dbname}.t1") self.check_result_auto_tan( f"select abs(c1), abs(c2), abs(c3) , abs(c4) from {dbname}.t1", f"select tan(abs(c1)), tan(abs(c2)) ,tan(abs(c3)), tan(abs(c4)) from {dbname}.t1")
# used for sub table # used for sub table
tdSql.query(f"select c2 ,tan(c2) from {dbname}.ct1") tdSql.query(f"select c2 ,tan(c2) from {dbname}.ct1")
@ -402,21 +390,21 @@ class TDTestCase:
) )
tdSql.execute(f'create table {dbname}.sub1_bound using {dbname}.stb_bound tags ( 1 )') tdSql.execute(f'create table {dbname}.sub1_bound using {dbname}.stb_bound tags ( 1 )')
tdSql.execute( tdSql.execute(
f"insert into sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" f"insert into {dbname}.sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
) )
tdSql.execute( tdSql.execute(
f"insert into sub1_bound values ( now()-1s, -2147483647, -9223372036854775807, -32767, -127, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" f"insert into {dbname}.sub1_bound values ( now()-1s, -2147483647, -9223372036854775807, -32767, -127, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
) )
tdSql.execute( tdSql.execute(
f"insert into sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" f"insert into {dbname}.sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
) )
tdSql.execute( tdSql.execute(
f"insert into sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" f"insert into {dbname}.sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
) )
tdSql.error( tdSql.error(
f"insert into sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" f"insert into {dbname}.sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
) )
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 abs(c1), abs(c2), abs(c3) , abs(c4) from {dbname}.sub1_bound ", f"select tan(abs(c1)), tan(abs(c2)) ,tan(abs(c3)), tan(abs(c4)) 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 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")
@ -463,9 +451,6 @@ class TDTestCase:
tdSql.execute(f'insert into {dbname}.tb2 values (now()-10s, {PI*2}, {PI*2})') 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})') tdSql.execute(f'insert into {dbname}.tb2 values (now(), {PI*2.5}, {PI*2.5})')
for i in range(100):
tdSql.execute(f'insert into tb3 values (now()+{i}s, {PI*(5+i)/2}, {PI*(5+i)/2})')
self.check_result_auto_tan(f"select num1,num2 from {dbname}.tb3;" , f"select tan(num1),tan(num2) from {dbname}.tb3") self.check_result_auto_tan(f"select num1,num2 from {dbname}.tb3;" , f"select tan(num1),tan(num2) from {dbname}.tb3")
def support_super_table_test(self, dbname="db"): def support_super_table_test(self, dbname="db"):

View File

@ -25,6 +25,7 @@ class TDTestCase:
self.ntbname = f'{self.dbname}.ntb' self.ntbname = f'{self.dbname}.ntb'
self.stbname = f'{self.dbname}.stb' self.stbname = f'{self.dbname}.stb'
self.ctbname = f'{self.dbname}.ctb' self.ctbname = f'{self.dbname}.ctb'
def check_ms_timestamp(self,unit,date_time): def check_ms_timestamp(self,unit,date_time):
if unit.lower() == '1a': if unit.lower() == '1a':
for i in range(len(self.ts_str)): for i in range(len(self.ts_str)):
@ -50,6 +51,7 @@ class TDTestCase:
for i in range(len(self.ts_str)): for i in range(len(self.ts_str)):
ts_result = self.get_time.get_ms_timestamp(str(tdSql.queryResult[i][0])) ts_result = self.get_time.get_ms_timestamp(str(tdSql.queryResult[i][0]))
tdSql.checkEqual(ts_result,int(date_time[i]/1000/60/60/24/7)*7*24*60*60*1000) tdSql.checkEqual(ts_result,int(date_time[i]/1000/60/60/24/7)*7*24*60*60*1000)
def check_us_timestamp(self,unit,date_time): def check_us_timestamp(self,unit,date_time):
if unit.lower() == '1u': if unit.lower() == '1u':
for i in range(len(self.ts_str)): for i in range(len(self.ts_str)):
@ -79,31 +81,41 @@ class TDTestCase:
for i in range(len(self.ts_str)): for i in range(len(self.ts_str)):
ts_result = self.get_time.get_us_timestamp(str(tdSql.queryResult[i][0])) ts_result = self.get_time.get_us_timestamp(str(tdSql.queryResult[i][0]))
tdSql.checkEqual(ts_result,int(date_time[i]/1000/1000/60/60/24/7)*7*24*60*60*1000*1000) tdSql.checkEqual(ts_result,int(date_time[i]/1000/1000/60/60/24/7)*7*24*60*60*1000*1000)
def check_ns_timestamp(self,unit,date_time):
def check_ns_timestamp(self, unit, date_time:list):
if unit.lower() == '1b': if unit.lower() == '1b':
for i in range(len(self.ts_str)): for i in range(len(self.ts_str)):
tdSql.checkEqual(tdSql.queryResult[i][0],int(date_time[i])) ts_result = self.get_time.get_ns_timestamp(str(tdSql.queryResult[i][0]))
tdSql.checkEqual(ts_result,int(date_time[i]))
elif unit.lower() == '1u': elif unit.lower() == '1u':
for i in range(len(self.ts_str)): for i in range(len(self.ts_str)):
tdSql.checkEqual(tdSql.queryResult[i][0],int(date_time[i]*1000/1000/1000)*1000) ts_result = self.get_time.get_ns_timestamp(str(tdSql.queryResult[i][0]))
tdSql.checkEqual(ts_result,int(date_time[i]*1000/1000/1000)*1000)
elif unit.lower() == '1a': elif unit.lower() == '1a':
for i in range(len(self.ts_str)): for i in range(len(self.ts_str)):
tdSql.checkEqual(tdSql.queryResult[i][0],int(date_time[i]*1000/1000/1000/1000)*1000*1000) ts_result = self.get_time.get_ns_timestamp(str(tdSql.queryResult[i][0]))
tdSql.checkEqual(ts_result,int(date_time[i]*1000/1000/1000/1000)*1000*1000)
elif unit.lower() == '1s': elif unit.lower() == '1s':
for i in range(len(self.ts_str)): for i in range(len(self.ts_str)):
tdSql.checkEqual(tdSql.queryResult[i][0],int(date_time[i]*1000/1000/1000/1000/1000)*1000*1000*1000) ts_result = self.get_time.get_ns_timestamp(str(tdSql.queryResult[i][0]))
tdSql.checkEqual(ts_result,int(date_time[i]*1000/1000/1000/1000/1000)*1000*1000*1000)
elif unit.lower() == '1m': elif unit.lower() == '1m':
for i in range(len(self.ts_str)): for i in range(len(self.ts_str)):
tdSql.checkEqual(tdSql.queryResult[i][0],int(date_time[i]*1000/1000/1000/1000/1000/60)*60*1000*1000*1000) ts_result = self.get_time.get_ns_timestamp(str(tdSql.queryResult[i][0]))
tdSql.checkEqual(ts_result,int(date_time[i]*1000/1000/1000/1000/1000/60)*60*1000*1000*1000)
elif unit.lower() == '1h': elif unit.lower() == '1h':
for i in range(len(self.ts_str)): for i in range(len(self.ts_str)):
tdSql.checkEqual(tdSql.queryResult[i][0],int(date_time[i]*1000/1000/1000/1000/1000/60/60)*60*60*1000*1000*1000 ) ts_result = self.get_time.get_ns_timestamp(str(tdSql.queryResult[i][0]))
tdSql.checkEqual(ts_result,int(date_time[i]*1000/1000/1000/1000/1000/60/60)*60*60*1000*1000*1000 )
elif unit.lower() == '1d': elif unit.lower() == '1d':
for i in range(len(self.ts_str)): for i in range(len(self.ts_str)):
tdSql.checkEqual(tdSql.queryResult[i][0],int(date_time[i]*1000/1000/1000/1000/1000/60/60/24)*24*60*60*1000*1000*1000 ) ts_result = self.get_time.get_ns_timestamp(str(tdSql.queryResult[i][0]))
tdSql.checkEqual(ts_result,int(date_time[i]*1000/1000/1000/1000/1000/60/60/24)*24*60*60*1000*1000*1000 )
elif unit.lower() == '1w': elif unit.lower() == '1w':
for i in range(len(self.ts_str)): for i in range(len(self.ts_str)):
tdSql.checkEqual(tdSql.queryResult[i][0],int(date_time[i]*1000/1000/1000/1000/1000/60/60/24/7)*7*24*60*60*1000*1000*1000) ts_result = self.get_time.get_ns_timestamp(str(tdSql.queryResult[i][0]))
tdSql.checkEqual(ts_result,int(date_time[i]*1000/1000/1000/1000/1000/60/60/24/7)*7*24*60*60*1000*1000*1000)
def check_tb_type(self,unit,tb_type): def check_tb_type(self,unit,tb_type):
if tb_type.lower() == 'ntb': if tb_type.lower() == 'ntb':
tdSql.query(f'select timetruncate(ts,{unit}) from {self.ntbname}') tdSql.query(f'select timetruncate(ts,{unit}) from {self.ntbname}')
@ -111,6 +123,7 @@ class TDTestCase:
tdSql.query(f'select timetruncate(ts,{unit}) from {self.ctbname}') tdSql.query(f'select timetruncate(ts,{unit}) from {self.ctbname}')
elif tb_type.lower() == 'stb': elif tb_type.lower() == 'stb':
tdSql.query(f'select timetruncate(ts,{unit}) from {self.stbname}') tdSql.query(f'select timetruncate(ts,{unit}) from {self.stbname}')
def data_check(self,date_time,precision,tb_type): def data_check(self,date_time,precision,tb_type):
for unit in self.time_unit: for unit in self.time_unit:
if (unit.lower() == '1u' and precision.lower() == 'ms') or (unit.lower() == '1b' and precision.lower() == 'us') or (unit.lower() == '1b' and precision.lower() == 'ms'): if (unit.lower() == '1u' and precision.lower() == 'ms') or (unit.lower() == '1b' and precision.lower() == 'us') or (unit.lower() == '1b' and precision.lower() == 'ms'):
@ -139,16 +152,19 @@ class TDTestCase:
tdSql.error(f'select timetruncate(ts,{unit}) from {self.ctbname}') tdSql.error(f'select timetruncate(ts,{unit}) from {self.ctbname}')
elif tb_type.lower() == 'stb': elif tb_type.lower() == 'stb':
tdSql.error(f'select timetruncate(ts,{unit}) from {self.stbname}') tdSql.error(f'select timetruncate(ts,{unit}) from {self.stbname}')
def function_check_ntb(self): def function_check_ntb(self):
for precision in self.db_param_precision: for precision in self.db_param_precision:
tdSql.execute(f'drop database if exists {self.dbname}') tdSql.execute(f'drop database if exists {self.dbname}')
tdSql.execute(f'create database {self.dbname} precision "{precision}"') tdSql.execute(f'create database {self.dbname} precision "{precision}"')
tdLog.info(f"=====now is in a {precision} database=====")
tdSql.execute(f'use {self.dbname}') tdSql.execute(f'use {self.dbname}')
tdSql.execute(f'create table {self.ntbname} (ts timestamp,c0 int)') tdSql.execute(f'create table {self.ntbname} (ts timestamp,c0 int)')
for ts in self.ts_str: for ts in self.ts_str:
tdSql.execute(f'insert into {self.ntbname} values("{ts}",1)') tdSql.execute(f'insert into {self.ntbname} values("{ts}",1)')
date_time = self.get_time.time_transform(self.ts_str,precision) date_time = self.get_time.time_transform(self.ts_str,precision)
self.data_check(date_time,precision,'ntb') self.data_check(date_time,precision,'ntb')
def function_check_stb(self): def function_check_stb(self):
for precision in self.db_param_precision: for precision in self.db_param_precision:
tdSql.execute(f'drop database if exists {self.dbname}') tdSql.execute(f'drop database if exists {self.dbname}')
@ -161,9 +177,11 @@ class TDTestCase:
date_time = self.get_time.time_transform(self.ts_str,precision) date_time = self.get_time.time_transform(self.ts_str,precision)
self.data_check(date_time,precision,'ctb') self.data_check(date_time,precision,'ctb')
self.data_check(date_time,precision,'stb') self.data_check(date_time,precision,'stb')
def run(self): def run(self):
self.function_check_ntb() self.function_check_ntb()
self.function_check_stb() self.function_check_stb()
def stop(self): def stop(self):
tdSql.close() tdSql.close()
tdLog.success("%s successfully executed" % __file__) tdLog.success("%s successfully executed" % __file__)

View File

@ -22,7 +22,7 @@ class TDTestCase:
def init(self, conn, logSql): def init(self, conn, logSql):
tdLog.debug(f"start to excute {__file__}") tdLog.debug(f"start to excute {__file__}")
tdSql.init(conn.cursor(), True) tdSql.init(conn.cursor(), False)
def create_ctable(self,tsql=None, dbName='db',stbName='stb',ctbPrefix='ctb',ctbNum=1): def create_ctable(self,tsql=None, dbName='db',stbName='stb',ctbPrefix='ctb',ctbNum=1):
tsql.execute("use %s" %dbName) tsql.execute("use %s" %dbName)
@ -32,10 +32,10 @@ class TDTestCase:
for i in range(ctbNum): for i in range(ctbNum):
tagValue = 'beijing' tagValue = 'beijing'
if (i % 10 == 0): if (i % 10 == 0):
sql += " %s%d using %s (name,fleet,driver,device_version,load_capacity,fuel_capacity,nominal_fuel_consumption) tags('truck_%d', 'South%d','Trish%d','v2.%d', 1500+%d*20, 150+%d*2, 5+%d)"%(ctbPrefix,i,stbName,i,i,i,i,(1500+i*20),(150+i*2),(5+i)) sql += f" {dbName}.%s%d using %s (name,fleet,driver,device_version,load_capacity,fuel_capacity,nominal_fuel_consumption) tags('truck_%d', 'South%d','Trish%d','v2.%d', 1500+%d*20, 150+%d*2, 5+%d)"%(ctbPrefix,i,stbName,i,i,i,i,(1500+i*20),(150+i*2),(5+i))
else: else:
model = 'H-%d'%i model = 'H-%d'%i
sql += " %s%d using %s tags('truck_%d', 'South%d','Trish%d','%s','v2.%d', %d, %d,%d)"%(ctbPrefix,i,stbName,i,i,i,model,i,(1500+i*20),(150+i*2),(5+i)) sql += f" {dbName}.%s%d using %s tags('truck_%d', 'South%d','Trish%d','%s','v2.%d', %d, %d,%d)"%(ctbPrefix,i,stbName,i,i,i,model,i,(1500+i*20),(150+i*2),(5+i))
if (i > 0) and (i%1000 == 0): if (i > 0) and (i%1000 == 0):
tsql.execute(sql) tsql.execute(sql)
sql = pre_create sql = pre_create
@ -54,7 +54,7 @@ class TDTestCase:
startTs = int(round(t * 1000)) startTs = int(round(t * 1000))
for i in range(ctbNum): for i in range(ctbNum):
sql += " %s%d values "%(ctbPrefix,i) sql += f" {dbName}.%s%d values "%(ctbPrefix,i)
for j in range(rowsPerTbl): for j in range(rowsPerTbl):
if(ctbPrefix=="rct"): if(ctbPrefix=="rct"):
sql += f"({startTs+j*60000}, {80+j}, {90+j}, {85+j}, {30+j*10}, {1.2*j}, {221+j*2}, {20+j*0.2}) " sql += f"({startTs+j*60000}, {80+j}, {90+j}, {85+j}, {30+j*10}, {1.2*j}, {221+j*2}, {20+j*0.2}) "
@ -66,7 +66,7 @@ class TDTestCase:
# tdLog.debug("2insert sql:%s"%sql) # tdLog.debug("2insert sql:%s"%sql)
tsql.execute(sql) tsql.execute(sql)
if j < rowsPerTbl - 1: if j < rowsPerTbl - 1:
sql = "insert into %s%d values " %(ctbPrefix,i) sql = f"insert into {dbName}.%s%d values " %(ctbPrefix,i)
else: else:
sql = "insert into " sql = "insert into "
if sql != pre_insert: if sql != pre_insert:
@ -77,8 +77,8 @@ class TDTestCase:
def prepareData(self): def prepareData(self):
dbname="db_tsbs" dbname="db_tsbs"
stabname1="readings" stabname1=f"{dbname}.readings"
stabname2="diagnostics" stabname2=f"{dbname}.diagnostics"
ctbnamePre1="rct" ctbnamePre1="rct"
ctbnamePre2="dct" ctbnamePre2="dct"
ctbNums=50 ctbNums=50
@ -133,84 +133,84 @@ class TDTestCase:
# tdLog.info("avg value check pass , it work as expected ,sql is \"%s\" "%check_query ) # tdLog.info("avg value check pass , it work as expected ,sql is \"%s\" "%check_query )
def tsbsIotQuery(self,insertinto=True): def tsbsIotQuery(self,insertinto=True, dbname="db_tsbs"):
tdSql.execute("use db_tsbs") tdSql.execute("use db_tsbs")
# test interval and partition # test interval and partition
tdSql.query(" SELECT avg(velocity) as mean_velocity ,name,driver,fleet FROM readings WHERE ts > 1451606400000 AND ts <= 1451606460000 partition BY name,driver,fleet; ") tdSql.query(f"select avg(velocity) as mean_velocity ,name,driver,fleet from {dbname}.readings WHERE ts > 1451606400000 AND ts <= 1451606460000 partition BY name,driver,fleet; ")
parRows=tdSql.queryRows parRows=tdSql.queryRows
tdSql.query(" SELECT avg(velocity) as mean_velocity ,name,driver,fleet FROM readings WHERE ts > 1451606400000 AND ts <= 1451606460000 partition BY name,driver,fleet interval(10m); ") tdSql.query(f"select avg(velocity) as mean_velocity ,name,driver,fleet from {dbname}.readings WHERE ts > 1451606400000 AND ts <= 1451606460000 partition BY name,driver,fleet interval(10m); ")
tdSql.checkRows(parRows) tdSql.checkRows(parRows)
# test insert into # test insert into
if insertinto == True : if insertinto == True :
tdSql.execute("create table testsnode (ts timestamp, c1 float,c2 binary(30),c3 binary(30),c4 binary(30)) ;") tdSql.execute(f"create table {dbname}.testsnode (ts timestamp, c1 float,c2 binary(30),c3 binary(30),c4 binary(30)) ;")
tdSql.query("insert into testsnode SELECT ts,avg(velocity) as mean_velocity,name,driver,fleet FROM readings WHERE ts > 1451606400000 AND ts <= 1451606460000 partition BY name,driver,fleet,ts interval(10m);") tdSql.query(f"insert into {dbname}.testsnode SELECT ts,avg(velocity) as mean_velocity,name,driver,fleet from {dbname}.readings WHERE ts > 1451606400000 AND ts <= 1451606460000 partition BY name,driver,fleet,ts interval(10m);")
tdSql.query("insert into testsnode(ts,c1,c2,c3,c4) SELECT ts,avg(velocity) as mean_velocity,name,driver,fleet FROM readings WHERE ts > 1451606400000 AND ts <= 1451606460000 partition BY name,driver,fleet,ts interval(10m);") tdSql.query(f"insert into {dbname}.testsnode(ts,c1,c2,c3,c4) SELECT ts,avg(velocity) as mean_velocity,name,driver,fleet from {dbname}.readings WHERE ts > 1451606400000 AND ts <= 1451606460000 partition BY name,driver,fleet,ts interval(10m);")
# test paitition interval fill # test paitition interval fill
tdSql.query("SELECT name,floor(avg(velocity)/10)/floor(avg(velocity)/10) AS mv FROM readings WHERE name!='' AND ts > '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by name interval(10m) fill(value,0) ;") tdSql.query(f"select name,floor(avg(velocity)/10)/floor(avg(velocity)/10) AS mv from {dbname}.readings WHERE name!='' AND ts > '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by name interval(10m) fill(value,0) ;")
# test partition interval limit (PRcore-TD-17410) # test partition interval limit (PRcore-TD-17410)
tdSql.query("select name,driver from (SELECT name,driver,fleet ,avg(velocity) as mean_velocity FROM readings partition BY name,driver,fleet interval (10m) limit 1);") tdSql.query(f"select name,driver from (SELECT name,driver,fleet ,avg(velocity) as mean_velocity from {dbname}.readings partition BY name,driver,fleet interval (10m) limit 1);")
tdSql.checkRows(self.ctbNums) tdSql.checkRows(self.ctbNums)
# test partition interval Pseudo time-column # test partition interval Pseudo time-column
tdSql.query("SELECT count(ms1)/144 FROM (SELECT _wstart as ts1,model, fleet,avg(status) AS ms1 FROM diagnostics WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by model, fleet interval(10m)) WHERE ts1 >= '2016-01-01T00:00:00Z' AND ts1 < '2016-01-05T00:00:01Z' AND ms1<1;") tdSql.query(f"select count(ms1)/144 FROM (SELECT _wstart as ts1,model, fleet,avg(status) AS ms1 from {dbname}.diagnostics WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by model, fleet interval(10m)) WHERE ts1 >= '2016-01-01T00:00:00Z' AND ts1 < '2016-01-05T00:00:01Z' AND ms1<1;")
# 1 high-load: # 1 high-load:
tdSql.query("SELECT ts,name,driver,current_load,load_capacity FROM (SELECT last(ts) as ts,name,driver, current_load,load_capacity FROM diagnostics WHERE fleet = 'South' partition by name,driver) WHERE current_load>= (0.9 * load_capacity) partition by name ORDER BY name desc, ts DESC;") tdSql.query(f"select ts,name,driver,current_load,load_capacity FROM (SELECT last(ts) as ts,name,driver, current_load,load_capacity from {dbname}.diagnostics WHERE fleet = 'South' partition by name,driver) WHERE current_load>= (0.9 * load_capacity) partition by name ORDER BY name desc, ts DESC;")
tdSql.query("SELECT ts,name,driver,current_load,load_capacity FROM (SELECT last(ts) as ts,name,driver, current_load,load_capacity FROM diagnostics WHERE fleet = 'South' partition by name,driver) WHERE current_load>= (0.9 * load_capacity) partition by name ORDER BY name ;") tdSql.query(f"select ts,name,driver,current_load,load_capacity FROM (SELECT last(ts) as ts,name,driver, current_load,load_capacity from {dbname}.diagnostics WHERE fleet = 'South' partition by name,driver) WHERE current_load>= (0.9 * load_capacity) partition by name ORDER BY name ;")
# 2 stationary-trucks # 2 stationary-trucks
tdSql.query("select name,driver from (SELECT name,driver,fleet ,avg(velocity) as mean_velocity FROM readings WHERE ts > '2016-01-01T15:07:21Z' AND ts <= '2016-01-01T16:17:21Z' partition BY name,driver,fleet interval(10m) LIMIT 1)") tdSql.query(f"select name,driver from (SELECT name,driver,fleet ,avg(velocity) as mean_velocity from {dbname}.readings WHERE ts > '2016-01-01T15:07:21Z' AND ts <= '2016-01-01T16:17:21Z' partition BY name,driver,fleet interval(10m) LIMIT 1)")
tdSql.query("select name,driver from (SELECT name,driver,fleet ,avg(velocity) as mean_velocity FROM readings WHERE ts > '2016-01-01T15:07:21Z' AND ts <= '2016-01-01T16:17:21Z' partition BY name,driver,fleet interval(10m) LIMIT 1) WHERE fleet = 'West' AND mean_velocity < 1000 partition BY name") tdSql.query(f"select name,driver from (SELECT name,driver,fleet ,avg(velocity) as mean_velocity from {dbname}.readings WHERE ts > '2016-01-01T15:07:21Z' AND ts <= '2016-01-01T16:17:21Z' partition BY name,driver,fleet interval(10m) LIMIT 1) WHERE fleet = 'West' AND mean_velocity < 1000 partition BY name")
# 3 long-driving-sessions # 3 long-driving-sessions
tdSql.query("SELECT name,driver FROM(SELECT name,driver,count(*) AS ten_min FROM(SELECT _wstart as ts,name,driver,avg(velocity) as mean_velocity FROM readings where ts > '2016-01-01T00:00:34Z' AND ts <= '2016-01-01T04:00:34Z' partition BY name,driver interval(10m)) WHERE mean_velocity > 1 GROUP BY name,driver) WHERE ten_min > 22 ;") tdSql.query(f"select name,driver FROM(SELECT name,driver,count(*) AS ten_min FROM(SELECT _wstart as ts,name,driver,avg(velocity) as mean_velocity from {dbname}.readings where ts > '2016-01-01T00:00:34Z' AND ts <= '2016-01-01T04:00:34Z' partition BY name,driver interval(10m)) WHERE mean_velocity > 1 GROUP BY name,driver) WHERE ten_min > 22 ;")
#4 long-daily-sessions #4 long-daily-sessions
tdSql.query("SELECT name,driver FROM(SELECT name,driver,count(*) AS ten_min FROM(SELECT name,driver,avg(velocity) as mean_velocity FROM readings WHERE fleet ='West' AND ts > '2016-01-01T12:31:37Z' AND ts <= '2016-01-05T12:31:37Z' partition BY name,driver interval(10m) ) WHERE mean_velocity > 1 GROUP BY name,driver) WHERE ten_min > 60") tdSql.query(f"select name,driver FROM(SELECT name,driver,count(*) AS ten_min FROM(SELECT name,driver,avg(velocity) as mean_velocity from {dbname}.readings WHERE fleet ='West' AND ts > '2016-01-01T12:31:37Z' AND ts <= '2016-01-05T12:31:37Z' partition BY name,driver interval(10m) ) WHERE mean_velocity > 1 GROUP BY name,driver) WHERE ten_min > 60")
# 5. avg-daily-driving-duration # 5. avg-daily-driving-duration
tdSql.query("select _wstart as ts,fleet,name,driver,count(mv)/6 as hours_driven from ( select _wstart as ts,fleet,name,driver,avg(velocity) as mv from readings where ts > '2016-01-01T00:00:00Z' and ts < '2016-01-05T00:00:01Z' partition by fleet,name,driver interval(10m)) where ts > '2016-01-01T00:00:00Z' and ts < '2016-01-05T00:00:01Z' partition by fleet,name,driver interval(1d) ;") tdSql.query(f"select _wstart as ts,fleet,name,driver,count(mv)/6 as hours_driven from ( select _wstart as ts,fleet,name,driver,avg(velocity) as mv from {dbname}.readings where ts > '2016-01-01T00:00:00Z' and ts < '2016-01-05T00:00:01Z' partition by fleet,name,driver interval(10m)) where ts > '2016-01-01T00:00:00Z' and ts < '2016-01-05T00:00:01Z' partition by fleet,name,driver interval(1d) ;")
# # 6. avg-daily-driving-session # # 6. avg-daily-driving-session
# #taosc core dumped # #taosc core dumped
tdSql.query(" SELECT _wstart as ts,name,floor(avg(velocity)/5) AS mv FROM readings WHERE name is not null AND ts > '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by name interval(10m) fill(value,0);") tdSql.query(f"select _wstart as ts,name,floor(avg(velocity)/5) AS mv from {dbname}.readings WHERE name is not null AND ts > '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by name interval(10m) fill(value,0);")
# tdSql.query("select name,diff(mv) AS difka FROM (SELECT ts,name,mv FROM (SELECT _wstart as ts,name,floor(avg(velocity)/10)/floor(avg(velocity)/10) AS mv FROM readings WHERE name!='' AND ts > '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by name interval(10m) fill(value,0))) group BY name ;") # tdSql.query(f"select name,diff(mv) AS difka FROM (SELECT ts,name,mv FROM (SELECT _wstart as ts,name,floor(avg(velocity)/10)/floor(avg(velocity)/10) AS mv from {dbname}.readings WHERE name!='' AND ts > '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by name interval(10m) fill(value,0))) group BY name ;")
# tdSql.query("SELECT _wstart,name,floor(avg(velocity)/10)/floor(avg(velocity)/10) AS mv FROM readings WHERE name!='' AND ts > '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by name interval(10m) fill(value,0)") # tdSql.query(f"select _wstart,name,floor(avg(velocity)/10)/floor(avg(velocity)/10) AS mv from {dbname}.readings WHERE name!='' AND ts > '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by name interval(10m) fill(value,0)")
# 7. avg-load # 7. avg-load
tdSql.query("SELECT fleet, model,avg(ml) AS mean_load_percentage FROM (SELECT fleet, model,current_load/load_capacity AS ml FROM diagnostics partition BY name, fleet, model) partition BY fleet, model order by fleet ;") tdSql.query(f"select fleet, model,avg(ml) AS mean_load_percentage FROM (SELECT fleet, model,current_load/load_capacity AS ml from {dbname}.diagnostics partition BY name, fleet, model) partition BY fleet, model order by fleet ;")
# 8. daily-activity # 8. daily-activity
tdSql.query(" SELECT model,ms1 FROM (SELECT _wstart as ts1,model, fleet,avg(status) AS ms1 FROM diagnostics WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by model, fleet interval(10m) fill(value,0)) WHERE ts1 >= '2016-01-01T00:00:00Z' AND ts1 < '2016-01-05T00:00:01Z' AND ms1<1;") tdSql.query(f"select model,ms1 FROM (SELECT _wstart as ts1,model, fleet,avg(status) AS ms1 from {dbname}.diagnostics WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by model, fleet interval(10m) fill(value,0)) WHERE ts1 >= '2016-01-01T00:00:00Z' AND ts1 < '2016-01-05T00:00:01Z' AND ms1<1;")
tdSql.query(" SELECT model,ms1 FROM (SELECT _wstart as ts1,model, fleet,avg(status) AS ms1 FROM diagnostics WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by model, fleet interval(10m) ) WHERE ts1 >= '2016-01-01T00:00:00Z' AND ts1 < '2016-01-05T00:00:01Z' AND ms1<1;") tdSql.query(f"select model,ms1 FROM (SELECT _wstart as ts1,model, fleet,avg(status) AS ms1 from {dbname}.diagnostics WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by model, fleet interval(10m) ) WHERE ts1 >= '2016-01-01T00:00:00Z' AND ts1 < '2016-01-05T00:00:01Z' AND ms1<1;")
tdSql.query("SELECT _wstart,model,fleet,count(ms1)/144 FROM (SELECT _wstart as ts1,model, fleet,avg(status) AS ms1 FROM diagnostics WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by model, fleet interval(10m) fill(value,0)) WHERE ts1 >= '2016-01-01T00:00:00Z' AND ts1 < '2016-01-05T00:00:01Z' AND ms1<1 partition by model, fleet interval(1d) ;") tdSql.query(f"select _wstart,model,fleet,count(ms1)/144 FROM (SELECT _wstart as ts1,model, fleet,avg(status) AS ms1 from {dbname}.diagnostics WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by model, fleet interval(10m) fill(value,0)) WHERE ts1 >= '2016-01-01T00:00:00Z' AND ts1 < '2016-01-05T00:00:01Z' AND ms1<1 partition by model, fleet interval(1d) ;")
tdSql.query("SELECT _wstart as ts,model,fleet,count(ms1)/144 FROM (SELECT _wstart as ts1,model, fleet,avg(status) AS ms1 FROM diagnostics WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by model, fleet interval(10m) ) WHERE ts1 >= '2016-01-01T00:00:00Z' AND ts1 < '2016-01-05T00:00:01Z' AND ms1<1 partition by model, fleet interval(1d) ;") tdSql.query(f"select _wstart as ts,model,fleet,count(ms1)/144 FROM (SELECT _wstart as ts1,model, fleet,avg(status) AS ms1 from {dbname}.diagnostics WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by model, fleet interval(10m) ) WHERE ts1 >= '2016-01-01T00:00:00Z' AND ts1 < '2016-01-05T00:00:01Z' AND ms1<1 partition by model, fleet interval(1d) ;")
# 9. breakdown-frequency # 9. breakdown-frequency
# NULL ---count(NULL)=0 expect count(NULL)= 100 # NULL ---count(NULL)=0 expect count(NULL)= 100
tdSql.query("SELECT model,state_changed,count(state_changed) FROM (SELECT model,diff(broken_down) AS state_changed FROM (SELECT _wstart,model,cast(cast(floor(2*(sum(nzs)/count(nzs))) as bool) as int) AS broken_down FROM (SELECT ts,model, cast(cast(status as bool) as int) AS nzs FROM diagnostics WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' ) WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition BY model interval(10m)) partition BY model) where model is null partition BY model,state_changed ") tdSql.query(f"select model,state_changed,count(state_changed) FROM (SELECT model,diff(broken_down) AS state_changed FROM (SELECT _wstart,model,cast(cast(floor(2*(sum(nzs)/count(nzs))) as bool) as int) AS broken_down FROM (SELECT ts,model, cast(cast(status as bool) as int) AS nzs from {dbname}.diagnostics WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' ) WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition BY model interval(10m)) partition BY model) where model is null partition BY model,state_changed ")
parRows=tdSql.queryRows parRows=tdSql.queryRows
assert parRows != 0 , "query result is wrong, query rows %d but expect > 0 " %parRows assert parRows != 0 , "query result is wrong, query rows %d but expect > 0 " %parRows
tdSql.query(" SELECT model,state_changed,count(state_changed) FROM (SELECT model,diff(broken_down) AS state_changed FROM (SELECT _wstart,model,cast(cast(floor(2*(sum(nzs)/count(nzs))) as bool) as int) AS broken_down FROM (SELECT ts,model, cast(cast(status as bool) as int) AS nzs FROM diagnostics WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' ) WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition BY model interval(10m)) partition BY model) where state_changed =1 partition BY model,state_changed ;") tdSql.query(f"select model,state_changed,count(state_changed) FROM (SELECT model,diff(broken_down) AS state_changed FROM (SELECT _wstart,model,cast(cast(floor(2*(sum(nzs)/count(nzs))) as bool) as int) AS broken_down FROM (SELECT ts,model, cast(cast(status as bool) as int) AS nzs from {dbname}.diagnostics WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' ) WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition BY model interval(10m)) partition BY model) where state_changed =1 partition BY model,state_changed ;")
sql="select model,ctc from (SELECT model,count(state_changed) as ctc FROM (SELECT model,diff(broken_down) AS state_changed FROM (SELECT model,cast(cast(floor(2*(sum(nzs)/count(nzs))) as bool) as int) AS broken_down FROM (SELECT ts,model, cast(cast(status as bool) as int) AS nzs FROM diagnostics WHERE ts >= 1451606400000 AND ts < 1451952001000 ) WHERE ts >= 1451606400000 AND ts < 1451952001000 partition BY model interval(10m)) partition BY model) WHERE state_changed = 1 partition BY model )where model is null;" sql=f"select model,ctc from (SELECT model,count(state_changed) as ctc FROM (SELECT model,diff(broken_down) AS state_changed FROM (SELECT model,cast(cast(floor(2*(sum(nzs)/count(nzs))) as bool) as int) AS broken_down FROM (SELECT ts,model, cast(cast(status as bool) as int) AS nzs from {dbname}.diagnostics WHERE ts >= 1451606400000 AND ts < 1451952001000 ) WHERE ts >= 1451606400000 AND ts < 1451952001000 partition BY model interval(10m)) partition BY model) WHERE state_changed = 1 partition BY model )where model is null;"
# for i in range(2): # for i in range(2):
# tdSql.query("%s"%sql) # tdSql.query("%s"%sql)
@ -223,14 +223,14 @@ class TDTestCase:
#it's already supported: #it's already supported:
# last-loc # last-loc
tdSql.query("SELECT last_row(ts),latitude,longitude,name,driver FROM readings WHERE fleet='South' and name IS NOT NULL partition BY name,driver order by name ;") tdSql.query(f"select last_row(ts),latitude,longitude,name,driver from {dbname}.readings WHERE fleet='South' and name IS NOT NULL partition BY name,driver order by name ;")
#2. low-fuel #2. low-fuel
tdSql.query("SELECT last_row(ts),name,driver,fuel_state,driver FROM diagnostics WHERE fuel_state <= 0.1 AND fleet = 'South' and name IS NOT NULL GROUP BY name,driver order by name;") tdSql.query(f"select last_row(ts),name,driver,fuel_state,driver from {dbname}.diagnostics WHERE fuel_state <= 0.1 AND fleet = 'South' and name IS NOT NULL GROUP BY name,driver order by name;")
# 3. avg-vs-projected-fuel-consumption # 3. avg-vs-projected-fuel-consumption
tdSql.query("select avg(fuel_consumption) as avg_fuel_consumption,avg(nominal_fuel_consumption) as nominal_fuel_consumption from readings where velocity > 1 group by fleet") tdSql.query(f"select avg(fuel_consumption) as avg_fuel_consumption,avg(nominal_fuel_consumption) as nominal_fuel_consumption from {dbname}.readings where velocity > 1 group by fleet")
def run(self): def run(self):
tdLog.printNoPrefix("==========step1:create database and table,insert data ==============") tdLog.printNoPrefix("==========step1:create database and table,insert data ==============")

View File

@ -26,20 +26,21 @@ class TDTestCase:
def init(self, conn, logSql): def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__) tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor(), logSql) tdSql.init(conn.cursor(), False)
def run(self): def run(self):
dbname="db"
tdSql.prepare() tdSql.prepare()
tdSql.error("create table ttl_table1(ts timestamp, i int) ttl 1.1") tdSql.error(f"create table {dbname}.ttl_table1(ts timestamp, i int) ttl 1.1")
tdSql.error("create table ttl_table2(ts timestamp, i int) ttl 1e1") tdSql.error(f"create table {dbname}.ttl_table2(ts timestamp, i int) ttl 1e1")
tdSql.error("create table ttl_table3(ts timestamp, i int) ttl -1") tdSql.error(f"create table {dbname}.ttl_table3(ts timestamp, i int) ttl -1")
print("============== STEP 1 ===== test normal table") print("============== STEP 1 ===== test normal table")
tdSql.execute("create table normal_table1(ts timestamp, i int)") tdSql.execute(f"create table {dbname}.normal_table1(ts timestamp, i int)")
tdSql.execute("create table normal_table2(ts timestamp, i int) comment '' ttl 3") tdSql.execute(f"create table {dbname}.normal_table2(ts timestamp, i int) comment '' ttl 3")
tdSql.execute("create table normal_table3(ts timestamp, i int) ttl 2100000000020 comment 'hello'") tdSql.execute(f"create table {dbname}.normal_table3(ts timestamp, i int) ttl 2100000000020 comment 'hello'")
tdSql.query("select * from information_schema.ins_tables where table_name like 'normal_table1'") tdSql.query("select * from information_schema.ins_tables where table_name like 'normal_table1'")
tdSql.checkData(0, 0, 'normal_table1') tdSql.checkData(0, 0, 'normal_table1')
@ -58,32 +59,32 @@ class TDTestCase:
tdSql.checkData(0, 7, 2147483647) tdSql.checkData(0, 7, 2147483647)
tdSql.checkData(0, 8, 'hello') tdSql.checkData(0, 8, 'hello')
tdSql.execute("alter table normal_table1 comment 'nihao'") tdSql.execute(f"alter table {dbname}.normal_table1 comment 'nihao'")
tdSql.query("select * from information_schema.ins_tables where table_name like 'normal_table1'") tdSql.query("select * from information_schema.ins_tables where table_name like 'normal_table1'")
tdSql.checkData(0, 0, 'normal_table1') tdSql.checkData(0, 0, 'normal_table1')
tdSql.checkData(0, 8, 'nihao') tdSql.checkData(0, 8, 'nihao')
tdSql.execute("alter table normal_table1 comment ''") tdSql.execute(f"alter table {dbname}.normal_table1 comment ''")
tdSql.query("select * from information_schema.ins_tables where table_name like 'normal_table1'") tdSql.query("select * from information_schema.ins_tables where table_name like 'normal_table1'")
tdSql.checkData(0, 0, 'normal_table1') tdSql.checkData(0, 0, 'normal_table1')
tdSql.checkData(0, 8, '') tdSql.checkData(0, 8, '')
tdSql.execute("alter table normal_table2 comment 'fly'") tdSql.execute(f"alter table {dbname}.normal_table2 comment 'fly'")
tdSql.query("select * from information_schema.ins_tables where table_name like 'normal_table2'") tdSql.query("select * from information_schema.ins_tables where table_name like 'normal_table2'")
tdSql.checkData(0, 0, 'normal_table2') tdSql.checkData(0, 0, 'normal_table2')
tdSql.checkData(0, 8, 'fly') tdSql.checkData(0, 8, 'fly')
tdSql.execute("alter table normal_table3 comment 'fly'") tdSql.execute(f"alter table {dbname}.normal_table3 comment 'fly'")
tdSql.query("select * from information_schema.ins_tables where table_name like 'normal_table3'") tdSql.query("select * from information_schema.ins_tables where table_name like 'normal_table3'")
tdSql.checkData(0, 0, 'normal_table3') tdSql.checkData(0, 0, 'normal_table3')
tdSql.checkData(0, 8, 'fly') tdSql.checkData(0, 8, 'fly')
tdSql.execute("alter table normal_table1 ttl 1") tdSql.execute(f"alter table {dbname}.normal_table1 ttl 1")
tdSql.query("select * from information_schema.ins_tables where table_name like 'normal_table1'") tdSql.query("select * from information_schema.ins_tables where table_name like 'normal_table1'")
tdSql.checkData(0, 0, 'normal_table1') tdSql.checkData(0, 0, 'normal_table1')
tdSql.checkData(0, 7, 1) tdSql.checkData(0, 7, 1)
tdSql.execute("alter table normal_table3 ttl 0") tdSql.execute(f"alter table {dbname}.normal_table3 ttl 0")
tdSql.query("select * from information_schema.ins_tables where table_name like 'normal_table3'") tdSql.query("select * from information_schema.ins_tables where table_name like 'normal_table3'")
tdSql.checkData(0, 0, 'normal_table3') tdSql.checkData(0, 0, 'normal_table3')
tdSql.checkData(0, 7, 0) tdSql.checkData(0, 7, 0)
@ -91,9 +92,9 @@ class TDTestCase:
print("============== STEP 2 ===== test super table") print("============== STEP 2 ===== test super table")
tdSql.execute("create table super_table1(ts timestamp, i int) tags(t int)") tdSql.execute(f"create table {dbname}.super_table1(ts timestamp, i int) tags(t int)")
tdSql.execute("create table super_table2(ts timestamp, i int) tags(t int) comment ''") tdSql.execute(f"create table {dbname}.super_table2(ts timestamp, i int) tags(t int) comment ''")
tdSql.execute("create table super_table3(ts timestamp, i int) tags(t int) comment 'super'") tdSql.execute(f"create table {dbname}.super_table3(ts timestamp, i int) tags(t int) comment 'super'")
tdSql.query("select * from information_schema.ins_stables where stable_name like 'super_table1'") tdSql.query("select * from information_schema.ins_stables where stable_name like 'super_table1'")
tdSql.checkData(0, 0, 'super_table1') tdSql.checkData(0, 0, 'super_table1')
@ -110,32 +111,32 @@ class TDTestCase:
tdSql.checkData(0, 6, 'super') tdSql.checkData(0, 6, 'super')
tdSql.execute("alter table super_table1 comment 'nihao'") tdSql.execute(f"alter table {dbname}.super_table1 comment 'nihao'")
tdSql.query("select * from information_schema.ins_stables where stable_name like 'super_table1'") tdSql.query("select * from information_schema.ins_stables where stable_name like 'super_table1'")
tdSql.checkData(0, 0, 'super_table1') tdSql.checkData(0, 0, 'super_table1')
tdSql.checkData(0, 6, 'nihao') tdSql.checkData(0, 6, 'nihao')
tdSql.execute("alter table super_table1 comment ''") tdSql.execute(f"alter table {dbname}.super_table1 comment ''")
tdSql.query("select * from information_schema.ins_stables where stable_name like 'super_table1'") tdSql.query("select * from information_schema.ins_stables where stable_name like 'super_table1'")
tdSql.checkData(0, 0, 'super_table1') tdSql.checkData(0, 0, 'super_table1')
tdSql.checkData(0, 6, '') tdSql.checkData(0, 6, '')
tdSql.execute("alter table super_table2 comment 'fly'") tdSql.execute(f"alter table {dbname}.super_table2 comment 'fly'")
tdSql.query("select * from information_schema.ins_stables where stable_name like 'super_table2'") tdSql.query("select * from information_schema.ins_stables where stable_name like 'super_table2'")
tdSql.checkData(0, 0, 'super_table2') tdSql.checkData(0, 0, 'super_table2')
tdSql.checkData(0, 6, 'fly') tdSql.checkData(0, 6, 'fly')
tdSql.execute("alter table super_table3 comment 'tdengine'") tdSql.execute(f"alter table {dbname}.super_table3 comment 'tdengine'")
tdSql.query("select * from information_schema.ins_stables where stable_name like 'super_table3'") tdSql.query("select * from information_schema.ins_stables where stable_name like 'super_table3'")
tdSql.checkData(0, 0, 'super_table3') tdSql.checkData(0, 0, 'super_table3')
tdSql.checkData(0, 6, 'tdengine') tdSql.checkData(0, 6, 'tdengine')
print("============== STEP 3 ===== test child table") print("============== STEP 3 ===== test child table")
tdSql.execute("create table child_table1 using super_table1 tags(1) ttl 10") tdSql.execute(f"create table {dbname}.child_table1 using {dbname}.super_table1 tags(1) ttl 10")
tdSql.execute("create table child_table2 using super_table1 tags(1) comment ''") tdSql.execute(f"create table {dbname}.child_table2 using {dbname}.super_table1 tags(1) comment ''")
tdSql.execute("create table child_table3 using super_table1 tags(1) comment 'child'") tdSql.execute(f"create table {dbname}.child_table3 using {dbname}.super_table1 tags(1) comment 'child'")
tdSql.execute("insert into child_table4 using super_table1 tags(1) values(now, 1)") tdSql.execute(f"insert into {dbname}.child_table4 using {dbname}.super_table1 tags(1) values(now, 1)")
tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table1'") tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table1'")
@ -160,38 +161,38 @@ class TDTestCase:
tdSql.checkData(0, 8, None) tdSql.checkData(0, 8, None)
tdSql.execute("alter table child_table1 comment 'nihao'") tdSql.execute(f"alter table {dbname}.child_table1 comment 'nihao'")
tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table1'") tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table1'")
tdSql.checkData(0, 0, 'child_table1') tdSql.checkData(0, 0, 'child_table1')
tdSql.checkData(0, 8, 'nihao') tdSql.checkData(0, 8, 'nihao')
tdSql.execute("alter table child_table1 comment ''") tdSql.execute(f"alter table {dbname}.child_table1 comment ''")
tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table1'") tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table1'")
tdSql.checkData(0, 0, 'child_table1') tdSql.checkData(0, 0, 'child_table1')
tdSql.checkData(0, 8, '') tdSql.checkData(0, 8, '')
tdSql.execute("alter table child_table2 comment 'fly'") tdSql.execute(f"alter table {dbname}.child_table2 comment 'fly'")
tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table2'") tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table2'")
tdSql.checkData(0, 0, 'child_table2') tdSql.checkData(0, 0, 'child_table2')
tdSql.checkData(0, 8, 'fly') tdSql.checkData(0, 8, 'fly')
tdSql.execute("alter table child_table3 comment 'tdengine'") tdSql.execute(f"alter table {dbname}.child_table3 comment 'tdengine'")
tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table3'") tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table3'")
tdSql.checkData(0, 0, 'child_table3') tdSql.checkData(0, 0, 'child_table3')
tdSql.checkData(0, 8, 'tdengine') tdSql.checkData(0, 8, 'tdengine')
tdSql.execute("alter table child_table4 comment 'tdengine'") tdSql.execute(f"alter table {dbname}.child_table4 comment 'tdengine'")
tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table4'") tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table4'")
tdSql.checkData(0, 0, 'child_table4') tdSql.checkData(0, 0, 'child_table4')
tdSql.checkData(0, 8, 'tdengine') tdSql.checkData(0, 8, 'tdengine')
tdSql.execute("alter table child_table4 ttl 9") tdSql.execute(f"alter table {dbname}.child_table4 ttl 9")
tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table4'") tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table4'")
tdSql.checkData(0, 0, 'child_table4') tdSql.checkData(0, 0, 'child_table4')
tdSql.checkData(0, 7, 9) tdSql.checkData(0, 7, 9)
tdSql.execute("alter table child_table3 ttl 9") tdSql.execute(f"alter table {dbname}.child_table3 ttl 9")
tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table3'") tdSql.query("select * from information_schema.ins_tables where table_name like 'child_table3'")
tdSql.checkData(0, 0, 'child_table3') tdSql.checkData(0, 0, 'child_table3')
tdSql.checkData(0, 7, 9) tdSql.checkData(0, 7, 9)
@ -203,4 +204,3 @@ class TDTestCase:
tdCases.addWindows(__file__, TDTestCase()) tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase()) tdCases.addLinux(__file__, TDTestCase())

View File

@ -7,10 +7,7 @@ import platform
import math import math
class TDTestCase: class TDTestCase:
updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , updatecfgDict = {"maxTablesPerVnode":2 ,"minTablesPerVnode":2,"tableIncStepPerVnode":2 }
"jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143,
"wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143,
"maxTablesPerVnode":2 ,"minTablesPerVnode":2,"tableIncStepPerVnode":2 }
def init(self, conn, logSql): def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__) tdLog.debug("start to execute %s" % __file__)
@ -21,46 +18,45 @@ class TDTestCase:
self.row_nums = 100 self.row_nums = 100
self.time_step = 1000 self.time_step = 1000
def prepare_datas_of_distribute(self): def prepare_datas_of_distribute(self, dbname="testdb"):
# prepate datas for 20 tables distributed at different vgroups # prepate datas for 20 tables distributed at different vgroups
tdSql.execute("create database if not exists testdb keep 3650 duration 1000 vgroups 5") tdSql.execute(f"create database if not exists {dbname} keep 3650 duration 1000 vgroups 5")
tdSql.execute(" use testdb ")
tdSql.execute( tdSql.execute(
'''create table stb1 f'''create table {dbname}.stb1
(ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp)
tags (t0 timestamp, t1 int, t2 bigint, t3 smallint, t4 tinyint, t5 float, t6 double, t7 bool, t8 binary(16),t9 nchar(32)) tags (t0 timestamp, t1 int, t2 bigint, t3 smallint, t4 tinyint, t5 float, t6 double, t7 bool, t8 binary(16),t9 nchar(32))
''' '''
) )
for i in range(self.tb_nums): for i in range(self.tb_nums):
tdSql.execute(f'create table ct{i+1} using stb1 tags ( now(), {1*i}, {11111*i}, {111*i}, {1*i}, {1.11*i}, {11.11*i}, {i%2}, "binary{i}", "nchar{i}" )') tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( now(), {1*i}, {11111*i}, {111*i}, {1*i}, {1.11*i}, {11.11*i}, {i%2}, "binary{i}", "nchar{i}" )')
ts = self.ts ts = self.ts
for j in range(self.row_nums): for j in range(self.row_nums):
ts+=j*self.time_step ts+=j*self.time_step
tdSql.execute( tdSql.execute(
f"insert into ct{i+1} values({ts}, 1, 11111, 111, 1, 1.11, 11.11, 2, 'binary{j}', 'nchar{j}', now()+{1*j}a )" f"insert into {dbname}.ct{i+1} values({ts}, 1, 11111, 111, 1, 1.11, 11.11, 2, 'binary{j}', 'nchar{j}', now()+{1*j}a )"
) )
tdSql.execute("insert into ct1 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute(f"insert into {dbname}.ct1 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ")
tdSql.execute("insert into ct1 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute(f"insert into {dbname}.ct1 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ")
tdSql.execute("insert into ct1 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute(f"insert into {dbname}.ct1 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ")
tdLog.info(" prepare data for distributed_aggregate done! ") tdLog.info(" prepare data for distributed_aggregate done! ")
def twa_support_types(self): def twa_support_types(self, dbname="testdb"):
tdSql.query("desc stb1 ") tdSql.query(f"desc {dbname}.stb1 ")
schema_list = tdSql.queryResult schema_list = tdSql.queryResult
for col_type in schema_list: for col_type in schema_list:
if col_type[1] in ["TINYINT" ,"SMALLINT","BIGINT" ,"INT","FLOAT","DOUBLE"]: if col_type[1] in ["TINYINT" ,"SMALLINT","BIGINT" ,"INT","FLOAT","DOUBLE"]:
tdSql.query(f" select twa({col_type[0]}) from stb1 partition by tbname ") tdSql.query(f"select twa({col_type[0]}) from {dbname}.stb1 partition by tbname ")
else: else:
tdSql.error(f" select twa({col_type[0]}) from stb1 partition by tbname ") tdSql.error(f"select twa({col_type[0]}) from {dbname}.stb1 partition by tbname ")
def check_distribute_datas(self): def check_distribute_datas(self, dbname="testdb"):
# get vgroup_ids of all # get vgroup_ids of all
tdSql.query("show vgroups ") tdSql.query(f"show {dbname}.vgroups ")
vgroups = tdSql.queryResult vgroups = tdSql.queryResult
vnode_tables={} vnode_tables={}
@ -69,7 +65,7 @@ class TDTestCase:
vnode_tables[vgroup_id[0]]=[] vnode_tables[vgroup_id[0]]=[]
# check sub_table of per vnode ,make sure sub_table has been distributed # check sub_table of per vnode ,make sure sub_table has been distributed
tdSql.query(f"select * from information_schema.ins_tables where db_name = 'testdb' and table_name like 'ct%'") tdSql.query(f"select * from information_schema.ins_tables where db_name = '{dbname}' and table_name like 'ct%'")
table_names = tdSql.queryResult table_names = tdSql.queryResult
tablenames = [] tablenames = []
for table_name in table_names: for table_name in table_names:
@ -83,28 +79,28 @@ class TDTestCase:
if count < 2: if count < 2:
tdLog.exit(" the datas of all not satisfy sub_table has been distributed ") tdLog.exit(" the datas of all not satisfy sub_table has been distributed ")
def distribute_twa_query(self): def distribute_twa_query(self, dbname="testdb"):
# basic filter # basic filter
tdSql.query(" select twa(c1) from ct1 ") tdSql.query(f"select twa(c1) from {dbname}.ct1 ")
tdSql.checkData(0,0,1.000000000) tdSql.checkData(0,0,1.000000000)
tdSql.query(" select twa(c1) from stb1 partition by tbname ") tdSql.query(f"select twa(c1) from {dbname}.stb1 partition by tbname ")
tdSql.checkRows(self.tb_nums) tdSql.checkRows(self.tb_nums)
tdSql.checkData(0,0,1.000000000) tdSql.checkData(0,0,1.000000000)
tdSql.query(" select twa(c2) from stb1 group by tbname ") tdSql.query(f"select twa(c2) from {dbname}.stb1 group by tbname ")
tdSql.checkRows(self.tb_nums) tdSql.checkRows(self.tb_nums)
tdSql.checkData(0,0,11111.000000000) tdSql.checkData(0,0,11111.000000000)
tdSql.query("select twa(c1+c2) from stb1 partition by tbname ") tdSql.query(f"select twa(c1+c2) from {dbname}.stb1 partition by tbname ")
tdSql.checkData(0,0,11112.000000000) tdSql.checkData(0,0,11112.000000000)
tdSql.query("select twa(c1) from stb1 partition by t1") tdSql.query(f"select twa(c1) from {dbname}.stb1 partition by t1")
tdSql.checkRows(self.tb_nums) tdSql.checkRows(self.tb_nums)
tdSql.checkData(0,0,1.000000000) tdSql.checkData(0,0,1.000000000)
# union all # union all
tdSql.query(" select twa(c1) from stb1 partition by tbname union all select twa(c1) from stb1 partition by tbname ") tdSql.query(f"select twa(c1) from {dbname}.stb1 partition by tbname union all select twa(c1) from {dbname}.stb1 partition by tbname ")
tdSql.checkRows(40) tdSql.checkRows(40)
tdSql.checkData(0,0,1.000000000) tdSql.checkData(0,0,1.000000000)
@ -112,26 +108,23 @@ class TDTestCase:
tdSql.execute(" create database if not exists db ") tdSql.execute(" create database if not exists db ")
tdSql.execute(" use db ") tdSql.execute(" use db ")
tdSql.execute(" create stable st (ts timestamp , c1 int ,c2 float) tags(t1 int) ") tdSql.execute(" create stable db.st (ts timestamp , c1 int ,c2 float) tags(t1 int) ")
tdSql.execute(" create table tb1 using st tags(1) ") tdSql.execute(" create table db.tb1 using db.st tags(1) ")
tdSql.execute(" create table tb2 using st tags(2) ") tdSql.execute(" create table db.tb2 using db.st tags(2) ")
for i in range(10): for i in range(10):
ts = i*10 + self.ts ts = i*10 + self.ts
tdSql.execute(f" insert into tb1 values({ts},{i},{i}.0)") tdSql.execute(f" insert into db.tb1 values({ts},{i},{i}.0)")
tdSql.execute(f" insert into tb2 values({ts},{i},{i}.0)") tdSql.execute(f" insert into db.tb2 values({ts},{i},{i}.0)")
tdSql.query(" select twa(tb1.c1), twa(tb2.c2) from tb1, tb2 where tb1.ts=tb2.ts ") tdSql.query(f"select twa(tb1.c1), twa(tb2.c2) from db.tb1 tb1, db.tb2 tb2 where tb1.ts=tb2.ts ")
tdSql.checkRows(1) tdSql.checkRows(1)
tdSql.checkData(0,0,4.500000000) tdSql.checkData(0,0,4.500000000)
tdSql.checkData(0,1,4.500000000) tdSql.checkData(0,1,4.500000000)
# group by
tdSql.execute(" use testdb ")
# mixup with other functions # mixup with other functions
tdSql.query(" select twa(c1),twa(c2),max(c1),elapsed(ts) from stb1 ") tdSql.query(f"select twa(c1),twa(c2),max(c1),elapsed(ts) from {dbname}.stb1 ")
tdSql.checkData(0,0,1.000000000) tdSql.checkData(0,0,1.000000000)
tdSql.checkData(0,1,11111.000000000) tdSql.checkData(0,1,11111.000000000)
tdSql.checkData(0,2,1) tdSql.checkData(0,2,1)

View File

@ -58,10 +58,10 @@ class TDTestCase:
def __join_condition(self, tb_list, filter=PRIMARY_COL, INNER=False): def __join_condition(self, tb_list, filter=PRIMARY_COL, INNER=False):
table_reference = tb_list[0] table_reference = tb_list[0]
join_condition = table_reference join_condition = f'{table_reference} {table_reference.split(".")[-1]}'
join = "inner join" if INNER else "join" join = "inner join" if INNER else "join"
for i in range(len(tb_list[1:])): for i in range(len(tb_list[1:])):
join_condition += f" {join} {tb_list[i+1]} on {table_reference}.{filter}={tb_list[i+1]}.{filter}" join_condition += f" {join} {tb_list[i+1]} {tb_list[i+1].split('.')[-1]} on {table_reference.split('.')[-1]}.{filter}={tb_list[i+1].split('.')[-1]}.{filter}"
return join_condition return join_condition
@ -76,7 +76,6 @@ class TDTestCase:
elif query_conditon.startswith("min"): elif query_conditon.startswith("min"):
query_conditon = query_conditon[4:-1] query_conditon = query_conditon[4:-1]
if query_conditon: if query_conditon:
return f" where {query_conditon} is not null" return f" where {query_conditon} is not null"
if col in NUM_COL: if col in NUM_COL:
@ -108,10 +107,10 @@ class TDTestCase:
return f"select {select_clause} from {from_clause} {where_condition} {group_condition}" return f"select {select_clause} from {from_clause} {where_condition} {group_condition}"
@property @property
def __join_tblist(self): def __join_tblist(self, dbname="db"):
return [ return [
["ct1", "t1"], [f"{dbname}.ct1", f"{dbname}.t1"],
["ct4", "t1"], [f"{dbname}.ct4", f"{dbname}.t1"],
# ["ct1", "ct2", "ct4"], # ["ct1", "ct2", "ct4"],
# ["ct1", "ct2", "t1"], # ["ct1", "ct2", "t1"],
# ["ct1", "ct4", "t1"], # ["ct1", "ct4", "t1"],
@ -120,10 +119,10 @@ class TDTestCase:
] ]
@property @property
def __tb_liast(self): def __tb_list(self, dbname="db"):
return [ return [
"ct1", f"{dbname}.ct1",
"ct4", f"{dbname}.ct4",
] ]
def sql_list(self): def sql_list(self):
@ -131,7 +130,8 @@ class TDTestCase:
__join_tblist = self.__join_tblist __join_tblist = self.__join_tblist
for join_tblist in __join_tblist: for join_tblist in __join_tblist:
for join_tb in join_tblist: for join_tb in join_tblist:
select_claus_list = self.__query_condition(join_tb) join_tb_name = join_tb.split(".")[-1]
select_claus_list = self.__query_condition(join_tb_name)
for select_claus in select_claus_list: for select_claus in select_claus_list:
group_claus = self.__group_condition( col=select_claus) group_claus = self.__group_condition( col=select_claus)
where_claus = self.__where_condition(query_conditon=select_claus) where_claus = self.__where_condition(query_conditon=select_claus)
@ -141,9 +141,10 @@ class TDTestCase:
self.__single_sql(select_claus, self.__join_condition(join_tblist, INNER=True), where_claus, having_claus), self.__single_sql(select_claus, self.__join_condition(join_tblist, INNER=True), where_claus, having_claus),
) )
) )
__no_join_tblist = self.__tb_liast __no_join_tblist = self.__tb_list
for tb in __no_join_tblist: for tb in __no_join_tblist:
select_claus_list = self.__query_condition(tb) tb_name = join_tb.split(".")[-1]
select_claus_list = self.__query_condition(tb_name)
for select_claus in select_claus_list: for select_claus in select_claus_list:
group_claus = self.__group_condition(col=select_claus) group_claus = self.__group_condition(col=select_claus)
where_claus = self.__where_condition(query_conditon=select_claus) where_claus = self.__where_condition(query_conditon=select_claus)
@ -230,31 +231,29 @@ class TDTestCase:
else: else:
tdSql.error(f"{sqls[i]} union {sqls[j+i]}") tdSql.error(f"{sqls[i]} union {sqls[j+i]}")
def __test_error(self): def __test_error(self, dbname="db"):
tdSql.error( "show tables union show tables" ) tdSql.error( f"show {dbname}.tables union show {dbname}.tables" )
tdSql.error( "create table errtb1 union all create table errtb2" ) tdSql.error( f"create table {dbname}.errtb1 union all create table {dbname}.errtb2" )
tdSql.error( "drop table ct1 union all drop table ct3" ) tdSql.error( f"drop table {dbname}.ct1 union all drop table {dbname}.ct3" )
tdSql.error( "select c1 from ct1 union all drop table ct3" ) tdSql.error( f"select c1 from {dbname}.ct1 union all drop table {dbname}.ct3" )
tdSql.error( "select c1 from ct1 union all '' " ) tdSql.error( f"select c1 from {dbname}.ct1 union all '' " )
tdSql.error( " '' union all select c1 from ct1 " ) tdSql.error( f" '' union all select c1 from{dbname}. ct1 " )
# tdSql.error( "select c1 from ct1 union select c1 from ct2 union select c1 from ct4 ")
def all_test(self): def all_test(self):
self.__test_error() self.__test_error()
self.union_check() self.union_check()
def __create_tb(self, dbname="db"):
def __create_tb(self):
tdLog.printNoPrefix("==========step1:create table") tdLog.printNoPrefix("==========step1:create table")
create_stb_sql = f'''create table stb1( create_stb_sql = f'''create table {dbname}.stb1(
ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint,
{FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool,
{BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp
) tags (t1 int) ) tags (tag1 int)
''' '''
create_ntb_sql = f'''create table t1( create_ntb_sql = f'''create table {dbname}.t1(
ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint,
{FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool,
{BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp
@ -264,30 +263,29 @@ class TDTestCase:
tdSql.execute(create_ntb_sql) tdSql.execute(create_ntb_sql)
for i in range(4): for i in range(4):
tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( {i+1} )')
{ i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}
def __insert_data(self, rows): def __insert_data(self, rows, dbname="db"):
now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000)
for i in range(rows): for i in range(rows):
tdSql.execute( tdSql.execute(
f"insert into ct1 values ( { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" f"insert into {dbname}.ct1 values ( { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )"
) )
tdSql.execute( tdSql.execute(
f"insert into ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" f"insert into {dbname}.ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )"
) )
tdSql.execute( tdSql.execute(
f"insert into ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" f"insert into {dbname}.ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )"
) )
tdSql.execute( tdSql.execute(
f'''insert into ct1 values f'''insert into {dbname}.ct1 values
( { now_time - rows * 5 }, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar_测试_0', { now_time + 8 } ) ( { now_time - rows * 5 }, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar_测试_0', { now_time + 8 } )
( { now_time + 10000 }, { rows }, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar_测试_9', { now_time + 9 } ) ( { now_time + 10000 }, { rows }, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar_测试_9', { now_time + 9 } )
''' '''
) )
tdSql.execute( tdSql.execute(
f'''insert into ct4 values f'''insert into {dbname}.ct4 values
( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
( { now_time - rows * 3888000000 + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 3888000000 + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
@ -303,7 +301,7 @@ class TDTestCase:
) )
tdSql.execute( tdSql.execute(
f'''insert into ct2 values f'''insert into {dbname}.ct2 values
( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
( { now_time - rows * 3888000000 + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 3888000000 + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
@ -319,13 +317,13 @@ class TDTestCase:
) )
for i in range(rows): for i in range(rows):
insert_data = f'''insert into t1 values insert_data = f'''insert into {dbname}.t1 values
( { now_time - i * 3600000 }, {i}, {i * 11111}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}, ( { now_time - i * 3600000 }, {i}, {i * 11111}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2},
"binary_{i}", "nchar_测试_{i}", { now_time - 1000 * i } ) "binary_{i}", "nchar_测试_{i}", { now_time - 1000 * i } )
''' '''
tdSql.execute(insert_data) tdSql.execute(insert_data)
tdSql.execute( tdSql.execute(
f'''insert into t1 values f'''insert into {dbname}.t1 values
( { now_time + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
( { now_time - (( rows // 2 ) * 60 + 30) * 60000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - (( rows // 2 ) * 60 + 30) * 60000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
( { now_time - rows * 3600000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 3600000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
@ -341,7 +339,6 @@ class TDTestCase:
''' '''
) )
def run(self): def run(self):
tdSql.prepare() tdSql.prepare()
@ -355,8 +352,7 @@ class TDTestCase:
tdLog.printNoPrefix("==========step3:all check") tdLog.printNoPrefix("==========step3:all check")
self.all_test() self.all_test()
tdDnodes.stop(1) tdSql.execute("flush database db")
tdDnodes.start(1)
tdSql.execute("use db") tdSql.execute("use db")

View File

@ -11,49 +11,46 @@ from util.sql import *
from util.cases import * from util.cases import *
class TDTestCase: class TDTestCase:
updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 ,
"jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143,
"wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143}
def init(self, conn, logSql): def init(self, conn, logSql):
tdLog.debug(f"start to excute {__file__}") tdLog.debug(f"start to excute {__file__}")
tdSql.init(conn.cursor()) tdSql.init(conn.cursor())
def prepare_datas(self): def prepare_datas(self, dbname="db"):
tdSql.execute( tdSql.execute(
'''create table stb1 f'''create table {dbname}.stb1
(ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp)
tags (t1 int) tags (t1 int)
''' '''
) )
tdSql.execute( tdSql.execute(
''' f'''
create table t1 create table {dbname}.t1
(ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp)
''' '''
) )
for i in range(4): for i in range(4):
tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( {i+1} )')
for i in range(9): for i in range(9):
tdSql.execute( tdSql.execute(
f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" f"insert into {dbname}.ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )"
) )
tdSql.execute( tdSql.execute(
f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" f"insert into {dbname}.ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )"
) )
tdSql.execute("insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") tdSql.execute(f"insert into {dbname}.ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )")
tdSql.execute("insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") tdSql.execute(f"insert into {dbname}.ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )")
tdSql.execute("insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") tdSql.execute(f"insert into {dbname}.ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )")
tdSql.execute("insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") tdSql.execute(f"insert into {dbname}.ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )")
tdSql.execute("insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute(f"insert into {dbname}.ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ")
tdSql.execute("insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute(f"insert into {dbname}.ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ")
tdSql.execute("insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute(f"insert into {dbname}.ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ")
tdSql.execute( tdSql.execute(
f'''insert into t1 values f'''insert into {dbname}.t1 values
( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a )
( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a )
@ -69,84 +66,84 @@ class TDTestCase:
''' '''
) )
def test_errors(self): def test_errors(self, dbname="db"):
error_sql_lists = [ error_sql_lists = [
"select unique from t1", f"select unique from {dbname}.t1",
"select unique(123--123)==1 from t1", f"select unique(123--123)==1 from {dbname}.t1",
"select unique(123,123) from t1", f"select unique(123,123) from {dbname}.t1",
"select unique(c1,ts) from t1", f"select unique(c1,ts) from {dbname}.t1",
"select unique(c1,c1,ts) from t1", f"select unique(c1,c1,ts) from {dbname}.t1",
"select unique(c1) as 'd1' from t1", f"select unique(c1) as 'd1' from {dbname}.t1",
"select unique(c1 ,c2 ) from t1", f"select unique(c1 ,c2 ) from {dbname}.t1",
"select unique(c1 ,NULL) from t1", f"select unique(c1 ,NULL) from {dbname}.t1",
"select unique(,) from t1;", f"select unique(,) from {dbname}.t1;",
"select unique(floor(c1) ab from t1)", f"select unique(floor(c1) ab from {dbname}.t1)",
"select unique(c1) as int from t1", f"select unique(c1) as int from {dbname}.t1",
"select unique('c1') from t1", f"select unique('c1') from {dbname}.t1",
"select unique(NULL) from t1", f"select unique(NULL) from {dbname}.t1",
"select unique('') from t1", f"select unique('') from {dbname}.t1",
"select unique(c%) from t1", f"select unique(c%) from {dbname}.t1",
"select unique(t1) from t1", f"select unique(t1) from {dbname}.t1",
"select unique(True) from t1", f"select unique(True) from {dbname}.t1",
"select unique(c1) , count(c1) from t1", f"select unique(c1) , count(c1) from {dbname}.t1",
"select unique(c1) , avg(c1) from t1", f"select unique(c1) , avg(c1) from {dbname}.t1",
"select unique(c1) , min(c1) from t1", f"select unique(c1) , min(c1) from {dbname}.t1",
"select unique(c1) , spread(c1) from t1", f"select unique(c1) , spread(c1) from {dbname}.t1",
"select unique(c1) , diff(c1) from t1", f"select unique(c1) , diff(c1) from {dbname}.t1",
#"select unique(c1) , abs(c1) from t1", # support #f"select unique(c1) , abs(c1) from {dbname}.t1", # support
#"select unique(c1) , c1 from t1", #f"select unique(c1) , c1 from {dbname}.t1",
"select unique from stb1 partition by tbname", f"select unique from {dbname}.stb1 partition by tbname",
"select unique(123--123)==1 from stb1 partition by tbname", f"select unique(123--123)==1 from {dbname}.stb1 partition by tbname",
"select unique(123) from stb1 partition by tbname", f"select unique(123) from {dbname}.stb1 partition by tbname",
"select unique(c1,ts) from stb1 partition by tbname", f"select unique(c1,ts) from {dbname}.stb1 partition by tbname",
"select unique(c1,c1,ts) from stb1 partition by tbname", f"select unique(c1,c1,ts) from {dbname}.stb1 partition by tbname",
"select unique(c1) as 'd1' from stb1 partition by tbname", f"select unique(c1) as 'd1' from {dbname}.stb1 partition by tbname",
"select unique(c1 ,c2 ) from stb1 partition by tbname", f"select unique(c1 ,c2 ) from {dbname}.stb1 partition by tbname",
"select unique(c1 ,NULL) from stb1 partition by tbname", f"select unique(c1 ,NULL) from {dbname}.stb1 partition by tbname",
"select unique(,) from stb1 partition by tbname;", f"select unique(,) from {dbname}.stb1 partition by tbname;",
#"select unique(floor(c1) ab from stb1 partition by tbname)", # support #f"select unique(floor(c1) ab from {dbname}.stb1 partition by tbname)", # support
#"select unique(c1) as int from stb1 partition by tbname", #f"select unique(c1) as int from {dbname}.stb1 partition by tbname",
"select unique('c1') from stb1 partition by tbname", f"select unique('c1') from {dbname}.stb1 partition by tbname",
"select unique(NULL) from stb1 partition by tbname", f"select unique(NULL) from {dbname}.stb1 partition by tbname",
"select unique('') from stb1 partition by tbname", f"select unique('') from {dbname}.stb1 partition by tbname",
"select unique(c%) from stb1 partition by tbname", f"select unique(c%) from {dbname}.stb1 partition by tbname",
#"select unique(t1) from stb1 partition by tbname", # support #f"select unique(t1) from {dbname}.stb1 partition by tbname", # support
"select unique(True) from stb1 partition by tbname", f"select unique(True) from {dbname}.stb1 partition by tbname",
"select unique(c1) , count(c1) from stb1 partition by tbname", f"select unique(c1) , count(c1) from {dbname}.stb1 partition by tbname",
"select unique(c1) , avg(c1) from stb1 partition by tbname", f"select unique(c1) , avg(c1) from {dbname}.stb1 partition by tbname",
"select unique(c1) , min(c1) from stb1 partition by tbname", f"select unique(c1) , min(c1) from {dbname}.stb1 partition by tbname",
"select unique(c1) , spread(c1) from stb1 partition by tbname", f"select unique(c1) , spread(c1) from {dbname}.stb1 partition by tbname",
"select unique(c1) , diff(c1) from stb1 partition by tbname", f"select unique(c1) , diff(c1) from {dbname}.stb1 partition by tbname",
#"select unique(c1) , abs(c1) from stb1 partition by tbname", # support #f"select unique(c1) , abs(c1) from {dbname}.stb1 partition by tbname", # support
#"select unique(c1) , c1 from stb1 partition by tbname" # support #f"select unique(c1) , c1 from {dbname}.stb1 partition by tbname" # support
] ]
for error_sql in error_sql_lists: for error_sql in error_sql_lists:
tdSql.error(error_sql) tdSql.error(error_sql)
pass pass
def support_types(self): def support_types(self, dbname="db"):
other_no_value_types = [ other_no_value_types = [
"select unique(ts) from t1" , f"select unique(ts) from {dbname}.t1" ,
"select unique(c7) from t1", f"select unique(c7) from {dbname}.t1",
"select unique(c8) from t1", f"select unique(c8) from {dbname}.t1",
"select unique(c9) from t1", f"select unique(c9) from {dbname}.t1",
"select unique(ts) from ct1" , f"select unique(ts) from {dbname}.ct1" ,
"select unique(c7) from ct1", f"select unique(c7) from {dbname}.ct1",
"select unique(c8) from ct1", f"select unique(c8) from {dbname}.ct1",
"select unique(c9) from ct1", f"select unique(c9) from {dbname}.ct1",
"select unique(ts) from ct3" , f"select unique(ts) from {dbname}.ct3" ,
"select unique(c7) from ct3", f"select unique(c7) from {dbname}.ct3",
"select unique(c8) from ct3", f"select unique(c8) from {dbname}.ct3",
"select unique(c9) from ct3", f"select unique(c9) from {dbname}.ct3",
"select unique(ts) from ct4" , f"select unique(ts) from {dbname}.ct4" ,
"select unique(c7) from ct4", f"select unique(c7) from {dbname}.ct4",
"select unique(c8) from ct4", f"select unique(c8) from {dbname}.ct4",
"select unique(c9) from ct4", f"select unique(c9) from {dbname}.ct4",
"select unique(ts) from stb1 partition by tbname" , f"select unique(ts) from {dbname}.stb1 partition by tbname" ,
"select unique(c7) from stb1 partition by tbname", f"select unique(c7) from {dbname}.stb1 partition by tbname",
"select unique(c8) from stb1 partition by tbname", f"select unique(c8) from {dbname}.stb1 partition by tbname",
"select unique(c9) from stb1 partition by tbname" f"select unique(c9) from {dbname}.stb1 partition by tbname"
] ]
for type_sql in other_no_value_types: for type_sql in other_no_value_types:
@ -154,43 +151,43 @@ class TDTestCase:
tdLog.info("support type ok , sql is : %s"%type_sql) tdLog.info("support type ok , sql is : %s"%type_sql)
type_sql_lists = [ type_sql_lists = [
"select unique(c1) from t1", f"select unique(c1) from {dbname}.t1",
"select unique(c2) from t1", f"select unique(c2) from {dbname}.t1",
"select unique(c3) from t1", f"select unique(c3) from {dbname}.t1",
"select unique(c4) from t1", f"select unique(c4) from {dbname}.t1",
"select unique(c5) from t1", f"select unique(c5) from {dbname}.t1",
"select unique(c6) from t1", f"select unique(c6) from {dbname}.t1",
"select unique(c1) from ct1", f"select unique(c1) from {dbname}.ct1",
"select unique(c2) from ct1", f"select unique(c2) from {dbname}.ct1",
"select unique(c3) from ct1", f"select unique(c3) from {dbname}.ct1",
"select unique(c4) from ct1", f"select unique(c4) from {dbname}.ct1",
"select unique(c5) from ct1", f"select unique(c5) from {dbname}.ct1",
"select unique(c6) from ct1", f"select unique(c6) from {dbname}.ct1",
"select unique(c1) from ct3", f"select unique(c1) from {dbname}.ct3",
"select unique(c2) from ct3", f"select unique(c2) from {dbname}.ct3",
"select unique(c3) from ct3", f"select unique(c3) from {dbname}.ct3",
"select unique(c4) from ct3", f"select unique(c4) from {dbname}.ct3",
"select unique(c5) from ct3", f"select unique(c5) from {dbname}.ct3",
"select unique(c6) from ct3", f"select unique(c6) from {dbname}.ct3",
"select unique(c1) from stb1 partition by tbname", f"select unique(c1) from {dbname}.stb1 partition by tbname",
"select unique(c2) from stb1 partition by tbname", f"select unique(c2) from {dbname}.stb1 partition by tbname",
"select unique(c3) from stb1 partition by tbname", f"select unique(c3) from {dbname}.stb1 partition by tbname",
"select unique(c4) from stb1 partition by tbname", f"select unique(c4) from {dbname}.stb1 partition by tbname",
"select unique(c5) from stb1 partition by tbname", f"select unique(c5) from {dbname}.stb1 partition by tbname",
"select unique(c6) from stb1 partition by tbname", f"select unique(c6) from {dbname}.stb1 partition by tbname",
"select unique(c6) as alisb from stb1 partition by tbname", f"select unique(c6) as alisb from {dbname}.stb1 partition by tbname",
"select unique(c6) alisb from stb1 partition by tbname", f"select unique(c6) alisb from {dbname}.stb1 partition by tbname",
] ]
for type_sql in type_sql_lists: for type_sql in type_sql_lists:
tdSql.query(type_sql) tdSql.query(type_sql)
def check_unique_table(self , unique_sql): def check_unique_table(self , unique_sql):
# unique_sql = "select unique(c1) from ct1" # unique_sql = f"select unique(c1) from {dbname}.ct1"
origin_sql = unique_sql.replace("unique(","").replace(")","") origin_sql = unique_sql.replace("unique(","").replace(")","")
tdSql.query(unique_sql) tdSql.query(unique_sql)
unique_result = tdSql.queryResult unique_result = tdSql.queryResult
@ -219,83 +216,83 @@ class TDTestCase:
else: else:
tdLog.exit(" unique query check fail , unique sql is: %s " %unique_sql) tdLog.exit(" unique query check fail , unique sql is: %s " %unique_sql)
def basic_unique_function(self): def basic_unique_function(self, dbname="db"):
# basic query # basic query
tdSql.query("select c1 from ct3") tdSql.query(f"select c1 from {dbname}.ct3")
tdSql.checkRows(0) tdSql.checkRows(0)
tdSql.query("select c1 from t1") tdSql.query(f"select c1 from {dbname}.t1")
tdSql.checkRows(12) tdSql.checkRows(12)
tdSql.query("select c1 from stb1") tdSql.query(f"select c1 from {dbname}.stb1")
tdSql.checkRows(25) tdSql.checkRows(25)
# used for empty table , ct3 is empty # used for empty table , ct3 is empty
tdSql.query("select unique(c1) from ct3") tdSql.query(f"select unique(c1) from {dbname}.ct3")
tdSql.checkRows(0) tdSql.checkRows(0)
tdSql.query("select unique(c2) from ct3") tdSql.query(f"select unique(c2) from {dbname}.ct3")
tdSql.checkRows(0) tdSql.checkRows(0)
tdSql.query("select unique(c3) from ct3") tdSql.query(f"select unique(c3) from {dbname}.ct3")
tdSql.checkRows(0) tdSql.checkRows(0)
tdSql.query("select unique(c4) from ct3") tdSql.query(f"select unique(c4) from {dbname}.ct3")
tdSql.checkRows(0) tdSql.checkRows(0)
tdSql.query("select unique(c5) from ct3") tdSql.query(f"select unique(c5) from {dbname}.ct3")
tdSql.checkRows(0) tdSql.checkRows(0)
tdSql.query("select unique(c6) from ct3") tdSql.query(f"select unique(c6) from {dbname}.ct3")
# will support _rowts mix with # will support _rowts mix with
# tdSql.query("select unique(c6),_rowts from ct3") # tdSql.query(f"select unique(c6),_rowts from {dbname}.ct3")
# auto check for t1 table # auto check for t1 table
# used for regular table # used for regular table
tdSql.query("select unique(c1) from t1") tdSql.query(f"select unique(c1) from {dbname}.t1")
tdSql.query("desc t1") tdSql.query(f"desc {dbname}.t1")
col_lists_rows = tdSql.queryResult col_lists_rows = tdSql.queryResult
col_lists = [] col_lists = []
for col_name in col_lists_rows: for col_name in col_lists_rows:
col_lists.append(col_name[0]) col_lists.append(col_name[0])
for col in col_lists: for col in col_lists:
self.check_unique_table(f"select unique({col}) from t1") self.check_unique_table(f"select unique({col}) from {dbname}.t1")
# unique with super tags # unique with super tags
tdSql.query("select unique(c1) from ct1") tdSql.query(f"select unique(c1) from {dbname}.ct1")
tdSql.checkRows(10) tdSql.checkRows(10)
tdSql.query("select unique(c1) from ct4") tdSql.query(f"select unique(c1) from {dbname}.ct4")
tdSql.checkRows(10) tdSql.checkRows(10)
#tdSql.error("select unique(c1),tbname from ct1") #support #tdSql.error(f"select unique(c1),tbname from {dbname}.ct1") #support
#tdSql.error("select unique(c1),t1 from ct1") #support #tdSql.error(f"select unique(c1),t1 from {dbname}.ct1") #support
# unique with common col # unique with common col
#tdSql.error("select unique(c1) ,ts from ct1") #tdSql.error(f"select unique(c1) ,ts from {dbname}.ct1")
#tdSql.error("select unique(c1) ,c1 from ct1") #tdSql.error(f"select unique(c1) ,c1 from {dbname}.ct1")
# unique with scalar function # unique with scalar function
#tdSql.error("select unique(c1) ,abs(c1) from ct1") #tdSql.error(f"select unique(c1) ,abs(c1) from {dbname}.ct1")
tdSql.error("select unique(c1) , unique(c2) from ct1") tdSql.error(f"select unique(c1) , unique(c2) from {dbname}.ct1")
#tdSql.error("select unique(c1) , abs(c2)+2 from ct1") #tdSql.error(f"select unique(c1) , abs(c2)+2 from {dbname}.ct1")
# unique with aggregate function # unique with aggregate function
tdSql.error("select unique(c1) ,sum(c1) from ct1") tdSql.error(f"select unique(c1) ,sum(c1) from {dbname}.ct1")
tdSql.error("select unique(c1) ,max(c1) from ct1") tdSql.error(f"select unique(c1) ,max(c1) from {dbname}.ct1")
tdSql.error("select unique(c1) ,csum(c1) from ct1") tdSql.error(f"select unique(c1) ,csum(c1) from {dbname}.ct1")
tdSql.error("select unique(c1) ,count(c1) from ct1") tdSql.error(f"select unique(c1) ,count(c1) from {dbname}.ct1")
# unique with filter where # unique with filter where
tdSql.query("select unique(c1) from ct4 where c1 is null") tdSql.query(f"select unique(c1) from {dbname}.ct4 where c1 is null")
tdSql.checkData(0, 0, None) tdSql.checkData(0, 0, None)
tdSql.query("select unique(c1) from ct4 where c1 >2 order by 1") tdSql.query(f"select unique(c1) from {dbname}.ct4 where c1 >2 order by 1")
tdSql.checkData(0, 0, 3) tdSql.checkData(0, 0, 3)
tdSql.checkData(1, 0, 4) tdSql.checkData(1, 0, 4)
tdSql.checkData(2, 0, 5) tdSql.checkData(2, 0, 5)
tdSql.checkData(5, 0, 8) tdSql.checkData(5, 0, 8)
tdSql.query("select unique(c1) from ct4 where c2 between 0 and 99999 order by 1 desc") tdSql.query(f"select unique(c1) from {dbname}.ct4 where c2 between 0 and 99999 order by 1 desc")
tdSql.checkData(0, 0, 8) tdSql.checkData(0, 0, 8)
tdSql.checkData(1, 0, 7) tdSql.checkData(1, 0, 7)
tdSql.checkData(2, 0, 6) tdSql.checkData(2, 0, 6)
@ -307,43 +304,43 @@ class TDTestCase:
tdSql.checkData(8, 0, 0) tdSql.checkData(8, 0, 0)
# unique with union all # unique with union all
tdSql.query("select unique(c1) from ct4 union all select c1 from ct1") tdSql.query(f"select unique(c1) from {dbname}.ct4 union all select c1 from {dbname}.ct1")
tdSql.checkRows(23) tdSql.checkRows(23)
tdSql.query("select unique(c1) from ct4 union all select distinct(c1) from ct4") tdSql.query(f"select unique(c1) from {dbname}.ct4 union all select distinct(c1) from {dbname}.ct4")
tdSql.checkRows(20) tdSql.checkRows(20)
tdSql.query("select unique(c2) from ct4 union all select abs(c2)/2 from ct4") tdSql.query(f"select unique(c2) from {dbname}.ct4 union all select abs(c2)/2 from {dbname}.ct4")
tdSql.checkRows(22) tdSql.checkRows(22)
# unique with join # unique with join
# prepare join datas with same ts # prepare join datas with same ts
tdSql.execute(" use db ") tdSql.execute(" use db ")
tdSql.execute(" create stable st1 (ts timestamp , num int) tags(ind int)") tdSql.execute(" create stable db.st1 (ts timestamp , num int) tags(ind int)")
tdSql.execute(" create table tb1 using st1 tags(1)") tdSql.execute(" create table db.tb1 using db.st1 tags(1)")
tdSql.execute(" create table tb2 using st1 tags(2)") tdSql.execute(" create table db.tb2 using db.st1 tags(2)")
tdSql.execute(" create stable st2 (ts timestamp , num int) tags(ind int)") tdSql.execute(" create stable db.st2 (ts timestamp , num int) tags(ind int)")
tdSql.execute(" create table ttb1 using st2 tags(1)") tdSql.execute(" create table db.ttb1 using db.st2 tags(1)")
tdSql.execute(" create table ttb2 using st2 tags(2)") tdSql.execute(" create table db.ttb2 using db.st2 tags(2)")
start_ts = 1622369635000 # 2021-05-30 18:13:55 start_ts = 1622369635000 # 2021-05-30 18:13:55
for i in range(10): for i in range(10):
ts_value = start_ts+i*1000 ts_value = start_ts+i*1000
tdSql.execute(f" insert into tb1 values({ts_value} , {i})") tdSql.execute(f" insert into {dbname}.tb1 values({ts_value} , {i})")
tdSql.execute(f" insert into tb2 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 {dbname}.ttb1 values({ts_value} , {i})")
tdSql.execute(f" insert into ttb2 values({ts_value} , {i})") tdSql.execute(f" insert into {dbname}.ttb2 values({ts_value} , {i})")
tdSql.query("select unique(tb2.num) from tb1, tb2 where tb1.ts=tb2.ts order by 1") tdSql.query(f"select unique(tb2.num) from db.tb1 tb1, db.tb2 tb2 where tb1.ts=tb2.ts order by 1")
tdSql.checkRows(10) tdSql.checkRows(10)
tdSql.checkData(0,0,0) tdSql.checkData(0,0,0)
tdSql.checkData(1,0,1) tdSql.checkData(1,0,1)
tdSql.checkData(2,0,2) tdSql.checkData(2,0,2)
tdSql.checkData(9,0,9) tdSql.checkData(9,0,9)
tdSql.query("select unique(tb2.num) from tb1, tb2 where tb1.ts=tb2.ts union all select unique(tb1.num) from tb1, tb2 where tb1.ts=tb2.ts order by 1") tdSql.query(f"select unique(tb2.num) from db.tb1 tb1, db.tb2 tb2 where tb1.ts=tb2.ts union all select unique(tb1.num) from db.tb1 tb1, db.tb2 tb2 where tb1.ts=tb2.ts order by 1")
tdSql.checkRows(20) tdSql.checkRows(20)
tdSql.checkData(0,0,0) tdSql.checkData(0,0,0)
tdSql.checkData(2,0,1) tdSql.checkData(2,0,1)
@ -351,23 +348,23 @@ class TDTestCase:
tdSql.checkData(18,0,9) tdSql.checkData(18,0,9)
# nest query # nest query
# tdSql.query("select unique(c1) from (select c1 from ct1)") # tdSql.query(f"select unique(c1) from (select c1 from {dbname}.ct1)")
tdSql.query("select c1 from (select unique(c1) c1 from ct4) order by 1 desc nulls first") tdSql.query(f"select c1 from (select unique(c1) c1 from {dbname}.ct4) order by 1 desc nulls first")
tdSql.checkRows(10) tdSql.checkRows(10)
tdSql.checkData(0, 0, None) tdSql.checkData(0, 0, None)
tdSql.checkData(1, 0, 8) tdSql.checkData(1, 0, 8)
tdSql.checkData(9, 0, 0) tdSql.checkData(9, 0, 0)
tdSql.query("select sum(c1) from (select unique(c1) c1 from ct1)") tdSql.query(f"select sum(c1) from (select unique(c1) c1 from {dbname}.ct1)")
tdSql.checkRows(1) tdSql.checkRows(1)
tdSql.checkData(0, 0, 45) tdSql.checkData(0, 0, 45)
tdSql.query("select sum(c1) from (select distinct(c1) c1 from ct1) union all select sum(c1) from (select unique(c1) c1 from ct1)") tdSql.query(f"select sum(c1) from (select distinct(c1) c1 from {dbname}.ct1) union all select sum(c1) from (select unique(c1) c1 from {dbname}.ct1)")
tdSql.checkRows(2) tdSql.checkRows(2)
tdSql.checkData(0, 0, 45) tdSql.checkData(0, 0, 45)
tdSql.checkData(1, 0, 45) tdSql.checkData(1, 0, 45)
tdSql.query("select 1-abs(c1) from (select unique(c1) c1 from ct4) order by 1 nulls first") tdSql.query(f"select 1-abs(c1) from (select unique(c1) c1 from {dbname}.ct4) order by 1 nulls first")
tdSql.checkRows(10) tdSql.checkRows(10)
tdSql.checkData(0, 0, None) tdSql.checkData(0, 0, None)
tdSql.checkData(1, 0, -7.000000000) tdSql.checkData(1, 0, -7.000000000)
@ -375,104 +372,103 @@ class TDTestCase:
# bug for stable # bug for stable
#partition by tbname #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.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) # tdSql.checkRows(21)
# group by # group by
tdSql.error("select unique(c1) from ct1 group by c1") tdSql.error(f"select unique(c1) from {dbname}.ct1 group by c1")
tdSql.error("select unique(c1) from ct1 group by tbname") tdSql.error(f"select unique(c1) from {dbname}.ct1 group by tbname")
# super table # super table
# super table # super table
tdSql.error("select tbname , tail(c1,2) from stb1 group by tbname") tdSql.error(f"select tbname , tail(c1,2) from {dbname}.stb1 group by tbname")
tdSql.query("select tail(c1,2) from stb1 partition by tbname") tdSql.query(f"select tail(c1,2) from {dbname}.stb1 partition by tbname")
tdSql.checkRows(4) tdSql.checkRows(4)
# bug need fix # bug need fix
# tdSql.query("select tbname , tail(c1,2) from stb1 partition by tbname") # tdSql.query(f"select tbname , tail(c1,2) from {dbname}.stb1 partition by tbname")
# tdSql.checkRows(4) # tdSql.checkRows(4)
# tdSql.query("select tbname , tail(c1,2) from stb1 partition by tbname order by tbname") # tdSql.query(f"select tbname , tail(c1,2) from {dbname}.stb1 partition by tbname order by tbname")
# tdSql.checkRows(4) # tdSql.checkRows(4)
# tdSql.query(" select tbname , count(c1) from stb1 partition by tbname order by tbname ") # tdSql.query(f"select tbname , count(c1) from {dbname}.stb1 partition by tbname order by tbname ")
# tdSql.checkRows(2) # tdSql.checkRows(2)
# tdSql.query(" select tbname , max(c1) ,c1 from stb1 partition by tbname order by tbname ") # tdSql.query(f"select tbname , max(c1) ,c1 from {dbname}.stb1 partition by tbname order by tbname ")
# tdSql.checkRows(2) # tdSql.checkRows(2)
# tdSql.query(" select tbname ,first(c1) from stb1 partition by tbname order by tbname ") # tdSql.query(f"select tbname ,first(c1) from {dbname}.stb1 partition by tbname order by tbname ")
# tdSql.checkRows(2) # tdSql.checkRows(2)
tdSql.query("select tail(c1,2) from stb1 partition by tbname") tdSql.query(f"select tail(c1,2) from {dbname}.stb1 partition by tbname")
tdSql.checkRows(4) tdSql.checkRows(4)
# # bug need fix # # bug need fix
# tdSql.query(" select tbname , unique(c1) from stb1 where t1 = 0 partition by tbname ") # tdSql.query(f"select tbname , unique(c1) from {dbname}.stb1 where t1 = 0 partition by tbname ")
# tdSql.checkRows(2) # tdSql.checkRows(2)
# tdSql.query(" select tbname , unique(c1) from stb1 where t1 = 0 partition by tbname order by tbname ") # tdSql.query(f"select tbname , unique(c1) from {dbname}.stb1 where t1 = 0 partition by tbname order by tbname ")
# tdSql.checkRows(2) # tdSql.checkRows(2)
# tdSql.query(" select tbname , unique(c1) from stb1 where c1 = 0 partition by tbname order by tbname ") # tdSql.query(f"select tbname , unique(c1) from {dbname}.stb1 where c1 = 0 partition by tbname order by tbname ")
# tdSql.checkRows(3) # tdSql.checkRows(3)
# tdSql.query(" select tbname , unique(c1) from stb1 where c1 = 0 partition by tbname ") # tdSql.query(f"select tbname , unique(c1) from {dbname}.stb1 where c1 = 0 partition by tbname ")
# tdSql.checkRows(3) # tdSql.checkRows(3)
tdSql.query(" select unique(t1) from stb1 ") tdSql.query(f"select unique(t1) from {dbname}.stb1 ")
tdSql.checkRows(2) tdSql.checkRows(2)
tdSql.query(" select unique(t1+c1) from stb1 ") tdSql.query(f"select unique(t1+c1) from {dbname}.stb1 ")
tdSql.checkRows(13) tdSql.checkRows(13)
tdSql.query(" select unique(t1+c1) from stb1 partition by tbname ") tdSql.query(f"select unique(t1+c1) from {dbname}.stb1 partition by tbname ")
tdSql.checkRows(20) tdSql.checkRows(20)
tdSql.query(" select unique(t1) from stb1 partition by tbname ") tdSql.query(f"select unique(t1) from {dbname}.stb1 partition by tbname ")
tdSql.checkRows(2) tdSql.checkRows(2)
# nest query # nest query
tdSql.query(" select unique(c1) from (select _rowts , t1 ,c1 , tbname from stb1 ) ") tdSql.query(f"select unique(c1) from (select _rowts , t1 ,c1 , tbname from {dbname}.stb1 ) ")
tdSql.checkRows(11) tdSql.checkRows(11)
tdSql.checkData(0,0,6) tdSql.checkData(0,0,6)
tdSql.checkData(10,0,3) tdSql.checkData(10,0,3)
tdSql.query("select unique(t1) from (select _rowts , t1 , tbname from stb1 )") tdSql.query(f"select unique(t1) from (select _rowts , t1 , tbname from {dbname}.stb1 )")
tdSql.checkRows(2) tdSql.checkRows(2)
tdSql.checkData(0,0,4) tdSql.checkData(0,0,4)
tdSql.checkData(1,0,1) tdSql.checkData(1,0,1)
def check_boundary_values(self): def check_boundary_values(self, dbname="bound_test"):
tdSql.execute("drop database if exists bound_test") tdSql.execute(f"drop database if exists {dbname}")
tdSql.execute("create database if not exists bound_test") tdSql.execute(f"create database if not exists {dbname}")
tdSql.execute("use bound_test")
tdSql.execute( tdSql.execute(
"create table stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);" f"create table {dbname}.stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);"
) )
tdSql.execute(f'create table sub1_bound using stb_bound tags ( 1 )') tdSql.execute(f'create table {dbname}.sub1_bound using {dbname}.stb_bound tags ( 1 )')
tdSql.execute( tdSql.execute(
f"insert into sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" f"insert into {dbname}.sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
) )
tdSql.execute( tdSql.execute(
f"insert into sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" f"insert into {dbname}.sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
) )
tdSql.execute( tdSql.execute(
f"insert into sub1_bound values ( now()+1s, -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" f"insert into {dbname}.sub1_bound values ( now()+1s, -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
) )
tdSql.execute( tdSql.execute(
f"insert into sub1_bound values ( now()+2s, 2147483643, 9223372036854775803, 32763, 123, 3.39E+38, 1.69e+308, True, 'binary_tb1', 'nchar_tb1', now() )" f"insert into {dbname}.sub1_bound values ( now()+2s, 2147483643, 9223372036854775803, 32763, 123, 3.39E+38, 1.69e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
) )
tdSql.execute( tdSql.execute(
f"insert into sub1_bound values ( now()+3s, -2147483643, -9223372036854775803, -32763, -123, -3.39E+38, -1.69e+308, True, 'binary_tb1', 'nchar_tb1', now() )" f"insert into {dbname}.sub1_bound values ( now()+3s, -2147483643, -9223372036854775803, -32763, -123, -3.39E+38, -1.69e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
) )
tdSql.error( tdSql.error(
f"insert into sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" f"insert into {dbname}.sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
) )
tdSql.query("select unique(c2) from sub1_bound order by 1 desc") tdSql.query(f"select unique(c2) from {dbname}.sub1_bound order by 1 desc")
tdSql.checkRows(5) tdSql.checkRows(5)
tdSql.checkData(0,0,9223372036854775807) tdSql.checkData(0,0,9223372036854775807)

View File

@ -95,16 +95,16 @@ class TDTestCase:
return sqls return sqls
def __test_current(self): def __test_current(self, dbname="db"):
tdLog.printNoPrefix("==========current sql condition check , must return query ok==========") tdLog.printNoPrefix("==========current sql condition check , must return query ok==========")
tbname = ["ct1", "ct2", "ct4", "t1", "stb1"] tbname = [f"{dbname}.ct1", f"{dbname}.ct2", f"{dbname}.ct4", f"{dbname}.t1", f"{dbname}.stb1"]
for tb in tbname: for tb in tbname:
self.__upper_current_check(tb) self.__upper_current_check(tb)
tdLog.printNoPrefix(f"==========current sql condition check in {tb} over==========") tdLog.printNoPrefix(f"==========current sql condition check in {tb} over==========")
def __test_error(self): def __test_error(self, dbname="db"):
tdLog.printNoPrefix("==========err sql condition check , must return error==========") tdLog.printNoPrefix("==========err sql condition check , must return error==========")
tbname = ["ct1", "ct2", "ct4", "t1", "stb1"] tbname = [f"{dbname}.ct1", f"{dbname}.ct2", f"{dbname}.ct4", f"{dbname}.t1", f"{dbname}.stb1"]
for tb in tbname: for tb in tbname:
for errsql in self.__upper_err_check(tb): for errsql in self.__upper_err_check(tb):
@ -112,22 +112,20 @@ class TDTestCase:
tdLog.printNoPrefix(f"==========err sql condition check in {tb} over==========") tdLog.printNoPrefix(f"==========err sql condition check in {tb} over==========")
def all_test(self): def all_test(self, dbname="db"):
self.__test_current() self.__test_current(dbname)
self.__test_error() self.__test_error(dbname)
def __create_tb(self, dbname="db"):
def __create_tb(self):
tdSql.prepare()
tdLog.printNoPrefix("==========step1:create table") tdLog.printNoPrefix("==========step1:create table")
create_stb_sql = f'''create table stb1( create_stb_sql = f'''create table {dbname}.stb1(
ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint,
{FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool,
{BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp
) tags (t1 int) ) tags (tag1 int)
''' '''
create_ntb_sql = f'''create table t1( create_ntb_sql = f'''create table {dbname}.t1(
ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint,
{FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool,
{BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp
@ -137,83 +135,82 @@ class TDTestCase:
tdSql.execute(create_ntb_sql) tdSql.execute(create_ntb_sql)
for i in range(4): for i in range(4):
tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( {i+1} )')
def __insert_data(self, rows): def __insert_data(self, rows, dbname="db"):
now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000)
for i in range(rows): for i in range(rows):
tdSql.execute( tdSql.execute(
f"insert into ct1 values ( { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" f"insert into {dbname}.ct1 values ( { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )"
) )
tdSql.execute( tdSql.execute(
f"insert into ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" f"insert into {dbname}.ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )"
) )
tdSql.execute( tdSql.execute(
f"insert into ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" f"insert into {dbname}.ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )"
) )
tdSql.execute( tdSql.execute(
f'''insert into ct1 values f'''insert into {dbname}.ct1 values
( { now_time - rows * 5 }, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', { now_time + 8 } ) ( { now_time - rows * 5 }, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar_测试_0', { now_time + 8 } )
( { now_time + 10000 }, { rows }, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', { now_time + 9 } ) ( { now_time + 10000 }, { rows }, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar_测试_9', { now_time + 9 } )
''' '''
) )
tdSql.execute( tdSql.execute(
f'''insert into ct4 values f'''insert into {dbname}.ct4 values
( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
( { now_time - rows * 3888000000 + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 3888000000 + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
( (
{ now_time + 5184000000}, {pow(2,31)-pow(2,15)}, {pow(2,63)-pow(2,30)}, 32767, 127, { now_time + 5184000000}, {pow(2,31)-pow(2,15)}, {pow(2,63)-pow(2,30)}, 32767, 127,
{ 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_limit-1", { now_time - 86400000} { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_测试_limit-1", { now_time - 86400000}
) )
( (
{ now_time + 2592000000 }, {pow(2,31)-pow(2,16)}, {pow(2,63)-pow(2,31)}, 32766, 126, { now_time + 2592000000 }, {pow(2,31)-pow(2,16)}, {pow(2,63)-pow(2,31)}, 32766, 126,
{ 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_limit-2", { now_time - 172800000} { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_测试_limit-2", { now_time - 172800000}
) )
''' '''
) )
tdSql.execute( tdSql.execute(
f'''insert into ct2 values f'''insert into {dbname}.ct2 values
( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
( { now_time - rows * 3888000000 + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 3888000000 + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
( (
{ now_time + 5184000000 }, { -1 * pow(2,31) + pow(2,15) }, { -1 * pow(2,63) + pow(2,30) }, -32766, -126, { now_time + 5184000000 }, { -1 * pow(2,31) + pow(2,15) }, { -1 * pow(2,63) + pow(2,30) }, -32766, -126,
{ -1 * 3.2 * pow(10,38) }, { -1.2 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_limit-1", { now_time - 86400000 } { -1 * 3.2 * pow(10,38) }, { -1.2 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_测试_limit-1", { now_time - 86400000 }
) )
( (
{ now_time + 2592000000 }, { -1 * pow(2,31) + pow(2,16) }, { -1 * pow(2,63) + pow(2,31) }, -32767, -127, { now_time + 2592000000 }, { -1 * pow(2,31) + pow(2,16) }, { -1 * pow(2,63) + pow(2,31) }, -32767, -127,
{ - 3.3 * pow(10,38) }, { -1.3 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_limit-2", { now_time - 172800000 } { - 3.3 * pow(10,38) }, { -1.3 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_测试_limit-2", { now_time - 172800000 }
) )
''' '''
) )
for i in range(rows): for i in range(rows):
insert_data = f'''insert into t1 values insert_data = f'''insert into {dbname}.t1 values
( { now_time - i * 3600000 }, {i}, {i * 11111}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}, ( { now_time - i * 3600000 }, {i}, {i * 11111}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2},
"binary_{i}", "nchar_{i}", { now_time - 1000 * i } ) "binary_{i}", "nchar_测试_{i}", { now_time - 1000 * i } )
''' '''
tdSql.execute(insert_data) tdSql.execute(insert_data)
tdSql.execute( tdSql.execute(
f'''insert into t1 values f'''insert into {dbname}.t1 values
( { now_time + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
( { now_time - (( rows // 2 ) * 60 + 30) * 60000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - (( rows // 2 ) * 60 + 30) * 60000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
( { now_time - rows * 3600000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 3600000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
( { now_time + 7200000 }, { pow(2,31) - pow(2,15) }, { pow(2,63) - pow(2,30) }, 32767, 127, ( { now_time + 7200000 }, { pow(2,31) - pow(2,15) }, { pow(2,63) - pow(2,30) }, 32767, 127,
{ 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 },
"binary_limit-1", "nchar_limit-1", { now_time - 86400000 } "binary_limit-1", "nchar_测试_limit-1", { now_time - 86400000 }
) )
( (
{ now_time + 3600000 } , { pow(2,31) - pow(2,16) }, { pow(2,63) - pow(2,31) }, 32766, 126, { now_time + 3600000 } , { pow(2,31) - pow(2,16) }, { pow(2,63) - pow(2,31) }, 32766, 126,
{ 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 },
"binary_limit-2", "nchar_limit-2", { now_time - 172800000 } "binary_limit-2", "nchar_测试_limit-2", { now_time - 172800000 }
) )
''' '''
) )
def run(self): def run(self):
tdSql.prepare() tdSql.prepare()
@ -226,8 +223,7 @@ class TDTestCase:
tdLog.printNoPrefix("==========step3:all check") tdLog.printNoPrefix("==========step3:all check")
self.all_test() self.all_test()
tdDnodes.stop(1) tdSql.execute("flush database db")
tdDnodes.start(1)
tdSql.execute("use db") tdSql.execute("use db")

View File

@ -14,43 +14,44 @@ class TDTestCase:
tdSql.init(conn.cursor()) tdSql.init(conn.cursor())
def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring
dbname = "db"
tdSql.prepare() tdSql.prepare()
tdLog.printNoPrefix("==========step1:create table") tdLog.printNoPrefix("==========step1:create table")
tdSql.execute( tdSql.execute(
'''create table stb1 f'''create table {dbname}.stb1
(ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 varchar(16),c9 nchar(32), c10 timestamp) (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 varchar(16),c9 nchar(32), c10 timestamp)
tags (t1 int) tags (t1 int)
''' '''
) )
tdSql.execute( tdSql.execute(
''' f'''
create table t1 create table {dbname}.t1
(ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 varchar(16),c9 nchar(32), c10 timestamp) (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 varchar(16),c9 nchar(32), c10 timestamp)
''' '''
) )
for i in range(4): for i in range(4):
tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( {i+1} )')
tdLog.printNoPrefix("==========step2:insert data") tdLog.printNoPrefix("==========step2:insert data")
for i in range(9): for i in range(9):
tdSql.execute( tdSql.execute(
f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'varchar{i}', 'nchar{i}', now()+{1*i}a )" f"insert into {dbname}.ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'varchar{i}', 'nchar{i}', now()+{1*i}a )"
) )
tdSql.execute( tdSql.execute(
f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'varchar{i}', 'nchar{i}', now()+{1*i}a )" f"insert into {dbname}.ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'varchar{i}', 'nchar{i}', now()+{1*i}a )"
) )
tdSql.execute("insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'varchar0', 'nchar0', now()+8a )") tdSql.execute(f"insert into {dbname}.ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'varchar0', 'nchar0', now()+8a )")
tdSql.execute("insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'varchar9', 'nchar9', now()+9a )") tdSql.execute(f"insert into {dbname}.ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'varchar9', 'nchar9', now()+9a )")
tdSql.execute("insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute(f"insert into {dbname}.ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ")
tdSql.execute("insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute(f"insert into {dbname}.ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ")
tdSql.execute("insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute(f"insert into {dbname}.ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ")
tdSql.execute( tdSql.execute(
f'''insert into t1 values f'''insert into {dbname}.t1 values
( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "varchar1", "nchar1", now()+1a ) ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "varchar1", "nchar1", now()+1a )
( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "varchar2", "nchar2", now()+2a ) ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "varchar2", "nchar2", now()+2a )
@ -70,7 +71,7 @@ class TDTestCase:
tdLog.printNoPrefix("==========step3: cast on varchar") tdLog.printNoPrefix("==========step3: cast on varchar")
tdSql.query("select c8 from ct1") tdSql.query(f"select c8 from {dbname}.ct1")
for i in range(tdSql.queryRows): for i in range(tdSql.queryRows):
tdSql.checkData(i,0, data_ct1_c8[i]) tdSql.checkData(i,0, data_ct1_c8[i])

View File

@ -124,8 +124,14 @@ python3 ./test.py -f 2-query/leastsquares.py
python3 ./test.py -f 2-query/leastsquares.py -R python3 ./test.py -f 2-query/leastsquares.py -R
python3 ./test.py -f 2-query/length.py python3 ./test.py -f 2-query/length.py
python3 ./test.py -f 2-query/length.py -R python3 ./test.py -f 2-query/length.py -R
python3 ./test.py -f 2-query/log.py
# python3 ./test.py -f 2-query/log.py -R
python3 ./test.py -f 2-query/lower.py
python3 ./test.py -f 2-query/lower.py -R
python3 ./test.py -f 2-query/ltrim.py python3 ./test.py -f 2-query/ltrim.py
python3 ./test.py -f 2-query/ltrim.py -R python3 ./test.py -f 2-query/ltrim.py -R
python3 ./test.py -f 2-query/mavg.py
python3 ./test.py -f 2-query/mavg.py -R
python3 ./test.py -f 2-query/max_partition.py python3 ./test.py -f 2-query/max_partition.py
python3 ./test.py -f 2-query/max_partition.py -R python3 ./test.py -f 2-query/max_partition.py -R
python3 ./test.py -f 2-query/max.py python3 ./test.py -f 2-query/max.py
@ -147,7 +153,7 @@ python3 ./test.py -f 2-query/rtrim.py -R
python3 ./test.py -f 2-query/sample.py python3 ./test.py -f 2-query/sample.py
python3 ./test.py -f 2-query/sample.py -R python3 ./test.py -f 2-query/sample.py -R
python3 ./test.py -f 2-query/sin.py python3 ./test.py -f 2-query/sin.py
# python3 ./test.py -f 2-query/sin.py -R python3 ./test.py -f 2-query/sin.py -R
python3 ./test.py -f 2-query/smaTest.py python3 ./test.py -f 2-query/smaTest.py
python3 ./test.py -f 2-query/smaTest.py -R python3 ./test.py -f 2-query/smaTest.py -R
python3 ./test.py -f 2-query/sml.py python3 ./test.py -f 2-query/sml.py
@ -155,7 +161,7 @@ python3 ./test.py -f 2-query/sml.py -R
python3 ./test.py -f 2-query/spread.py python3 ./test.py -f 2-query/spread.py
python3 ./test.py -f 2-query/spread.py -R python3 ./test.py -f 2-query/spread.py -R
python3 ./test.py -f 2-query/sqrt.py python3 ./test.py -f 2-query/sqrt.py
# python3 ./test.py -f 2-query/sqrt.py -R python3 ./test.py -f 2-query/sqrt.py -R
python3 ./test.py -f 2-query/statecount.py python3 ./test.py -f 2-query/statecount.py
python3 ./test.py -f 2-query/statecount.py -R python3 ./test.py -f 2-query/statecount.py -R
python3 ./test.py -f 2-query/stateduration.py python3 ./test.py -f 2-query/stateduration.py
@ -167,32 +173,48 @@ python3 ./test.py -f 2-query/sum.py -R
python3 ./test.py -f 2-query/tail.py python3 ./test.py -f 2-query/tail.py
python3 ./test.py -f 2-query/tail.py -R python3 ./test.py -f 2-query/tail.py -R
python3 ./test.py -f 2-query/tan.py python3 ./test.py -f 2-query/tan.py
python3 ./test.py -f 2-query/tan.py -R # python3 ./test.py -f 2-query/tan.py -R
python3 ./test.py -f 2-query/Timediff.py
python3 ./test.py -f 2-query/Timediff.py -R
python3 ./test.py -f 2-query/timetruncate.py
# python3 ./test.py -f 2-query/timetruncate.py -R
python3 ./test.py -f 2-query/timezone.py
python3 ./test.py -f 2-query/timezone.py -R
python3 ./test.py -f 2-query/To_iso8601.py
python3 ./test.py -f 2-query/To_iso8601.py -R
python3 ./test.py -f 2-query/To_unixtimestamp.py
python3 ./test.py -f 2-query/To_unixtimestamp.py -R
python3 ./test.py -f 2-query/Today.py
# python3 ./test.py -f 2-query/Today.py -R
python3 ./test.py -f 2-query/top.py
python3 ./test.py -f 2-query/top.py -R
python3 ./test.py -f 2-query/tsbsQuery.py
python3 ./test.py -f 2-query/tsbsQuery.py -R
python3 ./test.py -f 2-query/ttl_comment.py
python3 ./test.py -f 2-query/ttl_comment.py -R
python3 ./test.py -f 2-query/twa.py
python3 ./test.py -f 2-query/twa.py -R
python3 ./test.py -f 2-query/union.py
python3 ./test.py -f 2-query/union.py -R
python3 ./test.py -f 2-query/unique.py
python3 ./test.py -f 2-query/unique.py -R
python3 ./test.py -f 2-query/upper.py
python3 ./test.py -f 2-query/upper.py -R
python3 ./test.py -f 2-query/varchar.py
python3 ./test.py -f 2-query/varchar.py -R
python3 ./test.py -f 1-insert/update_data.py python3 ./test.py -f 1-insert/update_data.py
python3 ./test.py -f 1-insert/delete_data.py python3 ./test.py -f 1-insert/delete_data.py
python3 ./test.py -f 2-query/varchar.py
python3 ./test.py -f 2-query/upper.py
python3 ./test.py -f 2-query/lower.py
python3 ./test.py -f 2-query/join2.py python3 ./test.py -f 2-query/join2.py
python3 ./test.py -f 2-query/union.py
python3 ./test.py -f 2-query/union1.py python3 ./test.py -f 2-query/union1.py
python3 ./test.py -f 2-query/concat2.py python3 ./test.py -f 2-query/concat2.py
python3 ./test.py -f 2-query/timezone.py
python3 ./test.py -f 2-query/Today.py
python3 ./test.py -f 2-query/To_iso8601.py
python3 ./test.py -f 2-query/To_unixtimestamp.py
python3 ./test.py -f 2-query/timetruncate.py
python3 ./test.py -f 2-query/Timediff.py
python3 ./test.py -f 2-query/json_tag.py python3 ./test.py -f 2-query/json_tag.py
python3 ./test.py -f 2-query/top.py
python3 ./test.py -f 2-query/log.py
# python3 ./test.py -f 2-query/nestedQuery.py # python3 ./test.py -f 2-query/nestedQuery.py
# TD-15983 subquery output duplicate name column. # TD-15983 subquery output duplicate name column.
# Please Xiangyang Guo modify the following script # Please Xiangyang Guo modify the following script
@ -200,13 +222,8 @@ python3 ./test.py -f 2-query/log.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/csum.py
python3 ./test.py -f 2-query/mavg.py
python3 ./test.py -f 2-query/function_diff.py python3 ./test.py -f 2-query/function_diff.py
python3 ./test.py -f 2-query/unique.py
python3 ./test.py -f 2-query/ttl_comment.py
python3 ./test.py -f 2-query/twa.py
python3 ./test.py -f 2-query/queryQnode.py python3 ./test.py -f 2-query/queryQnode.py
python3 ./test.py -f 2-query/tsbsQuery.py
python3 ./test.py -f 6-cluster/5dnode1mnode.py python3 ./test.py -f 6-cluster/5dnode1mnode.py
python3 ./test.py -f 6-cluster/5dnode2mnode.py -N 5 -M 3 python3 ./test.py -f 6-cluster/5dnode2mnode.py -N 5 -M 3