From 8152a7690c0fe8ee7e8b94bc331778460f8af734 Mon Sep 17 00:00:00 2001 From: jiacy-jcy Date: Wed, 10 Aug 2022 15:04:40 +0800 Subject: [PATCH 1/5] update test case --- tests/system-test/2-query/Today.py | 23 +++++++++++---------- tests/system-test/2-query/top.py | 33 +++++++++++++++--------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/tests/system-test/2-query/Today.py b/tests/system-test/2-query/Today.py index 43c5263af6..6887e73970 100644 --- a/tests/system-test/2-query/Today.py +++ b/tests/system-test/2-query/Today.py @@ -20,8 +20,9 @@ class TDTestCase: self.arithmetic_operators = ['+','-','*','/'] self.relational_operator = ['<','<=','=','>=','>'] # prepare data - self.ntbname = 'ntb' - self.stbname = 'stb' + self.dbname = 'db' + self.ntbname = f'{self.dbname}.ntb' + self.stbname = f'{self.dbname}.stb' self.column_dict = { 'ts':'timestamp', 'c1':'int', @@ -96,7 +97,7 @@ class TDTestCase: tdSql.checkRows(num_same*tb_num) elif tb == 'stb': tdSql.checkRows(num_same) - for i in [f'{tbname}',f'db.{tbname}']: + for i in [f'{tbname}']: for unit in self.time_unit: for symbol in ['+','-']: tdSql.query(f"select today() {symbol}1{unit} from {i}") @@ -148,20 +149,20 @@ class TDTestCase: tdSql.checkData(i, 0, str(self.today_date)) def today_check_ntb(self): for time_unit in self.db_percision: - print(time_unit) - tdSql.execute(f'create database db precision "{time_unit}"') - tdSql.execute('use db') + + tdSql.execute(f'create database {self.dbname} precision "{time_unit}"') + tdSql.execute(f'use {self.dbname}') tdSql.execute(self.set_create_normaltable_sql(self.ntbname,self.column_dict)) for i in self.values_list: tdSql.execute( f'insert into {self.ntbname} values({i})') self.data_check(self.column_dict,self.ntbname,self.values_list,1,'tb',time_unit) - tdSql.execute('drop database db') + tdSql.execute(f'drop database {self.dbname}') def today_check_stb_tb(self): for time_unit in self.db_percision: - print(time_unit) - tdSql.execute(f'create database db precision "{time_unit}"') - tdSql.execute('use db') + + tdSql.execute(f'create database {self.dbname} precision "{time_unit}"') + tdSql.execute(f'use {self.dbname}') tdSql.execute(self.set_create_stable_sql(self.stbname,self.column_dict,self.tag_dict)) for i in range(self.tbnum): tdSql.execute(f'create table if not exists {self.stbname}_{i} using {self.stbname} tags({self.tag_values[i]})') @@ -172,7 +173,7 @@ class TDTestCase: self.data_check(self.column_dict,f'{self.stbname}_{i}',self.values_list,1,'tb',time_unit) # check stable self.data_check(self.column_dict,self.stbname,self.values_list,self.tbnum,'stb',time_unit) - tdSql.execute('drop database db') + tdSql.execute(f'drop database {self.dbname}') def run(self): # sourcery skip: extract-duplicate-method diff --git a/tests/system-test/2-query/top.py b/tests/system-test/2-query/top.py index a7a433a897..41d6f32cfd 100644 --- a/tests/system-test/2-query/top.py +++ b/tests/system-test/2-query/top.py @@ -23,7 +23,9 @@ class TDTestCase: tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) self.setsql = TDSetSql() - self.ntbname = 'ntb' + self.dbname = 'db' + self.stbname = f'{self.dbname}.stb' + self.ntbname = f'{self.dbname}.ntb' self.rowNum = 10 self.tbnum = 20 self.ts = 1537146000000 @@ -96,52 +98,49 @@ class TDTestCase: else: tdSql.checkRows(2*self.tbnum) def top_check_stb(self): - dbname = tdCom.getLongName(10, "letters") - stbname = tdCom.getLongName(5, "letters") + tag_dict = { 't0':'int' } tag_values = [ f'1' ] - tdSql.execute(f"create database if not exists {dbname} vgroups 2") - tdSql.execute(f'use {dbname}') - tdSql.execute(self.setsql.set_create_stable_sql(stbname,self.column_dict,tag_dict)) + tdSql.execute(f"create database if not exists {self.dbname} vgroups 2") + tdSql.execute(f'use {self.dbname}') + tdSql.execute(self.setsql.set_create_stable_sql(self.stbname,self.column_dict,tag_dict)) for i in range(self.tbnum): - tdSql.execute(f"create table {stbname}_{i} using {stbname} tags({tag_values[0]})") - self.insert_data(self.column_dict,f'{stbname}_{i}',self.rowNum) - tdSql.query('show tables') + tdSql.execute(f"create table {self.stbname}_{i} using {self.stbname} tags({tag_values[0]})") + self.insert_data(self.column_dict,f'{self.stbname}_{i}',self.rowNum) + tdSql.query(f'show {self.dbname}.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!') - else: tdLog.exit( 'This scene does not meet the requirements with {vgroups_num} vgroup!\n') for i in range(self.tbnum): - self.top_check_data(f'{stbname}_{i}','child_table') - self.top_check_data(stbname,'stable') - tdSql.execute(f'drop database {dbname}') + self.top_check_data(f'{self.stbname}_{i}','child_table') + self.top_check_data(self.stbname,'stable') + tdSql.execute(f'drop database {self.dbname}') def top_check_ntb(self): - tdSql.prepare() + tdSql.execute(f"create database if not exists {self.dbname}") + tdSql.execute(f'use {self.dbname}') tdSql.execute(self.setsql.set_create_normaltable_sql(self.ntbname,self.column_dict)) self.insert_data(self.column_dict,self.ntbname,self.rowNum) self.top_check_data(self.ntbname,'normal_table') - tdSql.execute('drop database db') + tdSql.execute(f'drop database {self.dbname}') def run(self): self.top_check_ntb() self.top_check_stb() - def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) From 75511b17b1b7cd812e1048df7130efb230447c3c Mon Sep 17 00:00:00 2001 From: jiacy-jcy Date: Wed, 10 Aug 2022 16:10:16 +0800 Subject: [PATCH 2/5] update --- tests/system-test/2-query/To_unixtimestamp.py | 124 +++++++++--------- 1 file changed, 63 insertions(+), 61 deletions(-) diff --git a/tests/system-test/2-query/To_unixtimestamp.py b/tests/system-test/2-query/To_unixtimestamp.py index 60d5cc7b72..64f7b18e41 100644 --- a/tests/system-test/2-query/To_unixtimestamp.py +++ b/tests/system-test/2-query/To_unixtimestamp.py @@ -3,6 +3,7 @@ from time import sleep from util.log import * from util.sql import * from util.cases import * +from util.sqlset import TDSetSql @@ -12,17 +13,19 @@ class TDTestCase: def init(self, conn, logSql): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) + self.setsql = TDSetSql() + self.dbname = 'db' # name of normal table - self.ntbname = 'ntb' + self.ntbname = f'{self.dbname}.ntb' # name of stable - self.stbname = 'stb' + self.stbname = f'{self.dbname}.stb' # structure of column self.column_dict = { 'ts':'timestamp', 'c1':'int', 'c2':'float', - 'c3':'binary(20)', - 'c4':'nchar(20)' + 'c3':'binary(20)' + } # structure of tag self.tag_dict = { @@ -32,69 +35,68 @@ class TDTestCase: self.tbnum = 2 # values of tag,the number of values should equal to tbnum self.tag_values = [ - f'10', - f'100' + '10', + '100' ] # values of rows, structure should be same as column self.values_list = [ - f'now,10,99.99,"2020-1-1 00:00:00"', - f'today(),100,11.111,22.222222' + f'now,10,99.99,"abc"', + f'today(),100,11.111,"abc"' ] - self.error_param = [1,'now()'] - + self.error_param = [1,1.5,'now()'] + def data_check(self,tbname,values_list,tb_type,tb_num=1): + for time in ['1970-01-01T08:00:00+0800','1970-01-01T08:00:00+08:00']: + tdSql.query(f"select to_unixtimestamp('{time}') from {tbname}") + if tb_type == 'ntb' or tb_type == 'ctb': + tdSql.checkRows(len(values_list)) + for i in range(len(values_list)): + tdSql.checkEqual(tdSql.queryResult[i][0],0) + elif tb_type == 'stb': + tdSql.checkRows(len(self.values_list)*tb_num) + for time in ['1900-01-01T08:00:00+08:00']: + tdSql.query(f"select to_unixtimestamp('{time}') from {tbname}") + if tb_type == 'ntb' or tb_type == 'ctb': + tdSql.checkRows(len(values_list)) + elif tb_type == 'stb': + tdSql.checkRows(len(self.values_list)*tb_num) + for time in ['2020-01-32T08:00:00','2020-13-32T08:00:00','acd']: + tdSql.query(f"select to_unixtimestamp('{time}') from {tbname}") + if tb_type == 'ntb' or tb_type == 'ctb': + tdSql.checkRows(len(values_list)) + for i in range(len(values_list)): + tdSql.checkEqual(tdSql.queryResult[i][0],None) + elif tb_type == 'stb': + tdSql.checkRows(len(values_list)*tb_num) + for i in self.column_dict.keys(): + tdSql.query(f"select {i} from {tbname} where to_unixtimestamp('1970-01-01T08:00:00+08:00')=0") + if tb_type == 'ntb' or tb_type == 'ctb': + tdSql.checkRows(len(values_list)) + elif tb_type == 'stb': + tdSql.checkRows(len(values_list)*tb_num) + for time in self.error_param: + tdSql.error(f"select to_unixtimestamp({time}) from {tbname}") + def timestamp_change_check_ntb(self): + tdSql.execute(f'create database {self.dbname}') + tdSql.execute(self.setsql.set_create_normaltable_sql(self.ntbname,self.column_dict)) + for i in range(len(self.values_list)): + tdSql.execute(f'insert into {self.ntbname} values({self.values_list[i]})') + self.data_check(self.ntbname,self.values_list,'ntb') + tdSql.execute(f'drop database {self.dbname}') + def timestamp_change_check_stb(self): + tdSql.execute(f'create database {self.dbname}') + tdSql.execute(self.setsql.set_create_stable_sql(self.stbname,self.column_dict,self.tag_dict)) + for i in range(self.tbnum): + tdSql.execute(f'create table {self.stbname}_{i} using {self.stbname} tags({self.tag_values[i]})') + for j in range(len(self.values_list)): + tdSql.execute(f'insert into {self.stbname}_{i} values({self.values_list[j]})') + for i in range(self.tbnum): + self.data_check(f'{self.stbname}_{i}',self.values_list,'ctb') + self.data_check(self.stbname,self.values_list,'stb',self.tbnum) + tdSql.execute(f'drop database {self.dbname}') def run(self): # sourcery skip: extract-duplicate-method - tdSql.prepare() - tdLog.printNoPrefix("==========step1:create tables==========") - tdSql.execute( - '''create table if not exists ntb - (ts timestamp, c1 int, c2 float,c3 double,c4 timestamp) - ''' - ) - tdSql.execute( - '''create table if not exists stb - (ts timestamp, c1 int, c2 float,c3 double,c4 timestamp) tags(t0 int) - ''' - ) - tdSql.execute( - '''create table if not exists stb_1 using stb tags(100) - ''' - ) - tdLog.printNoPrefix("==========step2:insert data into ntb==========") - - # RFC3339:2020-01-01T00:00:00+8:00 - # ISO8601:2020-01-01T00:00:00.000+0800 - tdSql.execute( - 'insert into ntb values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())') - tdSql.execute( - 'insert into stb_1 values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())') - tdSql.query("select to_unixtimestamp('1970-01-01T08:00:00+0800') from ntb") - tdSql.checkData(0,0,0) - tdSql.checkData(1,0,0) - tdSql.checkData(2,0,0) - tdSql.checkRows(3) - tdSql.query("select to_unixtimestamp('1970-01-01T08:00:00+08:00') from ntb") - tdSql.checkData(0,0,0) - tdSql.checkRows(3) - tdSql.query("select to_unixtimestamp('1900-01-01T08:00:00+08:00') from ntb") - tdSql.checkRows(3) - tdSql.query("select to_unixtimestamp('2020-01-32T08:00:00') from ntb") - tdSql.checkRows(3) - tdSql.checkData(0,0,None) - tdSql.query("select to_unixtimestamp('2020-13-32T08:00:00') from ntb") - tdSql.checkRows(3) - tdSql.checkData(0,0,None) - tdSql.query("select to_unixtimestamp('acd') from ntb") - tdSql.checkRows(3) - tdSql.checkData(0,0,None) - tdSql.error("select to_unixtimestamp(1) from ntb") - tdSql.error("select to_unixtimestamp(1.5) from ntb") - tdSql.error("select to_unixtimestamp(ts) from ntb") - - tdSql.query("select ts from ntb where to_unixtimestamp('1970-01-01T08:00:00+08:00')=0") - tdSql.checkRows(3) - - + self.timestamp_change_check_ntb() + self.timestamp_change_check_stb() def stop(self): tdSql.close() tdLog.success(f"{__file__} successfully executed") From d0126422bc6a3f2b0c77050ae30858555f92557f Mon Sep 17 00:00:00 2001 From: jiacy-jcy Date: Wed, 10 Aug 2022 17:08:27 +0800 Subject: [PATCH 3/5] update test case --- tests/system-test/2-query/Now.py | 19 +- tests/system-test/2-query/Timediff.py | 19 +- tests/system-test/2-query/To_iso8601.py | 20 +- tests/system-test/2-query/last.py | 41 +-- tests/system-test/2-query/percentile.py | 15 +- tests/system-test/2-query/stateduration.py | 407 ++++++++++++--------- tests/system-test/2-query/timetruncate.py | 19 +- tests/system-test/2-query/timezone.py | 10 +- 8 files changed, 310 insertions(+), 240 deletions(-) diff --git a/tests/system-test/2-query/Now.py b/tests/system-test/2-query/Now.py index 386c8b9d31..35291856f2 100644 --- a/tests/system-test/2-query/Now.py +++ b/tests/system-test/2-query/Now.py @@ -9,12 +9,13 @@ class TDTestCase: def init(self, conn, logSql): tdLog.debug(f"start to excute {__file__}") - tdSql.init(conn.cursor(),True) + tdSql.init(conn.cursor()) self.setsql = TDSetSql() + self.dbname = 'db' # name of normal table - self.ntbname = 'ntb' + self.ntbname = f'{self.dbname}.ntb' # name of stable - self.stbname = 'stb' + self.stbname = f'{self.dbname}.stb' # structure of column self.column_dict = { 'ts':'timestamp', @@ -72,19 +73,19 @@ class TDTestCase: def now_check_ntb(self): for time_unit in self.db_percision: - tdSql.execute(f'create database db precision "{time_unit}"') - tdSql.execute('use db') + tdSql.execute(f'create database {self.dbname} precision "{time_unit}"') + tdSql.execute(f'use {self.dbname}') tdSql.execute(self.setsql.set_create_normaltable_sql(self.ntbname,self.column_dict)) for value in self.values_list: tdSql.execute( f'insert into {self.ntbname} values({value})') self.data_check(self.ntbname,'normal table') - tdSql.execute('drop database db') + tdSql.execute(f'drop database {self.dbname}') def now_check_stb(self): for time_unit in self.db_percision: - tdSql.execute(f'create database db precision "{time_unit}"') - tdSql.execute('use db') + tdSql.execute(f'create database {self.dbname} precision "{time_unit}"') + tdSql.execute(f'use {self.dbname}') tdSql.execute(self.setsql.set_create_stable_sql(self.stbname,self.column_dict,self.tag_dict)) for i in range(self.tbnum): tdSql.execute(f"create table {self.stbname}_{i} using {self.stbname} tags({self.tag_values[0]})") @@ -93,7 +94,7 @@ class TDTestCase: for i in range(self.tbnum): self.data_check(f'{self.stbname}_{i}','child table') self.data_check(self.stbname,'stable') - tdSql.execute('drop database db') + tdSql.execute(f'drop database {self.dbname}') def run(self): # sourcery skip: extract-duplicate-method self.now_check_ntb() diff --git a/tests/system-test/2-query/Timediff.py b/tests/system-test/2-query/Timediff.py index 9c595a8c8c..d9bac2e930 100644 --- a/tests/system-test/2-query/Timediff.py +++ b/tests/system-test/2-query/Timediff.py @@ -19,9 +19,10 @@ class TDTestCase: self.db_param_precision = ['ms','us','ns'] self.time_unit = ['1w','1d','1h','1m','1s','1a','1u','1b'] self.error_unit = ['2w','2d','2h','2m','2s','2a','2u','1c','#1'] - self.ntbname = 'ntb' - self.stbname = 'stb' - self.ctbname = 'ctb' + self.dbname = 'db' + self.ntbname = f'{self.dbname}.ntb' + self.stbname = f'{self.dbname}.stb' + self.ctbname = f'{self.dbname}.ctb' self.subtractor = 1 # unit:s def check_tbtype(self,tb_type): if tb_type.lower() == 'ntb': @@ -139,9 +140,9 @@ class TDTestCase: tdSql.error(f'select timediff(c0,{self.subtractor},{unit}) from {self.ntbname}') def function_check_ntb(self): for precision in self.db_param_precision: - tdSql.execute('drop database if exists db') - tdSql.execute(f'create database db precision "{precision}"') - tdSql.execute('use db') + tdSql.execute(f'drop database if exists {self.dbname}') + tdSql.execute(f'create database {self.dbname} precision "{precision}"') + tdSql.execute(f'use {self.dbname}') tdSql.execute(f'create table {self.ntbname} (ts timestamp,c0 int)') for ts in self.ts_str: tdSql.execute(f'insert into {self.ntbname} values("{ts}",1)') @@ -151,9 +152,9 @@ class TDTestCase: self.data_check(date_time,precision,'ntb') def function_check_stb(self): for precision in self.db_param_precision: - tdSql.execute('drop database if exists db') - tdSql.execute(f'create database db precision "{precision}"') - tdSql.execute('use db') + tdSql.execute(f'drop database if exists {self.dbname}') + tdSql.execute(f'create database {self.dbname} precision "{precision}"') + tdSql.execute(f'use {self.dbname}') tdSql.execute(f'create table {self.stbname} (ts timestamp,c0 int) tags(t0 int)') tdSql.execute(f'create table {self.ctbname} using {self.stbname} tags(1)') for ts in self.ts_str: diff --git a/tests/system-test/2-query/To_iso8601.py b/tests/system-test/2-query/To_iso8601.py index a80978bcda..16db0cca59 100644 --- a/tests/system-test/2-query/To_iso8601.py +++ b/tests/system-test/2-query/To_iso8601.py @@ -15,16 +15,18 @@ class TDTestCase: tdSql.init(conn.cursor()) self.rowNum = 10 self.ts = 1640966400000 # 2022-1-1 00:00:00.000 + self.dbname = 'db' + self.stbname = f'{self.dbname}.stb' + self.ntbname = f'{self.dbname}.ntb' def check_customize_param_ms(self): time_zone = time.strftime('%z') - tdSql.execute('create database db1 precision "ms"') - tdSql.execute('use db1') - tdSql.execute('create table if not exists ntb(ts timestamp, c1 int, c2 timestamp)') + tdSql.execute(f'create database {self.dbname} precision "ms"') + tdSql.execute(f'use {self.dbname}') + tdSql.execute(f'create table if not exists {self.ntbname}(ts timestamp, c1 int, c2 timestamp)') for i in range(self.rowNum): - tdSql.execute("insert into ntb values(%d, %d, %d)" - % (self.ts + i, i + 1, self.ts + i)) - tdSql.query('select to_iso8601(ts) from ntb') + tdSql.execute(f"insert into {self.ntbname} values({self.ts + i}, {i + 1}, {self.ts + i})") + tdSql.query(f'select to_iso8601(ts) from {self.ntbname}') for i in range(self.rowNum): tdSql.checkEqual(tdSql.queryResult[i][0],f'2022-01-01T00:00:00.00{i}{time_zone}') @@ -36,17 +38,17 @@ class TDTestCase: '-00:00','-01:00','-02:00','-03:00','-04:00','-05:00','-06:00','-07:00','-08:00','-09:00','-10:00','-11:00','-12:00',\ 'z','Z'] for j in timezone_list: - tdSql.query(f'select to_iso8601(ts,"{j}") from ntb') + tdSql.query(f'select to_iso8601(ts,"{j}") from {self.ntbname}') for i in range(self.rowNum): tdSql.checkEqual(tdSql.queryResult[i][0],f'2022-01-01T00:00:00.00{i}{j}') error_param_list = [0,100.5,'a','!'] for i in error_param_list: - tdSql.error(f'select to_iso8601(ts,"{i}") from ntb') + tdSql.error(f'select to_iso8601(ts,"{i}") from {self.ntbname}') #! bug TD-16372:对于错误的时区,缺少校验 error_timezone_param = ['+13','-13','+1300','-1300','+0001','-0001','-0330','-0530'] for i in error_timezone_param: - tdSql.error(f'select to_iso8601(ts,"{i}") from ntb') + tdSql.error(f'select to_iso8601(ts,"{i}") from {self.ntbname}') def check_base_function(self): tdSql.prepare() diff --git a/tests/system-test/2-query/last.py b/tests/system-test/2-query/last.py index bae77b582c..afc7ed36a5 100644 --- a/tests/system-test/2-query/last.py +++ b/tests/system-test/2-query/last.py @@ -37,7 +37,7 @@ class TDTestCase: def last_check_stb_tb_base(self): tdSql.prepare() - stbname = tdCom.getLongName(5, "letters") + stbname = f'db.{tdCom.getLongName(5, "letters")}' column_dict = { 'col1': 'tinyint', 'col2': 'smallint', @@ -61,7 +61,7 @@ class TDTestCase: tdSql.execute(f"create table {stbname}_1 using {stbname} tags('beijing')") tdSql.execute(f"insert into {stbname}_1(ts) values(%d)" % (self.ts - 1)) - for i in [f'{stbname}_1', f'db.{stbname}_1']: + for i in [f'{stbname}_1']: tdSql.query(f"select last(*) from {i}") tdSql.checkRows(1) tdSql.checkData(0, 1, None) @@ -71,7 +71,7 @@ class TDTestCase: # tdSql.checkRows(1) # tdSql.checkData(0, 1, None) for i in column_dict.keys(): - for j in [f'{stbname}_1', f'db.{stbname}_1', f'{stbname}', f'db.{stbname}']: + for j in [f'{stbname}_1', f'{stbname}']: tdSql.query(f"select last({i}) from {j}") tdSql.checkRows(0) tdSql.query(f"select last({list(column_dict.keys())[0]}) from {stbname}_1 group by {list(column_dict.keys())[-1]}") @@ -79,12 +79,12 @@ class TDTestCase: for i in range(self.rowNum): tdSql.execute(f"insert into {stbname}_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 [f'{stbname}_1', f'db.{stbname}_1', f'{stbname}', f'db.{stbname}']: + for i in [f'{stbname}_1',f'{stbname}']: tdSql.query(f"select last(*) from {i}") tdSql.checkRows(1) tdSql.checkData(0, 1, 10) for k, v in column_dict.items(): - for j in [f'{stbname}_1', f'db.{stbname}_1', f'{stbname}', f'db.{stbname}']: + for j in [f'{stbname}_1', f'{stbname}']: tdSql.query(f"select last({k}) from {j}") tdSql.checkRows(1) # tinyint,smallint,int,bigint,tinyint unsigned,smallint unsigned,int unsigned,bigint unsigned @@ -103,7 +103,7 @@ class TDTestCase: # nchar elif 'nchar' in v.lower(): tdSql.checkData(0, 0, f'{self.nchar_str}{self.rowNum}') - for i in [f'{stbname}_1', f'db.{stbname}_1', f'{stbname}', f'db.{stbname}']: + for i in [f'{stbname}_1', f'{stbname}']: tdSql.query(f"select last({list(column_dict.keys())[0]},{list(column_dict.keys())[1]},{list(column_dict.keys())[2]}) from {stbname}_1") tdSql.checkData(0, 2, 10) @@ -113,7 +113,7 @@ class TDTestCase: def last_check_ntb_base(self): tdSql.prepare() - ntbname = tdCom.getLongName(5, "letters") + ntbname = f'db.{tdCom.getLongName(5, "letters")}' column_dict = { 'col1': 'tinyint', 'col2': 'smallint', @@ -135,11 +135,8 @@ class TDTestCase: tdSql.query(f"select last(*) from {ntbname}") tdSql.checkRows(1) tdSql.checkData(0, 1, None) - tdSql.query(f"select last(*) from db.{ntbname}") - tdSql.checkRows(1) - tdSql.checkData(0, 1, None) for i in column_dict.keys(): - for j in [f'{ntbname}', f'db.{ntbname}']: + for j in [f'{ntbname}']: tdSql.query(f"select last({i}) from {j}") tdSql.checkRows(0) for i in range(self.rowNum): @@ -148,11 +145,8 @@ class TDTestCase: tdSql.query(f"select last(*) from {ntbname}") tdSql.checkRows(1) tdSql.checkData(0, 1, 10) - tdSql.query(f"select last(*) from db.{ntbname}") - tdSql.checkRows(1) - tdSql.checkData(0, 1, 10) for k, v in column_dict.items(): - for j in [f'{ntbname}', f'db.{ntbname}']: + for j in [f'{ntbname}']: tdSql.query(f"select last({k}) from {j}") tdSql.checkRows(1) # tinyint,smallint,int,bigint,tinyint unsigned,smallint unsigned,int unsigned,bigint unsigned @@ -178,8 +172,8 @@ class TDTestCase: def last_check_stb_distribute(self): # prepare data for vgroup 4 dbname = tdCom.getLongName(10, "letters") - stbname = tdCom.getLongName(5, "letters") - vgroup_num = 4 + stbname = f'{dbname}.{tdCom.getLongName(5, "letters")}' + vgroup_num = 2 column_dict = { 'col1': 'tinyint', 'col2': 'smallint', @@ -208,11 +202,7 @@ class TDTestCase: f"create table {stbname}_{i} using {stbname} tags('beijing')") tdSql.execute( f"insert into {stbname}_{i}(ts) values(%d)" % (self.ts - 1-i)) - # for i in [f'{stbname}', f'{dbname}.{stbname}']: - # tdSql.query(f"select last(*) from {i}") - # tdSql.checkRows(1) - # tdSql.checkData(0, 1, None) - tdSql.query('show tables') + tdSql.query(f'show {dbname}.tables') vgroup_list = [] for i in range(len(tdSql.queryResult)): vgroup_list.append(tdSql.queryResult[i][6]) @@ -222,20 +212,17 @@ class TDTestCase: if vgroups_num >= 2: tdLog.info(f'This scene with {vgroups_num} vgroups is ok!') continue - # else: - # tdLog.exit( - # f'This scene does not meet the requirements with {vgroups_num} vgroup!\n') for i in range(self.tbnum): for j in range(self.rowNum): 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 [f'{stbname}', f'{dbname}.{stbname}']: + for i in [f'{stbname}']: tdSql.query(f"select last(*) from {i}") tdSql.checkRows(1) tdSql.checkData(0, 1, 10) for k, v in column_dict.items(): - for j in [f'{stbname}', f'{dbname}.{stbname}']: + for j in [f'{stbname}']: tdSql.query(f"select last({k}) from {j}") tdSql.checkRows(1) # tinyint,smallint,int,bigint,tinyint unsigned,smallint unsigned,int unsigned,bigint unsigned diff --git a/tests/system-test/2-query/percentile.py b/tests/system-test/2-query/percentile.py index 43b5c5610a..3b027ed6a0 100644 --- a/tests/system-test/2-query/percentile.py +++ b/tests/system-test/2-query/percentile.py @@ -23,13 +23,14 @@ from util.sqlset import TDSetSql class TDTestCase: def init(self, conn, logSql): tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(), True) + tdSql.init(conn.cursor()) self.rowNum = 10 self.ts = 1537146000000 self.setsql = TDSetSql() - self.ntbname = 'ntb' - self.stbname = 'stb' + self.dbname = 'db' + self.ntbname = f'{self.dbname}.ntb' + self.stbname = f'{self.dbname}.stb' self.binary_length = 20 # the length of binary for column_dict self.nchar_length = 20 # the length of nchar for column_dict self.column_dict = { @@ -100,10 +101,9 @@ class TDTestCase: return intData,floatData def check_tags(self,tags,param,num,value): tdSql.query(f'select percentile({tags}, {param}) from {self.stbname}_{num}') - print(tdSql.queryResult) tdSql.checkEqual(tdSql.queryResult[0][0], value) def function_check_ntb(self): - tdSql.prepare() + tdSql.execute(f'create database {self.dbname}') tdSql.execute(self.setsql.set_create_normaltable_sql(self.ntbname,self.column_dict)) intData,floatData = self.insert_data(self.column_dict,self.ntbname,self.rowNum) for k,v in self.column_dict.items(): @@ -116,8 +116,9 @@ class TDTestCase: else: tdSql.query(f'select percentile({k}, {param}) from {self.ntbname}') tdSql.checkData(0, 0, np.percentile(floatData, param)) + tdSql.execute(f'drop database {self.dbname}') def function_check_ctb(self): - tdSql.prepare() + tdSql.execute(f'create database {self.dbname}') tdSql.execute(self.setsql.set_create_stable_sql(self.stbname,self.column_dict,self.tag_dict)) for i in range(self.tbnum): tdSql.execute(f"create table {self.stbname}_{i} using {self.stbname} tags({self.tag_values[0]})") @@ -143,7 +144,7 @@ class TDTestCase: data_num = tdSql.queryResult[0][0] tdSql.query(f'select percentile({k},{param}) from {self.stbname}_{i}') tdSql.checkData(0,0,data_num) - + tdSql.execute(f'drop database {self.dbname}') def run(self): self.function_check_ntb() self.function_check_ctb() diff --git a/tests/system-test/2-query/stateduration.py b/tests/system-test/2-query/stateduration.py index 6b50446814..b6ddff4017 100644 --- a/tests/system-test/2-query/stateduration.py +++ b/tests/system-test/2-query/stateduration.py @@ -15,251 +15,328 @@ from util.log import * from util.cases import * from util.sql import * + class TDTestCase: def init(self, conn, logSql): tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) self.ts = 1537146000000 - self.param_list = ['LT','lt','Lt','lT','GT','gt','Gt','gT','LE','le','Le','lE','GE','ge','Ge','gE','NE','ne','Ne','nE','EQ','eq','Eq','eQ'] + self.param_list = ['LT', 'lt', 'Lt', 'lT', 'GT', 'gt', 'Gt', 'gT', 'LE', 'le', 'Le', + 'lE', 'GE', 'ge', 'Ge', 'gE', 'NE', 'ne', 'Ne', 'nE', 'EQ', 'eq', 'Eq', 'eQ'] self.row_num = 10 - def run(self): - tdSql.prepare() + self.dbname = 'db' + self.ntbname = f'{self.dbname}.ntb' + self.stbname = f'{self.dbname}.stb' + + def duration_check(self): + tdSql.execute(f'create database {self.dbname}') # timestamp = 1ms , time_unit = 1s - tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + tdSql.execute(f'''create table {self.ntbname}(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, col7 bool, col8 binary(20), col9 nchar(20), col11 tinyint unsigned, col12 smallint unsigned, col13 int unsigned, col14 bigint unsigned)''') for i in range(self.row_num): - tdSql.execute("insert into test values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)" - % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1)) - integer_list = [1,2,3,4,11,12,13,14] - float_list = [5,6] + tdSql.execute(f"insert into {self.ntbname} values({self.ts + i}, {i + 1}, {i + 1}, {i + 1}, {i + 1}, {i + 0.1}, {i + 0.1}, {i % 2}, 'taosdata{i + 1}', '涛思数据{i + 1}', {i + 1}, {i + 1}, {i + 1}, {i + 1})" + ) + integer_list = [1, 2, 3, 4, 11, 12, 13, 14] + float_list = [5, 6] for i in integer_list: for j in self.param_list: - tdSql.query(f"select stateduration(col{i},'{j}',5) from test") + tdSql.query( + f"select stateduration(col{i},'{j}',5) from {self.ntbname}") tdSql.checkRows(10) - if j in ['LT' ,'lt','Lt','lT']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (1,), (2,), (3,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,)]) - elif j in ['GT','gt', 'Gt','gT']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (-1,), (0,), (1,), (2,), (3,), (4,)]) - elif j in ['LE','le','Le','lE']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (1,), (2,), (3,), (4,), (-1,), (-1,), (-1,), (-1,), (-1,)]) - elif j in [ 'GE','ge','Ge','gE']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (0,), (1,), (2,), (3,), (4,), (5,)]) - elif j in ['NE','ne','Ne','nE']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (1,), (2,), (3,), (-1,), (0,), (1,), (2,), (3,), (4,)]) - elif j in ['EQ','eq','Eq','eQ']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (0,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + if j in ['LT', 'lt', 'Lt', 'lT']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (1,), (2,), (3,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + elif j in ['GT', 'gt', 'Gt', 'gT']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (-1,), (0,), (1,), (2,), (3,), (4,)]) + elif j in ['LE', 'le', 'Le', 'lE']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (1,), (2,), (3,), (4,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + elif j in ['GE', 'ge', 'Ge', 'gE']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (0,), (1,), (2,), (3,), (4,), (5,)]) + elif j in ['NE', 'ne', 'Ne', 'nE']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (1,), (2,), (3,), (-1,), (0,), (1,), (2,), (3,), (4,)]) + elif j in ['EQ', 'eq', 'Eq', 'eQ']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (0,), (-1,), (-1,), (-1,), (-1,), (-1,)]) for i in float_list: for j in self.param_list: - tdSql.query(f"select stateduration(col{i},'{j}',5) from test") + tdSql.query( + f"select stateduration(col{i},'{j}',5) from {self.ntbname}") tdSql.checkRows(10) - if j in ['LT','lt','Lt','lT','LE','le','Le','lE']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (1,), (2,), (3,), (4,), (-1,), (-1,), (-1,), (-1,), (-1,)]) - elif j in ['GE','ge','Ge','gE','GT','gt','Gt','gT']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (-1,), (0,), (1,), (2,), (3,), (4,)]) - elif j in ['NE','ne','Ne','nE']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (1,), (2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,)]) - elif j in ['EQ','eq','Eq','eQ']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + if j in ['LT', 'lt', 'Lt', 'lT', 'LE', 'le', 'Le', 'lE']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (1,), (2,), (3,), (4,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + elif j in ['GE', 'ge', 'Ge', 'gE', 'GT', 'gt', 'Gt', 'gT']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (-1,), (0,), (1,), (2,), (3,), (4,)]) + elif j in ['NE', 'ne', 'Ne', 'nE']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (1,), (2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,)]) + elif j in ['EQ', 'eq', 'Eq', 'eQ']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,)]) - error_column_list = ['ts','col7','col8','col9','a',1] + error_column_list = ['ts', 'col7', 'col8', 'col9', 'a', 1] for i in error_column_list: for j in self.param_list: - tdSql.error(f"select stateduration({i},{j},5) from test") + tdSql.error( + f"select stateduration({i},{j},5) from {self.ntbname}") - error_param_list = ['a',1] + error_param_list = ['a', 1] for i in error_param_list: - tdSql.error(f"select stateduration(col1,{i},5) from test") - + tdSql.error( + f"select stateduration(col1,{i},5) from {self.ntbname}") + tdSql.execute(f'drop table {self.ntbname}') # timestamp = 1s, time_unit =1s - tdSql.execute('''create table test1(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + tdSql.execute(f'''create table {self.ntbname}(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, col7 bool, col8 binary(20), col9 nchar(20), col11 tinyint unsigned, col12 smallint unsigned, col13 int unsigned, col14 bigint unsigned)''') for i in range(self.row_num): - tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)" - % (self.ts + i*1000, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1)) + tdSql.execute(f"insert into {self.ntbname} values({self.ts + i*1000}, {i + 1}, {i + 1}, {i + 1}, {i + 1}, {i + 0.1}, {i + 0.1}, {i % 2}, 'taosdata{i + 1}', '涛思数据{i + 1}', {i + 1}, {i + 1}, {i + 1}, {i + 1})" + ) for i in integer_list: for j in self.param_list: - tdSql.query(f"select stateduration(col{i},'{j}',5) from test1") + tdSql.query(f"select stateduration(col{i},'{j}',5) from {self.ntbname}") tdSql.checkRows(10) - # print(tdSql.queryResult) - if j in ['LT' ,'lt','Lt','lT']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (1000,), (2000,), (3000,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,)]) - elif j in ['GT','gt', 'Gt','gT']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (-1,), (0,), (1000,), (2000,), (3000,), (4000,)]) - elif j in ['LE','le','Le','lE']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (1000,), (2000,), (3000,), (4000,), (-1,), (-1,), (-1,), (-1,), (-1,)]) - elif j in [ 'GE','ge','Ge','gE']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (0,), (1000,), (2000,), (3000,), (4000,), (5000,)]) - elif j in ['NE','ne','Ne','nE']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (1000,), (2000,), (3000,), (-1,), (0,), (1000,), (2000,), (3000,), (4000,)]) - elif j in ['EQ','eq','Eq','eQ']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (0,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + if j in ['LT', 'lt', 'Lt', 'lT']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (1000,), (2000,), (3000,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + elif j in ['GT', 'gt', 'Gt', 'gT']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (-1,), (0,), (1000,), (2000,), (3000,), (4000,)]) + elif j in ['LE', 'le', 'Le', 'lE']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (1000,), (2000,), (3000,), (4000,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + elif j in ['GE', 'ge', 'Ge', 'gE']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (0,), (1000,), (2000,), (3000,), (4000,), (5000,)]) + elif j in ['NE', 'ne', 'Ne', 'nE']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (1000,), (2000,), (3000,), (-1,), (0,), (1000,), (2000,), (3000,), (4000,)]) + elif j in ['EQ', 'eq', 'Eq', 'eQ']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (0,), (-1,), (-1,), (-1,), (-1,), (-1,)]) for i in float_list: for j in self.param_list: - tdSql.query(f"select stateduration(col{i},'{j}',5) from test1") + tdSql.query(f"select stateduration(col{i},'{j}',5) from {self.ntbname}") tdSql.checkRows(10) print(tdSql.queryResult) - if j in ['LT','lt','Lt','lT','LE','le','Le','lE']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (1000,), (2000,), (3000,), (4000,), (-1,), (-1,), (-1,), (-1,), (-1,)]) - elif j in ['GE','ge','Ge','gE','GT','gt','Gt','gT']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (-1,), (0,), (1000,), (2000,), (3000,), (4000,)]) - elif j in ['NE','ne','Ne','nE']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (1000,), (2000,), (3000,), (4000,), (5000,), (6000,), (7000,), (8000,), (9000,)]) - elif j in ['EQ','eq','Eq','eQ']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,)]) - - + if j in ['LT', 'lt', 'Lt', 'lT', 'LE', 'le', 'Le', 'lE']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (1000,), (2000,), (3000,), (4000,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + elif j in ['GE', 'ge', 'Ge', 'gE', 'GT', 'gt', 'Gt', 'gT']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (-1,), (0,), (1000,), (2000,), (3000,), (4000,)]) + elif j in ['NE', 'ne', 'Ne', 'nE']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (1000,), (2000,), (3000,), (4000,), (5000,), (6000,), (7000,), (8000,), (9000,)]) + elif j in ['EQ', 'eq', 'Eq', 'eQ']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + tdSql.execute(f'drop table {self.ntbname}') # timestamp = 1m, time_unit =1m - tdSql.execute('''create table test2(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + tdSql.execute(f'''create table {self.ntbname}(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, col7 bool, col8 binary(20), col9 nchar(20), col11 tinyint unsigned, col12 smallint unsigned, col13 int unsigned, col14 bigint unsigned)''') for i in range(self.row_num): - tdSql.execute("insert into test2 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)" - % (self.ts + i*1000*60, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1)) + tdSql.execute(f"insert into {self.ntbname} values({self.ts + i*1000*60}, {i + 1}, {i + 1}, {i + 1}, {i + 1}, {i + 0.1},{i + 0.1}, {i % 2}, 'taosdata{i + 1}', '涛思数据{i + 1}',{i + 1}, {i + 1}, {i + 1}, {i + 1})" + ) for i in integer_list: for j in self.param_list: - tdSql.query(f"select stateduration(col{i},'{j}',5,1m) from test2") + tdSql.query( + f"select stateduration(col{i},'{j}',5,1m) from {self.ntbname}") tdSql.checkRows(10) - # print(tdSql.queryResult) - if j in ['LT' ,'lt','Lt','lT']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (1,), (2,), (3,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,)]) - elif j in ['GT','gt', 'Gt','gT']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (-1,), (0,), (1,), (2,), (3,), (4,)]) - elif j in ['LE','le','Le','lE']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (1,), (2,), (3,), (4,), (-1,), (-1,), (-1,), (-1,), (-1,)]) - elif j in [ 'GE','ge','Ge','gE']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (0,), (1,), (2,), (3,), (4,), (5,)]) - elif j in ['NE','ne','Ne','nE']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (1,), (2,), (3,), (-1,), (0,), (1,), (2,), (3,), (4,)]) - elif j in ['EQ','eq','Eq','eQ']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (0,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + if j in ['LT', 'lt', 'Lt', 'lT']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (1,), (2,), (3,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + elif j in ['GT', 'gt', 'Gt', 'gT']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (-1,), (0,), (1,), (2,), (3,), (4,)]) + elif j in ['LE', 'le', 'Le', 'lE']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (1,), (2,), (3,), (4,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + elif j in ['GE', 'ge', 'Ge', 'gE']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (0,), (1,), (2,), (3,), (4,), (5,)]) + elif j in ['NE', 'ne', 'Ne', 'nE']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (1,), (2,), (3,), (-1,), (0,), (1,), (2,), (3,), (4,)]) + elif j in ['EQ', 'eq', 'Eq', 'eQ']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (0,), (-1,), (-1,), (-1,), (-1,), (-1,)]) for i in float_list: for j in self.param_list: - tdSql.query(f"select stateduration(col{i},'{j}',5,1m) from test2") + tdSql.query( + f"select stateduration(col{i},'{j}',5,1m) from {self.ntbname}") tdSql.checkRows(10) print(tdSql.queryResult) - if j in ['LT','lt','Lt','lT','LE','le','Le','lE']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (1,), (2,), (3,), (4,), (-1,), (-1,), (-1,), (-1,), (-1,)]) - elif j in ['GE','ge','Ge','gE','GT','gt','Gt','gT']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (-1,), (0,), (1,), (2,), (3,), (4,)]) - elif j in ['NE','ne','Ne','nE']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (1,), (2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,)]) - elif j in ['EQ','eq','Eq','eQ']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,)]) - + if j in ['LT', 'lt', 'Lt', 'lT', 'LE', 'le', 'Le', 'lE']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (1,), (2,), (3,), (4,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + elif j in ['GE', 'ge', 'Ge', 'gE', 'GT', 'gt', 'Gt', 'gT']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (-1,), (0,), (1,), (2,), (3,), (4,)]) + elif j in ['NE', 'ne', 'Ne', 'nE']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (1,), (2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,)]) + elif j in ['EQ', 'eq', 'Eq', 'eQ']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + tdSql.execute(f'drop table {self.ntbname}') # timestamp = 1h, time_unit =1h - tdSql.execute('''create table test3(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + tdSql.execute(f'''create table {self.ntbname}(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, col7 bool, col8 binary(20), col9 nchar(20), col11 tinyint unsigned, col12 smallint unsigned, col13 int unsigned, col14 bigint unsigned)''') for i in range(self.row_num): - tdSql.execute("insert into test3 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)" - % (self.ts + i*1000*60*60, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1)) + tdSql.execute(f"insert into {self.ntbname} values({self.ts + i*1000*60*60}, {i + 1}, {i + 1}, {i + 1}, {i + 1},{i + 0.1}, {i + 0.1}, {i % 2}, 'taosdata{i + 1}', '涛思数据{i + 1}', {i + 1}, {i + 1}, {i + 1}, {i + 1})" + ) for i in integer_list: for j in self.param_list: - tdSql.query(f"select stateduration(col{i},'{j}',5,1h) from test3") + tdSql.query( + f"select stateduration(col{i},'{j}',5,1h) from {self.ntbname}") tdSql.checkRows(10) - # print(tdSql.queryResult) - if j in ['LT' ,'lt','Lt','lT']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (1,), (2,), (3,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,)]) - elif j in ['GT','gt', 'Gt','gT']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (-1,), (0,), (1,), (2,), (3,), (4,)]) - elif j in ['LE','le','Le','lE']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (1,), (2,), (3,), (4,), (-1,), (-1,), (-1,), (-1,), (-1,)]) - elif j in [ 'GE','ge','Ge','gE']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (0,), (1,), (2,), (3,), (4,), (5,)]) - elif j in ['NE','ne','Ne','nE']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (1,), (2,), (3,), (-1,), (0,), (1,), (2,), (3,), (4,)]) - elif j in ['EQ','eq','Eq','eQ']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (0,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + if j in ['LT', 'lt', 'Lt', 'lT']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (1,), (2,), (3,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + elif j in ['GT', 'gt', 'Gt', 'gT']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (-1,), (0,), (1,), (2,), (3,), (4,)]) + elif j in ['LE', 'le', 'Le', 'lE']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (1,), (2,), (3,), (4,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + elif j in ['GE', 'ge', 'Ge', 'gE']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (0,), (1,), (2,), (3,), (4,), (5,)]) + elif j in ['NE', 'ne', 'Ne', 'nE']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (1,), (2,), (3,), (-1,), (0,), (1,), (2,), (3,), (4,)]) + elif j in ['EQ', 'eq', 'Eq', 'eQ']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (0,), (-1,), (-1,), (-1,), (-1,), (-1,)]) for i in float_list: for j in self.param_list: - tdSql.query(f"select stateduration(col{i},'{j}',5,1h) from test3") + tdSql.query( + f"select stateduration(col{i},'{j}',5,1h) from {self.ntbname}") tdSql.checkRows(10) print(tdSql.queryResult) - if j in ['LT','lt','Lt','lT','LE','le','Le','lE']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (1,), (2,), (3,), (4,), (-1,), (-1,), (-1,), (-1,), (-1,)]) - elif j in ['GE','ge','Ge','gE','GT','gt','Gt','gT']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (-1,), (0,), (1,), (2,), (3,), (4,)]) - elif j in ['NE','ne','Ne','nE']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (1,), (2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,)]) - elif j in ['EQ','eq','Eq','eQ']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + if j in ['LT', 'lt', 'Lt', 'lT', 'LE', 'le', 'Le', 'lE']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (1,), (2,), (3,), (4,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + elif j in ['GE', 'ge', 'Ge', 'gE', 'GT', 'gt', 'Gt', 'gT']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (-1,), (0,), (1,), (2,), (3,), (4,)]) + elif j in ['NE', 'ne', 'Ne', 'nE']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (1,), (2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,)]) + elif j in ['EQ', 'eq', 'Eq', 'eQ']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,)]) # timestamp = 1h,time_unit =1m for i in integer_list: for j in self.param_list: - tdSql.query(f"select stateduration(col{i},'{j}',5,1m) from test3") + tdSql.query( + f"select stateduration(col{i},'{j}',5,1m) from {self.ntbname}") tdSql.checkRows(10) - # print(tdSql.queryResult) - if j in ['LT' ,'lt','Lt','lT']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (60,), (120,), (180,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,)]) - elif j in ['GT','gt', 'Gt','gT']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (-1,), (0,), (60,), (120,), (180,), (240,)]) - elif j in ['LE','le','Le','lE']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (60,), (120,), (180,), (240,), (-1,), (-1,), (-1,), (-1,), (-1,)]) - elif j in [ 'GE','ge','Ge','gE']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (0,), (60,), (120,), (180,), (240,), (300,)]) - elif j in ['NE','ne','Ne','nE']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (60,), (120,), (180,), (-1,), (0,), (60,), (120,), (180,), (240,)]) - elif j in ['EQ','eq','Eq','eQ']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (0,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + if j in ['LT', 'lt', 'Lt', 'lT']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (60,), (120,), (180,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + elif j in ['GT', 'gt', 'Gt', 'gT']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (-1,), (0,), (60,), (120,), (180,), (240,)]) + elif j in ['LE', 'le', 'Le', 'lE']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (60,), (120,), (180,), (240,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + elif j in ['GE', 'ge', 'Ge', 'gE']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (0,), (60,), (120,), (180,), (240,), (300,)]) + elif j in ['NE', 'ne', 'Ne', 'nE']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (60,), (120,), (180,), (-1,), (0,), (60,), (120,), (180,), (240,)]) + elif j in ['EQ', 'eq', 'Eq', 'eQ']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (0,), (-1,), (-1,), (-1,), (-1,), (-1,)]) for i in float_list: for j in self.param_list: - tdSql.query(f"select stateduration(col{i},'{j}',5,1m) from test3") + tdSql.query( + f"select stateduration(col{i},'{j}',5,1m) from {self.ntbname}") tdSql.checkRows(10) print(tdSql.queryResult) - if j in ['LT','lt','Lt','lT','LE','le','Le','lE']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (60,), (120,), (180,), (240,), (-1,), (-1,), (-1,), (-1,), (-1,)]) - elif j in ['GE','ge','Ge','gE','GT','gt','Gt','gT']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (-1,), (0,), (60,), (120,), (180,), (240,)]) - elif j in ['NE','ne','Ne','nE']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (60,), (120,), (180,), (240,), (300,), (360,), (420,), (480,), (540,)]) - elif j in ['EQ','eq','Eq','eQ']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + if j in ['LT', 'lt', 'Lt', 'lT', 'LE', 'le', 'Le', 'lE']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (60,), (120,), (180,), (240,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + elif j in ['GE', 'ge', 'Ge', 'gE', 'GT', 'gt', 'Gt', 'gT']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (-1,), (0,), (60,), (120,), (180,), (240,)]) + elif j in ['NE', 'ne', 'Ne', 'nE']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (60,), (120,), (180,), (240,), (300,), (360,), (420,), (480,), (540,)]) + elif j in ['EQ', 'eq', 'Eq', 'eQ']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,)]) # for stb - tdSql.execute('''create table stb(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + + tdSql.execute(f'''create table {self.stbname}(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, col7 bool, col8 binary(20), col9 nchar(20), col11 tinyint unsigned, col12 smallint unsigned, col13 int unsigned, col14 bigint unsigned) tags(t0 int)''') - tdSql.execute('create table stb_1 using stb tags(1)') + tdSql.execute(f'create table {self.stbname}_1 using {self.stbname} tags(1)') for i in range(self.row_num): - tdSql.execute("insert into stb_1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)" - % (self.ts + i*1000*60*60, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1)) + tdSql.execute(f"insert into {self.stbname}_1 values({self.ts + i*1000*60*60}, {i + 1}, {i + 1},{ i + 1}, {i + 1}, {i + 0.1}, {i + 0.1}, {i % 2},'taosdata{i + 1}', '涛思数据{i + 1}', {i + 1}, {i + 1}, {i + 1}, {i + 1})" + ) for i in integer_list: for j in self.param_list: - tdSql.query(f"select stateduration(col{i},'{j}',5,1h) from stb") + tdSql.query( + f"select stateduration(col{i},'{j}',5,1h) from {self.stbname}") tdSql.checkRows(10) # print(tdSql.queryResult) - if j in ['LT' ,'lt','Lt','lT']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (1,), (2,), (3,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,)]) - elif j in ['GT','gt', 'Gt','gT']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (-1,), (0,), (1,), (2,), (3,), (4,)]) - elif j in ['LE','le','Le','lE']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (1,), (2,), (3,), (4,), (-1,), (-1,), (-1,), (-1,), (-1,)]) - elif j in [ 'GE','ge','Ge','gE']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (0,), (1,), (2,), (3,), (4,), (5,)]) - elif j in ['NE','ne','Ne','nE']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (1,), (2,), (3,), (-1,), (0,), (1,), (2,), (3,), (4,)]) - elif j in ['EQ','eq','Eq','eQ']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (0,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + if j in ['LT', 'lt', 'Lt', 'lT']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (1,), (2,), (3,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + elif j in ['GT', 'gt', 'Gt', 'gT']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (-1,), (0,), (1,), (2,), (3,), (4,)]) + elif j in ['LE', 'le', 'Le', 'lE']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (1,), (2,), (3,), (4,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + elif j in ['GE', 'ge', 'Ge', 'gE']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (0,), (1,), (2,), (3,), (4,), (5,)]) + elif j in ['NE', 'ne', 'Ne', 'nE']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (1,), (2,), (3,), (-1,), (0,), (1,), (2,), (3,), (4,)]) + elif j in ['EQ', 'eq', 'Eq', 'eQ']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (0,), (-1,), (-1,), (-1,), (-1,), (-1,)]) for i in float_list: for j in self.param_list: - tdSql.query(f"select stateduration(col{i},'{j}',5,1h) from stb") + tdSql.query( + f"select stateduration(col{i},'{j}',5,1h) from {self.stbname}") tdSql.checkRows(10) print(tdSql.queryResult) - if j in ['LT','lt','Lt','lT','LE','le','Le','lE']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (1,), (2,), (3,), (4,), (-1,), (-1,), (-1,), (-1,), (-1,)]) - elif j in ['GE','ge','Ge','gE','GT','gt','Gt','gT']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (-1,), (0,), (1,), (2,), (3,), (4,)]) - elif j in ['NE','ne','Ne','nE']: - tdSql.checkEqual(tdSql.queryResult,[(0,), (1,), (2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,)]) - elif j in ['EQ','eq','Eq','eQ']: - tdSql.checkEqual(tdSql.queryResult,[(-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + if j in ['LT', 'lt', 'Lt', 'lT', 'LE', 'le', 'Le', 'lE']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (1,), (2,), (3,), (4,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + elif j in ['GE', 'ge', 'Ge', 'gE', 'GT', 'gt', 'Gt', 'gT']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (-1,), (0,), (1,), (2,), (3,), (4,)]) + elif j in ['NE', 'ne', 'Ne', 'nE']: + tdSql.checkEqual(tdSql.queryResult, [ + (0,), (1,), (2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,)]) + elif j in ['EQ', 'eq', 'Eq', 'eQ']: + tdSql.checkEqual(tdSql.queryResult, [ + (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,), (-1,)]) + def run(self): + self.duration_check() def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) + tdCases.addWindows(__file__, TDTestCase()) tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/timetruncate.py b/tests/system-test/2-query/timetruncate.py index ea4f963b71..3551d8ee2c 100644 --- a/tests/system-test/2-query/timetruncate.py +++ b/tests/system-test/2-query/timetruncate.py @@ -21,9 +21,10 @@ class TDTestCase: self.db_param_precision = ['ms','us','ns'] self.time_unit = ['1w','1d','1h','1m','1s','1a','1u','1b'] self.error_unit = ['2w','2d','2h','2m','2s','2a','2u','1c','#1'] - self.ntbname = 'ntb' - self.stbname = 'stb' - self.ctbname = 'ctb' + self.dbname = 'db' + self.ntbname = f'{self.dbname}.ntb' + self.stbname = f'{self.dbname}.stb' + self.ctbname = f'{self.dbname}.ctb' def check_ms_timestamp(self,unit,date_time): if unit.lower() == '1a': for i in range(len(self.ts_str)): @@ -140,9 +141,9 @@ class TDTestCase: tdSql.error(f'select timetruncate(ts,{unit}) from {self.stbname}') def function_check_ntb(self): for precision in self.db_param_precision: - tdSql.execute('drop database if exists db') - tdSql.execute(f'create database db precision "{precision}"') - tdSql.execute('use db') + tdSql.execute(f'drop database if exists {self.dbname}') + tdSql.execute(f'create database {self.dbname} precision "{precision}"') + tdSql.execute(f'use {self.dbname}') tdSql.execute(f'create table {self.ntbname} (ts timestamp,c0 int)') for ts in self.ts_str: tdSql.execute(f'insert into {self.ntbname} values("{ts}",1)') @@ -150,9 +151,9 @@ class TDTestCase: self.data_check(date_time,precision,'ntb') def function_check_stb(self): for precision in self.db_param_precision: - tdSql.execute('drop database if exists db') - tdSql.execute(f'create database db precision "{precision}"') - tdSql.execute('use db') + tdSql.execute(f'drop database if exists {self.dbname}') + tdSql.execute(f'create database {self.dbname} precision "{precision}"') + tdSql.execute(f'use {self.dbname}') tdSql.execute(f'create table {self.stbname} (ts timestamp,c0 int) tags(t0 int)') tdSql.execute(f'create table {self.ctbname} using {self.stbname} tags(1)') for ts in self.ts_str: diff --git a/tests/system-test/2-query/timezone.py b/tests/system-test/2-query/timezone.py index 3707d25c88..9a4953909c 100644 --- a/tests/system-test/2-query/timezone.py +++ b/tests/system-test/2-query/timezone.py @@ -17,10 +17,11 @@ class TDTestCase: self.setsql = TDSetSql() self.arithmetic_operators = ['+','-','*','/'] self.arithmetic_values = [0,1,100,15.5] + self.dbname = 'db' # name of normal table - self.ntbname = 'ntb' + self.ntbname = f'{self.dbname}.ntb' # name of stable - self.stbname = 'stb' + self.stbname = f'{self.dbname}.stb' # structure of column self.column_dict = { 'ts':'timestamp', @@ -60,7 +61,6 @@ class TDTestCase: time_zone_1 = os.popen('ls -l /etc/localtime|awk -F/ \'{print $(NF-1) "/" $NF}\'').read().strip() time_zone_2 = os.popen('date "+(%Z, %z)"').read().strip() time_zone = time_zone_1 + " " + time_zone_2 - print("expected time zone: " + time_zone) return time_zone def tb_type_check(self,tb_type): @@ -94,7 +94,7 @@ class TDTestCase: tdSql.query(f"select * from {tbname} where timezone()='{timezone}'") self.tb_type_check(tb_type) def timezone_check_ntb(self,timezone): - tdSql.prepare() + tdSql.execute(f'create database {self.dbname}') tdSql.execute(self.setsql.set_create_normaltable_sql(self.ntbname,self.column_dict)) for value in self.values_list: tdSql.execute( @@ -102,7 +102,7 @@ class TDTestCase: self.data_check(timezone,self.ntbname,'normal_table') tdSql.execute('drop database db') def timezone_check_stb(self,timezone): - tdSql.prepare() + tdSql.execute(f'create database {self.dbname}') tdSql.execute(self.setsql.set_create_stable_sql(self.stbname,self.column_dict,self.tag_dict)) for i in range(self.tbnum): tdSql.execute(f'create table if not exists {self.stbname}_{i} using {self.stbname} tags({self.tag_values[i]})') From fef13bcd19a18063b923a538eb7906ff8fe63b3b Mon Sep 17 00:00:00 2001 From: jiacy-jcy Date: Wed, 10 Aug 2022 17:47:26 +0800 Subject: [PATCH 4/5] update --- tests/system-test/2-query/To_iso8601.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/system-test/2-query/To_iso8601.py b/tests/system-test/2-query/To_iso8601.py index 16db0cca59..a8ab3e1a29 100644 --- a/tests/system-test/2-query/To_iso8601.py +++ b/tests/system-test/2-query/To_iso8601.py @@ -21,6 +21,7 @@ class TDTestCase: def check_customize_param_ms(self): time_zone = time.strftime('%z') + tdSql.execute(f'drop database if exists {self.dbname}') tdSql.execute(f'create database {self.dbname} precision "ms"') tdSql.execute(f'use {self.dbname}') tdSql.execute(f'create table if not exists {self.ntbname}(ts timestamp, c1 int, c2 timestamp)') From 7b1f30d8dc99c6499e0ebe3385e868876927a60e Mon Sep 17 00:00:00 2001 From: jiacy-jcy Date: Thu, 11 Aug 2022 16:13:23 +0800 Subject: [PATCH 5/5] update --- tests/system-test/2-query/To_iso8601.py | 64 +++++++++---------------- 1 file changed, 22 insertions(+), 42 deletions(-) diff --git a/tests/system-test/2-query/To_iso8601.py b/tests/system-test/2-query/To_iso8601.py index a8ab3e1a29..ccc26e9b1b 100644 --- a/tests/system-test/2-query/To_iso8601.py +++ b/tests/system-test/2-query/To_iso8601.py @@ -19,7 +19,6 @@ class TDTestCase: self.stbname = f'{self.dbname}.stb' self.ntbname = f'{self.dbname}.ntb' def check_customize_param_ms(self): - time_zone = time.strftime('%z') tdSql.execute(f'drop database if exists {self.dbname}') tdSql.execute(f'create database {self.dbname} precision "ms"') @@ -30,7 +29,6 @@ class TDTestCase: tdSql.query(f'select to_iso8601(ts) from {self.ntbname}') for i in range(self.rowNum): tdSql.checkEqual(tdSql.queryResult[i][0],f'2022-01-01T00:00:00.00{i}{time_zone}') - timezone_list = ['+0000','+0100','+0200','+0300','+0330','+0400','+0500','+0530','+0600','+0700','+0800','+0900','+1000','+1100','+1200',\ '+00','+01','+02','+03','+04','+05','+06','+07','+08','+09','+10','+11','+12',\ '+00:00','+01:00','+02:00','+03:00','+03:30','+04:00','+05:00','+05:30','+06:00','+07:00','+08:00','+09:00','+10:00','+11:00','+12:00',\ @@ -42,59 +40,46 @@ class TDTestCase: tdSql.query(f'select to_iso8601(ts,"{j}") from {self.ntbname}') for i in range(self.rowNum): tdSql.checkEqual(tdSql.queryResult[i][0],f'2022-01-01T00:00:00.00{i}{j}') - error_param_list = [0,100.5,'a','!'] for i in error_param_list: tdSql.error(f'select to_iso8601(ts,"{i}") from {self.ntbname}') - #! bug TD-16372:对于错误的时区,缺少校验 error_timezone_param = ['+13','-13','+1300','-1300','+0001','-0001','-0330','-0530'] for i in error_timezone_param: tdSql.error(f'select to_iso8601(ts,"{i}") from {self.ntbname}') def check_base_function(self): tdSql.prepare() - tdLog.printNoPrefix("==========step1:create tables==========") - tdSql.execute('create table if not exists ntb(ts timestamp, c1 int, c2 float,c3 double,c4 timestamp)') - tdSql.execute('create table if not exists stb(ts timestamp, c1 int, c2 float,c3 double,c4 timestamp) tags(t0 int)') - tdSql.execute('create table if not exists stb_1 using stb tags(100)') - - tdLog.printNoPrefix("==========step2:insert data==========") - tdSql.execute('insert into ntb values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())') - tdSql.execute('insert into stb_1 values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())') - - tdSql.query("select to_iso8601(ts) from ntb") + tdSql.execute('create table if not exists db.ntb(ts timestamp, c1 int, c2 float,c3 double,c4 timestamp)') + tdSql.execute('create table if not exists db.stb(ts timestamp, c1 int, c2 float,c3 double,c4 timestamp) tags(t0 int)') + tdSql.execute('create table if not exists db.stb_1 using db.stb tags(100)') + tdSql.execute('insert into db.ntb values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())') + tdSql.execute('insert into db.stb_1 values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())') + tdSql.query("select to_iso8601(ts) from db.ntb") tdSql.checkRows(3) - tdSql.query("select c1 from ntb where ts = to_iso8601(1577808000000)") + tdSql.query("select c1 from db.ntb where ts = to_iso8601(1577808000000)") tdSql.checkRows(1) tdSql.checkData(0,0,10) - tdSql.query("select * from ntb where ts = to_iso8601(1577808000000)") + tdSql.query("select * from db.ntb where ts = to_iso8601(1577808000000)") tdSql.checkRows(1) - tdSql.query("select to_iso8601(ts) from ntb where ts=today()") + tdSql.query("select to_iso8601(ts) from db.ntb where ts=today()") tdSql.checkRows(1) for i in range(0,3): - tdSql.query("select to_iso8601(1) from ntb") + tdSql.query("select to_iso8601(1) from db.ntb") tdSql.checkData(i,0,"1970-01-01T08:00:01+0800") tdSql.checkRows(3) - tdSql.query("select to_iso8601(ts) from ntb") - tdSql.checkRows(3) tdSql.query("select to_iso8601(ts) from db.ntb") - - tdSql.query("select to_iso8601(today()) from ntb") tdSql.checkRows(3) - tdSql.query("select to_iso8601(now()) from ntb") + tdSql.query("select to_iso8601(today()) from db.ntb") tdSql.checkRows(3) - - tdSql.error("select to_iso8601(timezone()) from ntb") - tdSql.error("select to_iso8601('abc') from ntb") - + tdSql.query("select to_iso8601(now()) from db.ntb") + tdSql.checkRows(3) + tdSql.error("select to_iso8601(timezone()) from db.ntb") + tdSql.error("select to_iso8601('abc') from db.ntb") for i in ['+','-','*','/']: - tdSql.query(f"select to_iso8601(today()) {i}null from ntb") - tdSql.checkRows(3) - tdSql.checkData(0,0,None) tdSql.query(f"select to_iso8601(today()) {i}null from db.ntb") tdSql.checkRows(3) tdSql.checkData(0,0,None) - tdSql.query("select to_iso8601(9223372036854775807) from ntb") + tdSql.query("select to_iso8601(9223372036854775807) from db.ntb") tdSql.checkRows(3) # bug TD-15207 # tdSql.query("select to_iso8601(10000000000) from ntb") @@ -105,27 +90,22 @@ class TDTestCase: # tdSql.checkData(0,0,None) err_param = [1.5,'a','c2'] for i in err_param: - tdSql.error(f"select to_iso8601({i}) from ntb") tdSql.error(f"select to_iso8601({i}) from db.ntb") - - tdSql.query("select to_iso8601(now) from stb") + tdSql.query("select to_iso8601(now) from db.stb") tdSql.checkRows(3) - tdSql.query("select to_iso8601(now()) from stb") + tdSql.query("select to_iso8601(now()) from db.stb") tdSql.checkRows(3) - tdSql.query("select to_iso8601(1) from stb") + tdSql.query("select to_iso8601(1) from db.stb") for i in range(0,3): tdSql.checkData(i,0,"1970-01-01T08:00:01+0800") tdSql.checkRows(3) - tdSql.query("select to_iso8601(ts) from stb") + tdSql.query("select to_iso8601(ts) from db.stb") tdSql.checkRows(3) - tdSql.query("select to_iso8601(ts)+1 from stb") + tdSql.query("select to_iso8601(ts)+1 from db.stb") tdSql.checkRows(3) - tdSql.query("select to_iso8601(ts)+'a' from stb ") + tdSql.query("select to_iso8601(ts)+'a' from db.stb ") tdSql.checkRows(3) for i in ['+','-','*','/']: - tdSql.query(f"select to_iso8601(today()) {i}null from stb") - tdSql.checkRows(3) - tdSql.checkData(0,0,None) tdSql.query(f"select to_iso8601(today()) {i}null from db.stb") tdSql.checkRows(3) tdSql.checkData(0,0,None)