From 3ad89e52404a611135bd00f08c3bcb31865c23fc Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Thu, 21 Jul 2022 19:31:50 +0800 Subject: [PATCH] fix(query): fix test cases --- tests/system-test/2-query/log.py | 118 +++++++++--------- .../2-query/query_cols_tags_and_or.py | 30 ++--- 2 files changed, 74 insertions(+), 74 deletions(-) diff --git a/tests/system-test/2-query/log.py b/tests/system-test/2-query/log.py index f08a4b20de..b8e0aaf52e 100644 --- a/tests/system-test/2-query/log.py +++ b/tests/system-test/2-query/log.py @@ -10,13 +10,13 @@ from util.cases import * class TDTestCase: - updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , + 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): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) - + def prepare_datas(self): tdSql.execute( '''create table stb1 @@ -24,7 +24,7 @@ class TDTestCase: tags (t1 int) ''' ) - + tdSql.execute( ''' create table t1 @@ -69,12 +69,12 @@ class TDTestCase: def check_result_auto_log(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: @@ -91,20 +91,20 @@ class TDTestCase: 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 + 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: @@ -121,7 +121,7 @@ class TDTestCase: 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 + check_status = False if not check_status: tdLog.notice("log function value has not as expected , sql is \"%s\" "%log_query ) sys.exit(1) @@ -133,7 +133,7 @@ class TDTestCase: origin_result = tdSql.getResult(origin_query) auto_result =[] - + for row in origin_result: row_check = [] for elem in row: @@ -150,7 +150,7 @@ class TDTestCase: 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 + check_status = False if not check_status: tdLog.notice("log function value has not as expected , sql is \"%s\" "%log_query ) sys.exit(1) @@ -161,7 +161,7 @@ class TDTestCase: origin_result = tdSql.getResult(origin_query) auto_result =[] - + for row in origin_result: row_check = [] for elem in row: @@ -178,13 +178,13 @@ class TDTestCase: 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 + 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): error_sql_lists = [ "select log from t1", @@ -218,42 +218,42 @@ class TDTestCase: ] for error_sql in error_sql_lists: tdSql.error(error_sql) - + def support_types(self): type_error_sql_lists = [ - "select log(ts ,2 ) from t1" , + "select log(ts ,2 ) from t1" , "select log(c7,c2 ) from t1", "select log(c8,c1 ) from t1", "select log(c9,c2 ) from t1", - "select log(ts,c7 ) from ct1" , + "select log(ts,c7 ) from ct1" , "select log(c7,c9 ) from ct1", "select log(c8,c2 ) from ct1", "select log(c9,c1 ) from ct1", - "select log(ts,2 ) from ct3" , + "select log(ts,2 ) from ct3" , "select log(c7,2 ) from ct3", "select log(c8,2 ) from ct3", "select log(c9,2 ) from ct3", - "select log(ts,2 ) from ct4" , + "select log(ts,2 ) from ct4" , "select log(c7,2 ) from ct4", "select log(c8,2 ) from ct4", "select log(c9,2 ) from ct4", - "select log(ts,2 ) from stb1" , + "select log(ts,2 ) from stb1" , "select log(c7,2 ) from stb1", "select log(c8,2 ) from stb1", "select log(c9,2 ) from stb1" , - "select log(ts,2 ) from stbbb1" , + "select log(ts,2 ) from stbbb1" , "select log(c7,2 ) from stbbb1", "select log(ts,2 ) from tbname", "select log(c9,2 ) from tbname" ] - + for type_sql in type_error_sql_lists: tdSql.error(type_sql) - - + + type_sql_lists = [ "select log(c1,2 ) from t1", "select log(c2,2 ) from t1", @@ -283,16 +283,16 @@ class TDTestCase: "select log(c5,2 ) from stb1", "select log(c6,2 ) from stb1", - "select log(c6,2) as alisb from stb1", - "select log(c6,2) alisb from stb1", + "select log(c6,2) as alisb from stb1", + "select log(c6,2) alisb from stb1", ] for type_sql in type_sql_lists: tdSql.query(type_sql) - + def basic_log_function(self): - # basic query + # basic query tdSql.query("select c1 from ct3") tdSql.checkRows(0) tdSql.query("select c1 from t1") @@ -344,7 +344,7 @@ class TDTestCase: self.check_result_auto_log2( "select c1, c2, c3 , c4, c5 from t1", "select log(c1 ,2), log(c2 ,2) ,log(c3, 2), log(c4 ,2), log(c5 ,2) from t1") self.check_result_auto_log1( "select c1, c2, c3 , c4, c5 from t1", "select log(c1 ,1), log(c2 ,1) ,log(c3, 1), log(c4 ,1), log(c5 ,1) from t1") self.check_result_auto_log__10( "select c1, c2, c3 , c4, c5 from t1", "select log(c1 ,-10), log(c2 ,-10) ,log(c3, -10), log(c4 ,-10), log(c5 ,-10) from t1") - + # used for sub table tdSql.query("select c1 ,log(c1 ,3) from ct1") tdSql.checkData(0, 1, 1.892789261) @@ -382,18 +382,18 @@ class TDTestCase: tdSql.checkData(4 , 2 , None) tdSql.checkData(4 , 3 , None) - # # used for stable table - + # # used for stable table + tdSql.query("select log(c1, 2) from stb1") tdSql.checkRows(25) - + # used for not exists table tdSql.error("select log(c1, 2) from stbbb1") tdSql.error("select log(c1, 2) from tbname") tdSql.error("select log(c1, 2) from ct5") - # mix with common col + # mix with common col tdSql.query("select c1, log(c1 ,2) from ct1") tdSql.checkData(0 , 0 ,8) tdSql.checkData(0 , 1 ,3.000000000) @@ -418,7 +418,7 @@ class TDTestCase: tdSql.checkData(0 , 1 ,None) tdSql.checkData(0 , 2 ,None) tdSql.checkData(0 , 3 ,None) - + tdSql.checkData(3 , 0 , 6) tdSql.checkData(3 , 1 , 2.584962501) tdSql.checkData(3 , 2 ,6.66000) @@ -439,7 +439,7 @@ class TDTestCase: tdSql.query("select max(c5), count(c5) from stb1") tdSql.query("select max(c5), count(c5) from ct1") - + # bug fix for count tdSql.query("select count(c1) from ct4 ") tdSql.checkData(0,0,9) @@ -450,7 +450,7 @@ class TDTestCase: tdSql.query("select count(*) from stb1 ") tdSql.checkData(0,0,25) - # # bug fix for compute + # # bug fix for compute tdSql.query("select c1, log(c1 ,2) -0 ,log(c1-4 ,2)-0 from ct4 ") tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, None) @@ -507,40 +507,40 @@ class TDTestCase: # base is an regular number ,int or double tdSql.query("select c1, log(c1, 2) from ct1") tdSql.checkData(0, 1,3.000000000) - tdSql.query("select c1, log(c1, 2.0) from ct1") + tdSql.query("select c1, log(c1, 2.0) from ct1") tdSql.checkData(0, 1, 3.000000000) - tdSql.query("select c1, log(1, 2.0) from ct1") + tdSql.query("select c1, log(1, 2.0) from ct1") tdSql.checkData(0, 1, 0.000000000) tdSql.checkRows(13) # # bug for compute in functions - # tdSql.query("select c1, abs(1/0) from ct1") + # tdSql.query("select c1, abs(1/0) from ct1") # tdSql.checkData(0, 0, 8) # tdSql.checkData(0, 1, 1) - tdSql.query("select c1, log(1, 2.0) from ct1") + tdSql.query("select c1, log(1, 2.0) from ct1") tdSql.checkData(0, 1, 0.000000000) tdSql.checkRows(13) # two cols start log(x,y) - tdSql.query("select c1,c2, log(c1,c2) from ct1") + tdSql.query("select c1,c2, log(c1,c2) from ct1") tdSql.checkData(0, 2, 0.182485070) tdSql.checkData(1, 2, 0.172791608) tdSql.checkData(4, 2, None) - tdSql.query("select c1,c2, log(c2,c1) from ct1") + tdSql.query("select c1,c2, log(c2,c1) from ct1") tdSql.checkData(0, 2, 5.479900349) tdSql.checkData(1, 2, 5.787318105) tdSql.checkData(4, 2, None) - tdSql.query("select c1, log(2.0 , c1) from ct1") + tdSql.query("select c1, log(2.0 , c1) from ct1") tdSql.checkData(0, 1, 0.333333333) tdSql.checkData(1, 1, 0.356207187) tdSql.checkData(4, 1, None) - tdSql.query("select c1, log(2.0 , ceil(abs(c1))) from ct1") + tdSql.query("select c1, log(2.0 , ceil(abs(c1))) from ct1") tdSql.checkData(0, 1, 0.333333333) tdSql.checkData(1, 1, 0.356207187) tdSql.checkData(4, 1, None) @@ -580,10 +580,10 @@ class TDTestCase: tdSql.checkData(0,3,8.000000000) tdSql.checkData(0,4,7.900000000) tdSql.checkData(0,5,3.000000000) - + def log_Arithmetic(self): pass - + def check_boundary_values(self): tdSql.execute("drop database if exists bound_test") @@ -612,13 +612,13 @@ class TDTestCase: self.check_result_auto_log( "select c1, c2, c3 , c4, c5 ,c6 from sub1_bound ", "select log(c1), log(c2) ,log(c3), log(c4), log(c5) ,log(c6) from sub1_bound") self.check_result_auto_log2( "select c1, c2, c3 , c4, c5 ,c6 from sub1_bound ", "select log(c1,2), log(c2,2) ,log(c3,2), log(c4,2), log(c5,2) ,log(c6,2) from sub1_bound") self.check_result_auto_log__10( "select c1, c2, c3 , c4, c5 ,c6 from sub1_bound ", "select log(c1,-10), log(c2,-10) ,log(c3,-10), log(c4,-10), log(c5,-10) ,log(c6,-10) from sub1_bound") - + self.check_result_auto_log2( "select c1, c2, c3 , c3, c2 ,c1 from sub1_bound ", "select log(c1,2), log(c2,2) ,log(c3,2), log(c3,2), log(c2,2) ,log(c1,2) from sub1_bound") self.check_result_auto_log( "select c1, c2, c3 , c3, c2 ,c1 from sub1_bound ", "select log(c1), log(c2) ,log(c3), log(c3), log(c2) ,log(c1) from sub1_bound") self.check_result_auto_log2("select abs(abs(abs(abs(abs(abs(abs(abs(abs(c1))))))))) nest_col_func from sub1_bound" , "select log(abs(c1) ,2) from sub1_bound" ) - + # check basic elem for table per row tdSql.query("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 sub1_bound ") tdSql.checkData(0,0,math.log(2147483647,2)) @@ -683,45 +683,45 @@ class TDTestCase: self.check_result_auto_log2( " select t1,c5 from stb1 where c1 > 0 order by tbname " , "select log(t1,2) ,log(c5,2) from stb1 where c1 > 0 order by tbname" ) self.check_result_auto_log2( " select t1,c5 from stb1 where c1 > 0 order by tbname " , "select log(t1,2) , log(c5,2) from stb1 where c1 > 0 order by tbname" ) pass - + def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring tdSql.prepare() tdLog.printNoPrefix("==========step1:create table ==============") - + self.prepare_datas() - tdLog.printNoPrefix("==========step2:test errors ==============") + tdLog.printNoPrefix("==========step2:test errors ==============") self.test_errors() - - tdLog.printNoPrefix("==========step3:support types ============") + + tdLog.printNoPrefix("==========step3:support types ============") self.support_types() - tdLog.printNoPrefix("==========step4: log basic query ============") + tdLog.printNoPrefix("==========step4: log basic query ============") self.basic_log_function() - tdLog.printNoPrefix("==========step5: big number log query ============") + tdLog.printNoPrefix("==========step5: big number log query ============") self.test_big_number() - tdLog.printNoPrefix("==========step6: base number for log query ============") + tdLog.printNoPrefix("==========step6: base number for log query ============") self.log_base_test() - tdLog.printNoPrefix("==========step7: log boundary query ============") + tdLog.printNoPrefix("==========step7: log boundary query ============") self.check_boundary_values() - tdLog.printNoPrefix("==========step8: log filter query ============") + tdLog.printNoPrefix("==========step8: log filter query ============") self.abs_func_filter() tdLog.printNoPrefix("==========step9: check log result of stable query ============") - self.support_super_table_test() + self.support_super_table_test() def stop(self): tdSql.close() diff --git a/tests/system-test/2-query/query_cols_tags_and_or.py b/tests/system-test/2-query/query_cols_tags_and_or.py index c9df6f61bb..e0fb986d79 100644 --- a/tests/system-test/2-query/query_cols_tags_and_or.py +++ b/tests/system-test/2-query/query_cols_tags_and_or.py @@ -50,7 +50,7 @@ class TDTestCase: tb_name = tdCom.getLongName(8, "letters") tdSql.execute( f"CREATE TABLE {tb_name} (ts timestamp, c1 tinyint, c2 smallint, c3 int, c4 bigint, c5 float, c6 double, c7 binary(100), c8 nchar(200), c9 bool, c10 tinyint unsigned, c11 smallint unsigned, c12 int unsigned, c13 bigint unsigned) tags (t1 tinyint, t2 smallint, t3 int, t4 bigint, t5 float, t6 double, t7 binary(100), t8 nchar(200), t9 bool, t10 tinyint unsigned, t11 smallint unsigned, t12 int unsigned, t13 bigint unsigned)") - for i in range(1, count+1): + for i in range(1, count+1): tdSql.execute( f'CREATE TABLE {tb_name}_sub_{i} using {tb_name} tags ({i}, {i}, {i}, {i}, {i}.{i}, {i}.{i}, "binary{i}", "nchar{i}", true, {i}, {i}, {i}, {i})') self.insertData(f'{tb_name}_sub_{i}') @@ -412,7 +412,7 @@ class TDTestCase: query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c1 > 2 and c1 >= 3 or c1 < 1 or c1 <= 0 or c1 =2 or c1 != 1 or c1 <> 1 and c1 is null or c1 between 2 and 3 and c1 not between 1 and 1 and c1 in (2, 3) and c1 not in (1, 2)' res = tdSql.query(query_sql) tdSql.checkRows(1) - + def queryUtinyintCol(self, tb_name, check_elm=None): select_elm = "*" if check_elm is None else check_elm # > @@ -497,7 +497,7 @@ class TDTestCase: query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c10 > 2 and c10 >= 3 or c10 < 1 or c10 <= 0 or c10 =2 or c10 != 1 or c10 <> 1 and c10 is null or c10 between 2 and 3 and c10 not between 1 and 1 and c10 in (2, 3) and c10 not in (1, 2)' res = tdSql.query(query_sql) tdSql.checkRows(10) - + def querySmallintCol(self, tb_name, check_elm=None): select_elm = "*" if check_elm is None else check_elm # > @@ -582,7 +582,7 @@ class TDTestCase: query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c2 > 0 and c2 >= 1 or c2 < 4 and c2 <= 3 and c2 != 1 and c2 <> 2 and c2 = 3 or c2 is not null and c2 between 2 and 3 and c2 not between 1 and 2 and c2 in (2,3) and c2 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(11) - + def queryUsmallintCol(self, tb_name, check_elm=None): select_elm = "*" if check_elm is None else check_elm # > @@ -752,7 +752,7 @@ class TDTestCase: query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c3 > 0 and c3 >= 1 or c3 < 5 and c3 <= 4 and c3 != 2 and c3 <> 2 and c3 = 4 or c3 is not null and c3 between 2 and 4 and c3 not between 1 and 2 and c3 in (2,4) and c3 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(11) - + def queryUintCol(self, tb_name, check_elm=None): select_elm = "*" if check_elm is None else check_elm # > @@ -1086,7 +1086,7 @@ class TDTestCase: query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c5 > 0 and c5 >= 1 or c5 < 5 and c5 <= 6.6 and c5 != 2 and c5 <> 2 and c5 = 4 or c5 is not null and c5 between 2 and 4 and c5 not between 1 and 2 and c5 in (2,4) and c5 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(11) - + def queryDoubleCol(self, tb_name, check_elm=None): select_elm = "*" if check_elm is None else check_elm # > @@ -1711,19 +1711,19 @@ class TDTestCase: tdSql.checkRows(4) tdSql.checkEqual(self.queryLastC10(query_sql), 7) - ## condition_A or (condition_B and condition_C) or (condition_D and condition_E) and condition_F + ## condition_A or (condition_B and condition_C) or (condition_D and condition_E) and condition_F query_sql = f'select * from {tb_name} where c1 != 1 or (c2 <= 1 and c3 <4) or (c3 >= 4 or c7 is not Null) and c9 <> true' tdSql.query(query_sql) tdSql.checkRows(3) tdSql.checkEqual(self.queryLastC10(query_sql), 10) - ## (condition_A or (condition_B and condition_C) or (condition_D and condition_E)) and condition_F + ## (condition_A or (condition_B and condition_C) or (condition_D and condition_E)) and condition_F query_sql = f'select * from {tb_name} where (c1 != 1 or (c2 <= 2 and c3 >= 4) or (c3 >= 4 or c7 is not Null)) and c9 != false' tdSql.query(query_sql) tdSql.checkRows(9) tdSql.checkEqual(self.queryLastC10(query_sql), 9) - ## (condition_A or condition_B) or (condition_C or condition_D) and (condition_E or condition_F or condition_G) + ## (condition_A or condition_B) or (condition_C or condition_D) and (condition_E or condition_F or condition_G) query_sql = f'select * from {tb_name} where c1 != 1 or (c2 <= 3 and c3 > 4) and c3 <= 5 and (c7 is not Null and c9 != false)' tdSql.query(query_sql) tdSql.checkRows(2) @@ -1780,17 +1780,17 @@ class TDTestCase: tdSql.query(query_sql) tdSql.checkRows(55) - ## condition_A or (condition_B and condition_C) or (condition_D and condition_E) and condition_F + ## condition_A or (condition_B and condition_C) or (condition_D and condition_E) and condition_F query_sql = f'select * from {tb_name} where t1 != 1 or (t2 <= 1 and t3 <4) or (t3 >= 4 or t7 is not Null) and t9 <> true' tdSql.query(query_sql) tdSql.checkRows(55) - ## (condition_A or (condition_B and condition_C) or (condition_D and condition_E)) and condition_F + ## (condition_A or (condition_B and condition_C) or (condition_D and condition_E)) and condition_F query_sql = f'select * from {tb_name} where (t1 != 1 or (t2 <= 2 and t3 >= 4) or (t3 >= 4 or t7 is not Null)) and t9 != false' tdSql.query(query_sql) tdSql.checkRows(55) - ## (condition_A or condition_B) or (condition_C or condition_D) and (condition_E or condition_F or condition_G) + ## (condition_A or condition_B) or (condition_C or condition_D) and (condition_E or condition_F or condition_G) query_sql = f'select * from {tb_name} where t1 != 1 or (t2 <= 3 and t3 > 4) and t3 <= 5 and (t7 is not Null and t9 != false)' tdSql.query(query_sql) tdSql.checkRows(44) @@ -2033,7 +2033,7 @@ class TDTestCase: self.checkColType(tb_name, check_elm) else: self.checkColType(stb_name, check_elm) - + def checkStbTagTypeOperator(self): ''' Super table full tag type and operator @@ -2089,7 +2089,7 @@ class TDTestCase: tb_name = self.initStb() self.queryColPreCal(f'{tb_name}_sub_1') self.queryTagPreCal(tb_name) - + def checkMultiTb(self): ''' test "or" in multi ordinary table @@ -2110,7 +2110,7 @@ class TDTestCase: ''' tb_name = self.initStb() self.queryMultiTbWithTag(tb_name) - + def checkMultiStbJoin(self): ''' join test -- GitLab