From 4a75a546d02b5e064ad33832043e693778bbd2df Mon Sep 17 00:00:00 2001 From: cpwu Date: Thu, 4 Aug 2022 14:23:39 +0800 Subject: [PATCH] fix case --- tests/system-test/0-others/user_control.py | 225 ++++++++---------- tests/system-test/1-insert/time_range_wise.py | 206 ++++++---------- 2 files changed, 181 insertions(+), 250 deletions(-) diff --git a/tests/system-test/0-others/user_control.py b/tests/system-test/0-others/user_control.py index ce8ac6941b..037f3075f6 100644 --- a/tests/system-test/0-others/user_control.py +++ b/tests/system-test/0-others/user_control.py @@ -1,15 +1,16 @@ -from tabnanny import check import taos import time import inspect import traceback import socket from dataclasses import dataclass +from datetime import datetime from util.log import * from util.sql import * from util.cases import * from util.dnodes import * +from util.common import * PRIVILEGES_ALL = "ALL" PRIVILEGES_READ = "READ" @@ -21,17 +22,40 @@ WEIGHT_WRITE = 3 PRIMARY_COL = "ts" -INT_COL = "c1" -BINT_COL = "c2" -SINT_COL = "c3" -TINT_COL = "c4" -FLOAT_COL = "c5" -DOUBLE_COL = "c6" -BOOL_COL = "c7" +INT_COL = "c_int" +BINT_COL = "c_bint" +SINT_COL = "c_sint" +TINT_COL = "c_tint" +FLOAT_COL = "c_float" +DOUBLE_COL = "c_double" +BOOL_COL = "c_bool" +TINT_UN_COL = "c_utint" +SINT_UN_COL = "c_usint" +BINT_UN_COL = "c_ubint" +INT_UN_COL = "c_uint" +BINARY_COL = "c_binary" +NCHAR_COL = "c_nchar" +TS_COL = "c_ts" -BINARY_COL = "c8" -NCHAR_COL = "c9" -TS_COL = "c10" +NUM_COL = [INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, ] +CHAR_COL = [BINARY_COL, NCHAR_COL, ] +BOOLEAN_COL = [BOOL_COL, ] +TS_TYPE_COL = [TS_COL, ] + +INT_TAG = "t_int" + +ALL_COL = [PRIMARY_COL, INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, BINARY_COL, NCHAR_COL, BOOL_COL, TS_COL] +TAG_COL = [INT_TAG] + +# insert data args: +TIME_STEP = 10000 +NOW = int(datetime.timestamp(datetime.now()) * 1000) + +# init db/table +DBNAME = "db" +STBNAME = "stb1" +CTBNAME = "ct1" +NTBNAME = "nt1" class TDconnect: def __init__(self, @@ -247,25 +271,25 @@ class TDTestCase: with taos_connect(user=user.name, passwd=user.passwd) as use: time.sleep(2) if check_priv == PRIVILEGES_ALL: - use.query("use db") - use.query("show tables") - use.query("select * from ct1") - use.query("insert into t1 (ts) values (now())") + use.query(f"use {DBNAME}") + use.query(f"show {DBNAME}.tables") + use.query(f"select * from {DBNAME}.{CTBNAME}") + use.query(f"insert into {DBNAME}.{CTBNAME} (ts) values (now())") elif check_priv == PRIVILEGES_READ: - use.query("use db") - use.query("show tables") - use.query("select * from ct1") - use.error("insert into t1 (ts) values (now())") + use.query(f"use {DBNAME}") + use.query(f"show {DBNAME}.tables") + use.query(f"select * from {DBNAME}.{CTBNAME}") + use.error(f"insert into {DBNAME}.{CTBNAME} (ts) values (now())") elif check_priv == PRIVILEGES_WRITE: - use.query("use db") - use.query("show tables") - use.error("select * from ct1") - use.query("insert into t1 (ts) values (now())") + use.query(f"use {DBNAME}") + use.query(f"show {DBNAME}.tables") + use.error(f"select * from {DBNAME}.{CTBNAME}") + use.query(f"insert into {DBNAME}.{CTBNAME} (ts) values (now())") elif check_priv is None: - use.error("use db") - use.error("show tables") - use.error("select * from db.ct1") - use.error("insert into db.t1 (ts) values (now())") + use.error(f"use {DBNAME}") + use.error(f"show {DBNAME}.tables") + use.error(f"select * from {DBNAME}.{CTBNAME}") + use.error(f"insert into {DBNAME}.{CTBNAME} (ts) values (now())") def __change_user_priv(self, user: User, pre_priv, invoke=False): if user.priv == pre_priv and invoke : @@ -418,7 +442,7 @@ class TDTestCase: self.__grant_user_privileges(privilege="", dbname="db", user_name=self.__user_list[0]) , self.__grant_user_privileges(privilege=" ".join(self.__privilege), user_name=self.__user_list[0]) , f"GRANT {self.__privilege[0]} ON * TO {self.__user_list[0]}" , - f"GRANT {self.__privilege[0]} ON db.t1 TO {self.__user_list[0]}" , + f"GRANT {self.__privilege[0]} ON {DBNAME}.{NTBNAME} TO {self.__user_list[0]}" , ] def __revoke_err(self): @@ -430,7 +454,7 @@ class TDTestCase: self.__revoke_user_privileges(privilege="", dbname="db", user_name=self.__user_list[0]) , self.__revoke_user_privileges(privilege=" ".join(self.__privilege), user_name=self.__user_list[0]) , f"REVOKE {self.__privilege[0]} ON * FROM {self.__user_list[0]}" , - f"REVOKE {self.__privilege[0]} ON db.t1 FROM {self.__user_list[0]}" , + f"REVOKE {self.__privilege[0]} ON {DBNAME}.{NTBNAME} FROM {self.__user_list[0]}" , ] def test_grant_err(self): @@ -505,101 +529,48 @@ class TDTestCase: self.drop_user_error() self.drop_user_current() - def __create_tb(self): - - tdLog.printNoPrefix("==========step1:create table") - create_stb_sql = f'''create table stb1( - ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, - {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, - {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp - ) tags (t1 int) - ''' - create_ntb_sql = f'''create table t1( - ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, - {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, - {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp - ) + def __create_tb(self, stb=STBNAME, ctb_num=20, ntbnum=1, dbname=DBNAME): + tdLog.printNoPrefix("==========step: create table") + create_stb_sql = f'''create table {dbname}.{stb}( + {PRIMARY_COL} timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, + {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, + {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp, + {TINT_UN_COL} tinyint unsigned, {SINT_UN_COL} smallint unsigned, + {INT_UN_COL} int unsigned, {BINT_UN_COL} bigint unsigned + ) tags ({INT_TAG} int) ''' tdSql.execute(create_stb_sql) - tdSql.execute(create_ntb_sql) - 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 __insert_data(self, rows): - now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) - for i in range(rows): - tdSql.execute( - f"insert into ct1 values ( { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" - ) - tdSql.execute( - f"insert into ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" - ) - tdSql.execute( - f"insert into ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" - ) - tdSql.execute( - f'''insert into ct1 values - ( { now_time - rows * 5 }, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar_测试_0', { now_time + 8 } ) - ( { now_time + 10000 }, { rows }, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar_测试_9', { now_time + 9 } ) - ''' - ) - - tdSql.execute( - f'''insert into ct4 values - ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( { now_time - rows * 3888000000 + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( - { now_time + 5184000000}, {pow(2,31)-pow(2,15)}, {pow(2,63)-pow(2,30)}, 32767, 127, - { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_测试_limit-1", { now_time - 86400000} + for i in range(ntbnum): + create_ntb_sql = f'''create table {dbname}.nt{i+1}( + {PRIMARY_COL} timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, + {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, + {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp, + {TINT_UN_COL} tinyint unsigned, {SINT_UN_COL} smallint unsigned, + {INT_UN_COL} int unsigned, {BINT_UN_COL} bigint unsigned ) - ( - { now_time + 2592000000 }, {pow(2,31)-pow(2,16)}, {pow(2,63)-pow(2,31)}, 32766, 126, - { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_测试_limit-2", { now_time - 172800000} - ) - ''' - ) - - tdSql.execute( - f'''insert into ct2 values - ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( { now_time - rows * 3888000000 + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( - { now_time + 5184000000 }, { -1 * pow(2,31) + pow(2,15) }, { -1 * pow(2,63) + pow(2,30) }, -32766, -126, - { -1 * 3.2 * pow(10,38) }, { -1.2 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_测试_limit-1", { now_time - 86400000 } - ) - ( - { now_time + 2592000000 }, { -1 * pow(2,31) + pow(2,16) }, { -1 * pow(2,63) + pow(2,31) }, -32767, -127, - { - 3.3 * pow(10,38) }, { -1.3 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_测试_limit-2", { now_time - 172800000 } - ) - ''' - ) - - for i in range(rows): - insert_data = f'''insert into t1 values - ( { now_time - i * 3600000 }, {i}, {i * 11111}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}, - "binary_{i}", "nchar_测试_{i}", { now_time - 1000 * i } ) ''' - tdSql.execute(insert_data) - tdSql.execute( - f'''insert into t1 values - ( { now_time + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( { now_time - (( rows // 2 ) * 60 + 30) * 60000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( { now_time - rows * 3600000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( { now_time + 7200000 }, { pow(2,31) - pow(2,15) }, { pow(2,63) - pow(2,30) }, 32767, 127, - { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, - "binary_limit-1", "nchar_测试_limit-1", { now_time - 86400000 } - ) - ( - { now_time + 3600000 } , { pow(2,31) - pow(2,16) }, { pow(2,63) - pow(2,31) }, 32766, 126, - { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, - "binary_limit-2", "nchar_测试_limit-2", { now_time - 172800000 } - ) + tdSql.execute(create_ntb_sql) + + for i in range(ctb_num): + tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.{stb} tags ( {i+1} )') + + def __insert_data(self, rows, ctb_num=20, dbname=DBNAME, star_time=NOW): + tdLog.printNoPrefix("==========step: start inser data into tables now.....") + # from ...pytest.util.common import DataSet + data = DataSet() + data.get_order_set(rows) + + for i in range(rows): + row_data = f''' + {data.int_data[i]}, {data.bint_data[i]}, {data.sint_data[i]}, {data.tint_data[i]}, {data.float_data[i]}, {data.double_data[i]}, + {data.bool_data[i]}, '{data.vchar_data[i]}', '{data.nchar_data[i]}', {data.ts_data[i]}, {data.utint_data[i]}, + {data.usint_data[i]}, {data.uint_data[i]}, {data.ubint_data[i]} ''' - ) + tdSql.execute( f"insert into {dbname}.{NTBNAME} values ( {star_time - i * int(TIME_STEP * 1.2)}, {row_data} )" ) + + for j in range(ctb_num): + tdSql.execute( f"insert into {dbname}.ct{j+1} values ( {star_time - j * i * TIME_STEP}, {row_data} )" ) def run(self): tdSql.prepare() @@ -656,25 +627,33 @@ class TDTestCase: with taos_connect(user=self.__user_list[0], passwd=f"new{self.__passwd_list[0]}") as user: # user = conn # 不能创建用户 - tdLog.printNoPrefix("==========step5: normal user can not create user") + tdLog.printNoPrefix("==========step4.1: normal user can not create user") user.error("create use utest1 pass 'utest1pass'") # 可以查看用户 - tdLog.printNoPrefix("==========step6: normal user can show user") + tdLog.printNoPrefix("==========step4.2: normal user can show user") user.query("show users") assert user.queryRows == self.users_count + 1 # 不可以修改其他用户的密码 - tdLog.printNoPrefix("==========step7: normal user can not alter other user pass") + tdLog.printNoPrefix("==========step4.3: normal user can not alter other user pass") user.error(self.__alter_pass_sql(self.__user_list[1], self.__passwd_list[1] )) user.error(self.__alter_pass_sql("root", "taosdata_root" )) # 可以修改自己的密码 - tdLog.printNoPrefix("==========step8: normal user can alter owner pass") + tdLog.printNoPrefix("==========step4.4: normal user can alter owner pass") user.query(self.__alter_pass_sql(self.__user_list[0], self.__passwd_list[0])) # 不可以删除用户,包括自己 - tdLog.printNoPrefix("==========step9: normal user can not drop any user ") + tdLog.printNoPrefix("==========step4.5: normal user can not drop any user ") user.error(f"drop user {self.__user_list[0]}") user.error(f"drop user {self.__user_list[1]}") user.error("drop user root") + tdLog.printNoPrefix("==========step5: enable info") + taos1_conn = taos.connect(user=self.__user_list[1], password=f"new{self.__passwd_list[1]}") + taos2_conn = taos.connect(user=self.__user_list[2], password=f"new{self.__passwd_list[2]}") + tdSql.execute() + + + + # root删除用户测试 tdLog.printNoPrefix("==========step10: super user drop normal user") self.test_drop_user() diff --git a/tests/system-test/1-insert/time_range_wise.py b/tests/system-test/1-insert/time_range_wise.py index e65dded601..e66f5560df 100644 --- a/tests/system-test/1-insert/time_range_wise.py +++ b/tests/system-test/1-insert/time_range_wise.py @@ -1,4 +1,4 @@ -import datetime +from datetime import datetime import time from dataclasses import dataclass @@ -8,6 +8,7 @@ from util.sql import * from util.cases import * from util.dnodes import * from util.constant import * +from util.common import * PRIMARY_COL = "ts" @@ -38,7 +39,7 @@ TAG_COL = [INT_TAG] # insert data args: TIME_STEP = 10000 -NOW = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) +NOW = int(datetime.timestamp(datetime.now()) * 1000) # init db/table DBNAME = "db" @@ -47,40 +48,6 @@ CTBNAME = "ct1" NTBNAME = "nt1" -@dataclass -class DataSet: - ts_data : List[int] = None - int_data : List[int] = None - bint_data : List[int] = None - sint_data : List[int] = None - tint_data : List[int] = None - int_un_data : List[int] = None - bint_un_data: List[int] = None - sint_un_data: List[int] = None - tint_un_data: List[int] = None - float_data : List[float] = None - double_data : List[float] = None - bool_data : List[int] = None - binary_data : List[str] = None - nchar_data : List[str] = None - - def __post_init__(self): - self.ts_data = [] - self.int_data = [] - self.bint_data = [] - self.sint_data = [] - self.tint_data = [] - self.int_un_data = [] - self.bint_un_data = [] - self.sint_un_data = [] - self.tint_un_data = [] - self.float_data = [] - self.double_data = [] - self.bool_data = [] - self.binary_data = [] - self.nchar_data = [] - - @dataclass class SMAschema: creation : str = "CREATE" @@ -164,10 +131,6 @@ class SMAschema: del self.other[k] - -# from ...pytest.util.sql import * -# from ...pytest.util.constant import * - class TDTestCase: updatecfgDict = {"querySmaOptimize": 1} @@ -469,14 +432,12 @@ class TDTestCase: err_sqls.append( SMAschema(index_flag="SMA INDEX ,", tbname=STBNAME, func=(f"min({INT_COL})",f"max({INT_COL})") ) ) err_sqls.append( SMAschema(index_name="tbname", tbname=STBNAME, func=(f"min({INT_COL})",f"max({INT_COL})") ) ) - # current_set cur_sqls.append( SMAschema(max_delay="",tbname=STBNAME, func=(f"min({INT_COL})",f"max({INT_COL})") ) ) cur_sqls.append( SMAschema(watermark="",index_name="sma_index_2",tbname=STBNAME, func=(f"min({INT_COL})",f"max({INT_COL})") ) ) cur_sqls.append( SMAschema(sliding="",index_name='sma_index_3',tbname=STBNAME, func=(f"min({INT_COL})",f"max({INT_COL})") ) ) - return err_sqls, cur_sqls def test_create_sma(self): @@ -512,102 +473,48 @@ class TDTestCase: self.test_create_sma() self.test_drop_sma() - pass - - def __create_tb(self): + def __create_tb(self, stb=STBNAME, ctb_num=20, ntbnum=1, dbname=DBNAME): tdLog.printNoPrefix("==========step: create table") - create_stb_sql = f'''create table {STBNAME}( - ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, + create_stb_sql = f'''create table {dbname}.{stb}( + {PRIMARY_COL} timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp, {TINT_UN_COL} tinyint unsigned, {SINT_UN_COL} smallint unsigned, {INT_UN_COL} int unsigned, {BINT_UN_COL} bigint unsigned ) tags ({INT_TAG} int) ''' - create_ntb_sql = f'''create table {NTBNAME}( - ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, - {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, - {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp, - {TINT_UN_COL} tinyint unsigned, {SINT_UN_COL} smallint unsigned, - {INT_UN_COL} int unsigned, {BINT_UN_COL} bigint unsigned - ) - ''' tdSql.execute(create_stb_sql) - tdSql.execute(create_ntb_sql) - for i in range(4): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + for i in range(ntbnum): + create_ntb_sql = f'''create table {dbname}.nt{i+1}( + {PRIMARY_COL} timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, + {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, + {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp, + {TINT_UN_COL} tinyint unsigned, {SINT_UN_COL} smallint unsigned, + {INT_UN_COL} int unsigned, {BINT_UN_COL} bigint unsigned + ) + ''' + tdSql.execute(create_ntb_sql) - def __data_set(self, rows): - data_set = DataSet() + for i in range(ctb_num): + tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.{stb} tags ( {i+1} )') + + def __insert_data(self, rows, ctb_num=20, dbname=DBNAME, star_time=NOW): + tdLog.printNoPrefix("==========step: start inser data into tables now.....") + # from ...pytest.util.common import DataSet + data = DataSet() + data.get_order_set(rows, bint_step=2) for i in range(rows): - data_set.ts_data.append(NOW + 1 * (rows - i)) - data_set.int_data.append(rows - i) - data_set.bint_data.append(11111 * (rows - i)) - data_set.sint_data.append(111 * (rows - i) % 32767) - data_set.tint_data.append(11 * (rows - i) % 127) - data_set.int_un_data.append(rows - i) - data_set.bint_un_data.append(11111 * (rows - i)) - data_set.sint_un_data.append(111 * (rows - i) % 32767) - data_set.tint_un_data.append(11 * (rows - i) % 127) - data_set.float_data.append(1.11 * (rows - i)) - data_set.double_data.append(1100.0011 * (rows - i)) - data_set.bool_data.append((rows - i) % 2) - data_set.binary_data.append(f'binary{(rows - i)}') - data_set.nchar_data.append(f'nchar_测试_{(rows - i)}') - - return data_set - - def __insert_data(self): - tdLog.printNoPrefix("==========step: start inser data into tables now.....") - data = self.__data_set(rows=self.rows) - - # now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) - null_data = '''null, null, null, null, null, null, null, null, null, null, null, null, null, null''' - zero_data = "0, 0, 0, 0, 0, 0, 0, 'binary_0', 'nchar_0', 0, 0, 0, 0, 0" - - for i in range(self.rows): row_data = f''' {data.int_data[i]}, {data.bint_data[i]}, {data.sint_data[i]}, {data.tint_data[i]}, {data.float_data[i]}, {data.double_data[i]}, - {data.bool_data[i]}, '{data.binary_data[i]}', '{data.nchar_data[i]}', {data.ts_data[i]}, {data.tint_un_data[i]}, - {data.sint_un_data[i]}, {data.int_un_data[i]}, {data.bint_un_data[i]} - ''' - neg_row_data = f''' - {-1 * data.int_data[i]}, {-1 * data.bint_data[i]}, {-1 * data.sint_data[i]}, {-1 * data.tint_data[i]}, {-1 * data.float_data[i]}, {-1 * data.double_data[i]}, - {data.bool_data[i]}, '{data.binary_data[i]}', '{data.nchar_data[i]}', {data.ts_data[i]}, {1 * data.tint_un_data[i]}, - {1 * data.sint_un_data[i]}, {1 * data.int_un_data[i]}, {1 * data.bint_un_data[i]} + {data.bool_data[i]}, '{data.vchar_data[i]}', '{data.nchar_data[i]}', {data.ts_data[i]}, {data.utint_data[i]}, + {data.usint_data[i]}, {data.uint_data[i]}, {data.ubint_data[i]} ''' + tdSql.execute( f"insert into {dbname}.{NTBNAME} values ( {star_time - i * int(TIME_STEP * 1.2)}, {row_data} )" ) - tdSql.execute( - f"insert into ct1 values ( {NOW - i * TIME_STEP}, {row_data} )") - tdSql.execute( - f"insert into ct2 values ( {NOW - i * int(TIME_STEP * 0.6)}, {neg_row_data} )") - tdSql.execute( - f"insert into ct4 values ( {NOW - i * int(TIME_STEP * 0.8) }, {row_data} )") - tdSql.execute( - f"insert into {NTBNAME} values ( {NOW - i * int(TIME_STEP * 1.2)}, {row_data} )") - - tdSql.execute( - f"insert into ct2 values ( {NOW + int(TIME_STEP * 0.6)}, {null_data} )") - tdSql.execute( - f"insert into ct2 values ( {NOW - (self.rows + 1) * int(TIME_STEP * 0.6)}, {null_data} )") - tdSql.execute( - f"insert into ct2 values ( {NOW - self.rows * int(TIME_STEP * 0.29) }, {null_data} )") - - tdSql.execute( - f"insert into ct4 values ( {NOW + int(TIME_STEP * 0.8)}, {null_data} )") - tdSql.execute( - f"insert into ct4 values ( {NOW - (self.rows + 1) * int(TIME_STEP * 0.8)}, {null_data} )") - tdSql.execute( - f"insert into ct4 values ( {NOW - self.rows * int(TIME_STEP * 0.39)}, {null_data} )") - - tdSql.execute( - f"insert into {NTBNAME} values ( {NOW + int(TIME_STEP * 1.2)}, {null_data} )") - tdSql.execute( - f"insert into {NTBNAME} values ( {NOW - (self.rows + 1) * int(TIME_STEP * 1.2)}, {null_data} )") - tdSql.execute( - f"insert into {NTBNAME} values ( {NOW - self.rows * int(TIME_STEP * 0.59)}, {null_data} )") + for j in range(ctb_num): + tdSql.execute( f"insert into {dbname}.ct{j+1} values ( {star_time - j * i * TIME_STEP}, {row_data} )" ) def run(self): self.rows = 10 @@ -616,14 +523,60 @@ class TDTestCase: tdLog.printNoPrefix("==========step1:create table in normal database") tdSql.prepare() - self.__create_tb() - self.__insert_data() + self.__create_tb(dbname=DBNAME) + self.__insert_data(rows=self.rows) self.all_test() + # # from ...pytest.util.sql import * + # drop databases, create same name db、stb and sma index tdSql.prepare() - self.__create_tb() - self.__insert_data() + self.__create_tb(dbname=DBNAME) + self.__insert_data(rows=self.rows,star_time=NOW + self.rows * 2 * TIME_STEP) + tdLog.printNoPrefix("==========step1.1 : create a tsma index and checkdata") + tdSql.execute(f"create sma index {DBNAME}.sma_index_name1 on {DBNAME}.{STBNAME} function(max({INT_COL}),max({BINT_COL}),min({INT_COL})) interval(6m,10s) sliding(6m)") + self.__insert_data(rows=self.rows) + tdSql.query(f"select max({INT_COL}), max({BINT_COL}), min({INT_COL}) from {DBNAME}.{STBNAME} interval(6m,10s) sliding(6m)") + tdSql.checkData(0, 0, self.rows - 1) + tdSql.checkData(0, 1, (self.rows - 1) * 2 ) + tdSql.checkData(tdSql.queryRows - 1, 2, 0) + # tdSql.checkData(0, 2, 0) + + tdLog.printNoPrefix("==========step1.2 : alter table schema, drop col without index") + tdSql.execute(f"alter stable {DBNAME}.{STBNAME} drop column {BINARY_COL}") + tdSql.query(f"select max({INT_COL}), max({BINT_COL}), min({INT_COL}) from {DBNAME}.{STBNAME} interval(6m,10s) sliding(6m)") + tdSql.checkData(0, 0, self.rows - 1) + tdSql.checkData(0, 1, (self.rows - 1) * 2 ) + tdSql.checkData(tdSql.queryRows - 1, 2, 0) + + tdLog.printNoPrefix("==========step1.3 : alter table schema, drop col with index") + # TODO: TD-18047, can not drop col, when col in tsma-index and tsma-index is not dropped. + tdSql.error(f"alter stable {DBNAME}.stb1 drop column {BINT_COL}") + + tdLog.printNoPrefix("==========step1.4 : alter table schema, add col") + tdSql.execute(f"alter stable {DBNAME}.{STBNAME} add column {BINT_COL}_1 bigint") + tdSql.execute(f"insert into {DBNAME}.{CTBNAME} ({PRIMARY_COL}, {BINT_COL}_1) values(now(), 111)") + tdSql.query(f"select max({INT_COL}), max({BINT_COL}), min({INT_COL}) from {DBNAME}.{STBNAME} interval(6m,10s) sliding(6m)") + tdSql.checkData(0, 0, self.rows - 1) + tdSql.checkData(0, 1, (self.rows - 1) * 2 ) + tdSql.checkData(tdSql.queryRows - 1, 2, 0) + # tdSql.checkData(0, 2, 0) + tdSql.query(f"select max({BINT_COL}_1) from {DBNAME}.{STBNAME} ") + tdSql.checkData(0, 0 , 111) + + tdSql.execute(f"flush database {DBNAME}") + + tdLog.printNoPrefix("==========step1.5 : drop child table") + tdSql.execute(f"drop table {CTBNAME}") + tdSql.query(f"select max({INT_COL}), max({BINT_COL}), min({INT_COL}) from {DBNAME}.{STBNAME} interval(6m,10s) sliding(6m)") + tdSql.checkData(0, 0, self.rows - 1) + tdSql.checkData(0, 1, (self.rows - 1) * 2 ) + tdSql.checkData(tdSql.queryRows - 1, 2, 0) + + tdLog.printNoPrefix("==========step1.6 : drop stable") + tdSql.execute(f"drop table {STBNAME}") + tdSql.error(f"select * from {DBNAME}.{STBNAME}") + self.all_test() tdLog.printNoPrefix("==========step2:create table in rollup database") @@ -640,7 +593,6 @@ class TDTestCase: tdSql.execute("flush database db ") - tdLog.printNoPrefix("==========step4:after wal, all check again ") self.all_test()