From 6297055fb52118bfe25d6ff6098cd0e27d817531 Mon Sep 17 00:00:00 2001 From: jiacy-jcy Date: Fri, 17 Jun 2022 15:28:07 +0800 Subject: [PATCH] update test case --- tests/system-test/2-query/first.py | 71 ++++++++++++++++------ tests/system-test/2-query/hyperloglog.py | 77 ++++++++++++++++++++++++ 2 files changed, 128 insertions(+), 20 deletions(-) diff --git a/tests/system-test/2-query/first.py b/tests/system-test/2-query/first.py index 0fdd683f67..25d561aa6b 100644 --- a/tests/system-test/2-query/first.py +++ b/tests/system-test/2-query/first.py @@ -48,12 +48,26 @@ class TDTestCase: return "".join(random.choices(population, k=length)) def first_check_base(self): tdSql.prepare() - + column_dict = { + 'col1': 'tinyint', + 'col2': 'smallint', + 'col3': 'int', + 'col4': 'bigint', + 'col5': 'tinyint unsigned', + 'col6': 'smallint unsigned', + 'col7': 'int unsigned', + 'col8': 'bigint unsigned', + 'col9': 'float', + 'col10': 'double', + 'col11': 'bool', + 'col12': 'binary(20)', + 'col13': 'nchar(20)' + } tdSql.execute('''create table stb(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 tinyint unsigned, col6 smallint unsigned, col7 int unsigned, col8 bigint unsigned, col9 float, col10 double, col11 bool, col12 binary(20), col13 nchar(20)) tags(loc nchar(20))''') tdSql.execute("create table stb_1 using stb tags('beijing')") tdSql.execute("insert into stb_1(ts) values(%d)" % (self.ts - 1)) - + column_list = ['col1','col2','col3','col4','col5','col6','col7','col8','col9','col10','col11','col12','col13'] for i in ['stb_1','db.stb_1','stb_1','db.stb_1']: tdSql.query(f"select first(*) from {i}") tdSql.checkRows(1) @@ -63,31 +77,32 @@ class TDTestCase: # tdSql.query(f"select first(*) from {i}") # tdSql.checkRows(1) # tdSql.checkData(0, 1, None) - for i in range(1, 14): + for i in column_list: for j in ['stb_1','db.stb_1','stb_1','db.stb_1']: - tdSql.query(f"select first(col{i}) from {j}") + tdSql.query(f"select first({i}) from {j}") tdSql.checkRows(0) for i in range(self.rowNum): tdSql.execute(f"insert into stb_1 values(%d, %d, %d, %d, %d, %d, %d, %d, %d, %f, %f, %d, '{self.binary_str}%d', '{self.nchar_str}%d')" % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1)) - for i in range(1, 14): + for k, v in column_dict.items(): for j in ['stb_1', 'db.stb_1', 'stb', 'db.stb']: - tdSql.query(f"select first(col{i}) from {j}") + tdSql.query(f"select first({k}) from {j}") tdSql.checkRows(1) # tinyint,smallint,int,bigint,tinyint unsigned,smallint unsigned,int unsigned,bigint unsigned - if i >=1 and i<9: + if v == 'tinyint' or v == 'smallint' or v == 'int' or v == 'bigint' or v == 'tinyint unsigned' or v == 'smallint unsigned'\ + or v == 'int unsigned' or v == 'bigint unsigned': tdSql.checkData(0, 0, 1) # float,double - elif i>=9 and i<11: + elif v == 'float' or v == 'double': tdSql.checkData(0, 0, 0.1) # bool - elif i == 11: + elif v == 'bool': tdSql.checkData(0, 0, False) # binary - elif i == 12: + elif 'binary' in v: tdSql.checkData(0, 0, f'{self.binary_str}1') # nchar - elif i == 13: + elif 'nchar' in v: tdSql.checkData(0, 0, f'{self.nchar_str}1') #!bug TD-16569 tdSql.query("select first(*),last(*) from stb where ts < 23 interval(1s)") @@ -98,6 +113,21 @@ class TDTestCase: dbname = self.get_long_name(length=10, mode="letters") stbname = self.get_long_name(length=5, mode="letters") child_table_num = 20 + column_dict = { + 'col1': 'tinyint', + 'col2': 'smallint', + 'col3': 'int', + 'col4': 'bigint', + 'col5': 'tinyint unsigned', + 'col6': 'smallint unsigned', + 'col7': 'int unsigned', + 'col8': 'bigint unsigned', + 'col9': 'float', + 'col10': 'double', + 'col11': 'bool', + 'col12': 'binary(20)', + 'col13': 'nchar(20)' + } tdSql.execute(f"create database if not exists {dbname} vgroups 4") tdSql.execute(f'use {dbname}') # build 20 child tables,every table insert 10 rows @@ -131,28 +161,29 @@ class TDTestCase: tdSql.execute(f"insert into {stbname}_{i} values(%d, %d, %d, %d, %d, %d, %d, %d, %d, %f, %f, %d, '{self.binary_str}%d', '{self.nchar_str}%d')" % (self.ts + j + i, j + 1, j + 1, j + 1, j + 1, j + 1, j + 1, j + 1, j + 1, j + 0.1, j + 0.1, j % 2, j + 1, j + 1)) - for i in range(1, 14): + for k, v in column_dict.items(): for j in [f'{stbname}_{i}', f'{dbname}.{stbname}_{i}', f'{stbname}', f'{dbname}.{stbname}']: - tdSql.query(f"select first(col{i}) from {j}") + tdSql.query(f"select first({k}) from {j}") tdSql.checkRows(1) # tinyint,smallint,int,bigint,tinyint unsigned,smallint unsigned,int unsigned,bigint unsigned - if i >=1 and i<9: + if v == 'tinyint' or v == 'smallint' or v == 'int' or v == 'bigint' or v == 'tinyint unsigned' or v == 'smallint unsigned'\ + or v == 'int unsigned' or v == 'bigint unsigned': tdSql.checkData(0, 0, 1) # float,double - elif i>=9 and i<11: + elif v == 'float' or v == 'double': tdSql.checkData(0, 0, 0.1) # bool - elif i == 11: + elif v == 'bool': tdSql.checkData(0, 0, False) # binary - elif i == 12: + elif 'binary' in v: tdSql.checkData(0, 0, f'{self.binary_str}1') # nchar - elif i == 13: + elif 'nchar' in v: tdSql.checkData(0, 0, f'{self.nchar_str}1') #!bug TD-16569 - tdSql.query(f"select first(*),last(*) from {stbname} where ts < 23 interval(1s)") - tdSql.checkRows(0) + # tdSql.query(f"select first(*),last(*) from {stbname} where ts < 23 interval(1s)") + # tdSql.checkRows(0) tdSql.execute(f'drop database {dbname}') diff --git a/tests/system-test/2-query/hyperloglog.py b/tests/system-test/2-query/hyperloglog.py index 337db140a1..920252573b 100644 --- a/tests/system-test/2-query/hyperloglog.py +++ b/tests/system-test/2-query/hyperloglog.py @@ -214,6 +214,79 @@ class TDTestCase: for i in range(4): tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2} + def __create_stable(self,stbname='stb',column_dict={'ts':'timestamp','col1': 'tinyint','col2': 'smallint','col3': 'int', + 'col4': 'bigint','col5': 'tinyint unsigned','col6': 'smallint unsigned','col7': 'int unsigned', + 'col8': 'bigint unsigned','col9': 'float','col10': 'double','col11': 'bool','col12': 'binary(20)','col13': 'nchar(20)'}, + tag_dict={'ts_tag':'timestamp','t1': 'tinyint','t2': 'smallint','t3': 'int', + 't4': 'bigint','t5': 'tinyint unsigned','t6': 'smallint unsigned','t7': 'int unsigned', + 't8': 'bigint unsigned','t9': 'float','t10': 'double','t11': 'bool','t12': 'binary(20)','t13': 'nchar(20)'}): + column_sql = '' + tag_sql = '' + for k,v in column_dict.items(): + column_sql += f"{k} {v}," + for k,v in tag_dict.items(): + tag_sql += f"{k} {v}," + tdSql.execute(f'create table is not exists {stbname} ({column_sql[:-1]}) tags({tag_sql[:-1]})') + + def __insert_data(self): + + pass + + def __hyperloglog_check_distribute(self): + dbname = "dbtest" + stbname = "stb" + childtable_num = 20 + vgroups_num = 4 + row_num = 10 + ts = 1537146000000 + binary_str = 'taosdata' + nchar_str = '涛思数据' + column_dict = { + 'ts':'timestamp', + 'col1': 'tinyint', + 'col2': 'smallint', + 'col3': 'int', + 'col4': 'bigint', + 'col5': 'tinyint unsigned', + 'col6': 'smallint unsigned', + 'col7': 'int unsigned', + 'col8': 'bigint unsigned', + 'col9': 'float', + 'col10': 'double', + 'col11': 'bool', + 'col12': 'binary(20)', + 'col13': 'nchar(20)' + } + tag_dict = { + 'loc':'nchar(20)' + } + tdSql.execute(f"create database if not exists {dbname} vgroups {vgroups_num}") + tdSql.execute(f'use {dbname}') + self.__create_stable(stbname,column_dict,tag_dict) + for i in range(childtable_num): + tdSql.execute(f"create table {stbname}_{i} using {stbname} tags('beijing')") + tdSql.query('show tables') + vgroup_list = [] + for i in range(len(tdSql.queryResult)): + vgroup_list.append(tdSql.queryResult[i][6]) + vgroup_list_set = set(vgroup_list) + for i in vgroup_list_set: + vgroups_num = vgroup_list.count(i) + if vgroups_num >=2: + tdLog.info(f'This scene with {vgroups_num} vgroups is ok!') + continue + else: + tdLog.exit('This scene does not meet the requirements with {vgroups_num} vgroup!\n') + for i in range(row_num): + tdSql.execute(f"insert into stb_1 values(%d, %d, %d, %d, %d, %d, %d, %d, %d, %f, %f, %d, '{binary_str}%d', '{nchar_str}%d')" + % (ts + i, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1)) + for k in column_dict.keys(): + tdSql.query(f"select hyperloglog({k}) from {stbname}") + tdSql.checkRows(1) + tdSql.query(f"select hyperloglog({k}) from {stbname} group by {k}") + + tdSql.execute(f'drop database {dbname}') + def __insert_data(self, rows): now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) @@ -311,6 +384,10 @@ class TDTestCase: tdLog.printNoPrefix("==========step4:after wal, all check again ") self.all_test() + tdLog.printNoPrefix("==========step5: distribute scene check") + self.__hyperloglog_check_distribute() + + def stop(self): tdSql.close() tdLog.success(f"{__file__} successfully executed") -- GitLab