From 046c9cb748edbd7b3c87fcbeb546593fe80d148f Mon Sep 17 00:00:00 2001 From: cpwu Date: Thu, 21 Jul 2022 17:05:31 +0800 Subject: [PATCH 01/20] fix case --- tests/system-test/2-query/concat.py | 61 ++- tests/system-test/2-query/concat2.py | 60 ++- tests/system-test/2-query/concat_ws.py | 60 +-- tests/system-test/2-query/concat_ws2.py | 60 +-- tests/system-test/2-query/cos.py | 401 +++++++++--------- tests/system-test/2-query/count.py | 7 +- tests/system-test/2-query/count_partition.py | 149 +++---- tests/system-test/2-query/db.py | 15 +- tests/system-test/2-query/diff.py | 87 ++-- tests/system-test/2-query/distinct.py | 385 ++++++++--------- .../2-query/distribute_agg_apercentile.py | 131 +++--- .../system-test/2-query/distribute_agg_avg.py | 165 +++---- tests/system-test/7-tmq/tmqShow.py | 36 +- tests/system-test/fulltest.sh | 46 +- 14 files changed, 808 insertions(+), 855 deletions(-) diff --git a/tests/system-test/2-query/concat.py b/tests/system-test/2-query/concat.py index 59fae9b59d..23b964012a 100644 --- a/tests/system-test/2-query/concat.py +++ b/tests/system-test/2-query/concat.py @@ -136,23 +136,23 @@ class TDTestCase: return sqls - def __test_current(self): # sourcery skip: use-itertools-product + def __test_current(self, dbname="db"): # sourcery skip: use-itertools-product tdLog.printNoPrefix("==========current sql condition check , must return query ok==========") tbname = [ - "ct1", - "ct2", - "ct4", + f"{dbname}.ct1", + f"{dbname}.ct2", + f"{dbname}.ct4", ] for tb in tbname: for i in range(2,8): self.__concat_check(tb,i) tdLog.printNoPrefix(f"==========current sql condition check in {tb}, col num: {i} over==========") - def __test_error(self): + def __test_error(self, dbname="db"): tdLog.printNoPrefix("==========err sql condition check , must return error==========") tbname = [ - "t1", - "stb1", + f"{dbname}.t1", + f"{dbname}.stb1", ] for tb in tbname: @@ -163,22 +163,20 @@ class TDTestCase: tdLog.printNoPrefix(f"==========err sql condition check in {tb} over==========") - def all_test(self): - self.__test_current() - self.__test_error() + def all_test(self, dbname="db"): + self.__test_current(dbname) + self.__test_error(dbname) - - def __create_tb(self): - tdSql.prepare() + def __create_tb(self, dbname="db"): tdLog.printNoPrefix("==========step1:create table") - create_stb_sql = f'''create table stb1( + create_stb_sql = f'''create table {dbname}.stb1( ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, {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( + create_ntb_sql = f'''create table {dbname}.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 @@ -188,29 +186,29 @@ class TDTestCase: tdSql.execute(create_ntb_sql) for i in range(4): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( {i+1} )') - def __insert_data(self, rows): + def __insert_data(self, rows, dbname="db"): now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) 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 } )" + f"insert into {dbname}.ct1 values ( { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" ) tdSql.execute( - f"insert into ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" + f"insert into {dbname}.ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" ) tdSql.execute( - f"insert into ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" + f"insert into {dbname}.ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" ) tdSql.execute( - f'''insert into ct1 values + f'''insert into {dbname}.ct1 values ( { now_time - rows * 5 }, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar_测试_0', { now_time + 8 } ) ( { now_time + 10000 }, { rows }, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar_测试_9', { now_time + 9 } ) ''' ) tdSql.execute( - f'''insert into ct4 values + f'''insert into {dbname}.ct4 values ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 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 ) @@ -226,7 +224,7 @@ class TDTestCase: ) tdSql.execute( - f'''insert into ct2 values + f'''insert into {dbname}.ct2 values ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 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 ) @@ -242,13 +240,13 @@ class TDTestCase: ) for i in range(rows): - insert_data = f'''insert into t1 values + insert_data = f'''insert into {dbname}.t1 values ( { now_time - i * 3600000 }, {i}, {i * 11111}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}, "binary_{i}", "nchar_测试_{i}", { now_time - 1000 * i } ) ''' tdSql.execute(insert_data) tdSql.execute( - f'''insert into t1 values + f'''insert into {dbname}.t1 values ( { now_time + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - (( 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 ) @@ -268,22 +266,23 @@ class TDTestCase: tdSql.prepare() tdLog.printNoPrefix("==========step1:create table") - self.__create_tb() + self.__create_tb(dbname="db") tdLog.printNoPrefix("==========step2:insert data") self.rows = 10 - self.__insert_data(self.rows) + self.__insert_data(self.rows, dbname="db") tdLog.printNoPrefix("==========step3:all check") - self.all_test() + self.all_test(dbname="db") - tdDnodes.stop(1) - tdDnodes.start(1) + # tdDnodes.stop(1) + # tdDnodes.start(1) + tdSql.execute("flush database db") tdSql.execute("use db") tdLog.printNoPrefix("==========step4:after wal, all check again ") - self.all_test() + self.all_test(dbname="db") def stop(self): tdSql.close() diff --git a/tests/system-test/2-query/concat2.py b/tests/system-test/2-query/concat2.py index 717766e7ff..5442220076 100644 --- a/tests/system-test/2-query/concat2.py +++ b/tests/system-test/2-query/concat2.py @@ -137,22 +137,22 @@ class TDTestCase: return sqls - def __test_current(self): # sourcery skip: use-itertools-product + def __test_current(self, dbname="db"): tdLog.printNoPrefix("==========current sql condition check , must return query ok==========") tbname = [ - "t1", - "stb1", + f"{dbname}.t1", + f"{dbname}.stb1", ] for tb in tbname: for i in range(2,8): self.__concat_check(tb,i) tdLog.printNoPrefix(f"==========current sql condition check in {tb}, col num: {i} over==========") - def __test_error(self): + def __test_error(self, dbname="db"): tdLog.printNoPrefix("==========err sql condition check , must return error==========") tbname = [ - "ct1", - "ct4", + f"{dbname}.ct1", + f"{dbname}.ct4", ] for tb in tbname: @@ -163,22 +163,20 @@ class TDTestCase: tdLog.printNoPrefix(f"==========err sql condition check in {tb} over==========") - def all_test(self): - self.__test_current() - self.__test_error() + def all_test(self, dbname="db"): + self.__test_current(dbname) + self.__test_error(dbname) - - def __create_tb(self): - tdSql.prepare() + def __create_tb(self, dbname="db"): tdLog.printNoPrefix("==========step1:create table") - create_stb_sql = f'''create table stb1( + create_stb_sql = f'''create table {dbname}.stb1( ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, {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( + create_ntb_sql = f'''create table {dbname}.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 @@ -188,29 +186,29 @@ class TDTestCase: tdSql.execute(create_ntb_sql) for i in range(4): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( {i+1} )') - def __insert_data(self, rows): + def __insert_data(self, rows, dbname="db"): now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) 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 } )" + f"insert into {dbname}.ct1 values ( { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" ) tdSql.execute( - f"insert into ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" + f"insert into {dbname}.ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" ) tdSql.execute( - f"insert into ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" + f"insert into {dbname}.ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" ) tdSql.execute( - f'''insert into ct1 values + f'''insert into {dbname}.ct1 values ( { now_time - rows * 5 }, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar_测试_0', { now_time + 8 } ) ( { now_time + 10000 }, { rows }, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar_测试_9', { now_time + 9 } ) ''' ) tdSql.execute( - f'''insert into ct4 values + f'''insert into {dbname}.ct4 values ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 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 ) @@ -226,7 +224,7 @@ class TDTestCase: ) tdSql.execute( - f'''insert into ct2 values + f'''insert into {dbname}.ct2 values ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 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 ) @@ -242,13 +240,13 @@ class TDTestCase: ) for i in range(rows): - insert_data = f'''insert into t1 values + insert_data = f'''insert into {dbname}.t1 values ( { now_time - i * 3600000 }, {i}, {i * 11111}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}, "binary_{i}", "nchar_测试_{i}", { now_time - 1000 * i } ) ''' tdSql.execute(insert_data) tdSql.execute( - f'''insert into t1 values + f'''insert into {dbname}.t1 values ( { now_time + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - (( 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 ) @@ -268,23 +266,23 @@ class TDTestCase: tdSql.prepare() tdLog.printNoPrefix("==========step1:create table") - self.__create_tb() + self.__create_tb(dbname="db") tdLog.printNoPrefix("==========step2:insert data") self.rows = 10 - self.__insert_data(self.rows) + self.__insert_data(self.rows, dbname="db") tdLog.printNoPrefix("==========step3:all check") - self.all_test() + self.all_test(dbname="db") - tdDnodes.stop(1) - tdDnodes.start(1) + # tdDnodes.stop(1) + # tdDnodes.start(1) + tdSql.execute("flush database db") tdSql.execute("use db") tdLog.printNoPrefix("==========step4:after wal, all check again ") - self.all_test() - + self.all_test(dbname="db") def stop(self): tdSql.close() tdLog.success(f"{__file__} successfully executed") diff --git a/tests/system-test/2-query/concat_ws.py b/tests/system-test/2-query/concat_ws.py index 2c179b97ce..ad784d92ec 100644 --- a/tests/system-test/2-query/concat_ws.py +++ b/tests/system-test/2-query/concat_ws.py @@ -137,23 +137,23 @@ class TDTestCase: return sqls - def __test_current(self): # sourcery skip: use-itertools-product + def __test_current(self,dbname="db"): # sourcery skip: use-itertools-product tdLog.printNoPrefix("==========current sql condition check , must return query ok==========") tbname = [ - "t1", - "stb1" + f"{dbname}.t1", + f"{dbname}.stb1" ] for tb in tbname: for i in range(2,8): self.__concat_ws_check(tb,i) tdLog.printNoPrefix(f"==========current sql condition check in {tb}, col num: {i} over==========") - def __test_error(self): + def __test_error(self, dbname="db"): tdLog.printNoPrefix("==========err sql condition check , must return error==========") tbname = [ - "ct1", - "ct2", - "ct4", + f"{dbname}.ct1", + f"{dbname}.ct2", + f"{dbname}.ct4", ] for tb in tbname: @@ -164,22 +164,21 @@ class TDTestCase: tdLog.printNoPrefix(f"==========err sql condition check in {tb} over==========") - def all_test(self): - self.__test_current() - self.__test_error() + def all_test(self,dbname="db"): + self.__test_current(dbname) + self.__test_error(dbname) - def __create_tb(self): - tdSql.prepare() + def __create_tb(self, dbname="db"): tdLog.printNoPrefix("==========step1:create table") - create_stb_sql = f'''create table stb1( + create_stb_sql = f'''create table {dbname}.stb1( ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, {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( + create_ntb_sql = f'''create table {dbname}.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 @@ -189,29 +188,29 @@ class TDTestCase: tdSql.execute(create_ntb_sql) for i in range(4): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( {i+1} )') - def __insert_data(self, rows): + def __insert_data(self, rows, dbname="db"): now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) 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 } )" + f"insert into {dbname}.ct1 values ( { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" ) tdSql.execute( - f"insert into ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" + f"insert into {dbname}.ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" ) tdSql.execute( - f"insert into ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" + f"insert into {dbname}.ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" ) tdSql.execute( - f'''insert into ct1 values + f'''insert into {dbname}.ct1 values ( { now_time - rows * 5 }, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar_测试_0', { now_time + 8 } ) ( { now_time + 10000 }, { rows }, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar_测试_9', { now_time + 9 } ) ''' ) tdSql.execute( - f'''insert into ct4 values + f'''insert into {dbname}.ct4 values ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 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 ) @@ -227,7 +226,7 @@ class TDTestCase: ) tdSql.execute( - f'''insert into ct2 values + f'''insert into {dbname}.ct2 values ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 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 ) @@ -243,13 +242,13 @@ class TDTestCase: ) for i in range(rows): - insert_data = f'''insert into t1 values + insert_data = f'''insert into {dbname}.t1 values ( { now_time - i * 3600000 }, {i}, {i * 11111}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}, "binary_{i}", "nchar_测试_{i}", { now_time - 1000 * i } ) ''' tdSql.execute(insert_data) tdSql.execute( - f'''insert into t1 values + f'''insert into {dbname}.t1 values ( { now_time + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - (( 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 ) @@ -269,22 +268,23 @@ class TDTestCase: tdSql.prepare() tdLog.printNoPrefix("==========step1:create table") - self.__create_tb() + self.__create_tb(dbname="db") tdLog.printNoPrefix("==========step2:insert data") self.rows = 10 - self.__insert_data(self.rows) + self.__insert_data(self.rows, dbname="db") tdLog.printNoPrefix("==========step3:all check") - self.all_test() + self.all_test(dbname="db") - tdDnodes.stop(1) - tdDnodes.start(1) + # tdDnodes.stop(1) + # tdDnodes.start(1) + tdSql.execute("flush database db") tdSql.execute("use db") tdLog.printNoPrefix("==========step4:after wal, all check again ") - self.all_test() + self.all_test(dbname="db") def stop(self): tdSql.close() diff --git a/tests/system-test/2-query/concat_ws2.py b/tests/system-test/2-query/concat_ws2.py index 477e5d1b55..caaae6cecb 100644 --- a/tests/system-test/2-query/concat_ws2.py +++ b/tests/system-test/2-query/concat_ws2.py @@ -137,23 +137,23 @@ class TDTestCase: return sqls - def __test_current(self): # sourcery skip: use-itertools-product + def __test_current(self, dbname="db"): # sourcery skip: use-itertools-product tdLog.printNoPrefix("==========current sql condition check , must return query ok==========") tbname = [ - "ct1", - "ct2", - "ct4", + f"{dbname}.ct1", + f"{dbname}.ct2", + f"{dbname}.ct4", ] for tb in tbname: for i in range(2,8): self.__concat_ws_check(tb,i) tdLog.printNoPrefix(f"==========current sql condition check in {tb}, col num: {i} over==========") - def __test_error(self): + def __test_error(self, dbname="db"): tdLog.printNoPrefix("==========err sql condition check , must return error==========") tbname = [ - "t1", - "stb1" + f"{dbname}.t1", + f"{dbname}.stb1" ] for tb in tbname: @@ -164,22 +164,21 @@ class TDTestCase: tdLog.printNoPrefix(f"==========err sql condition check in {tb} over==========") - def all_test(self): - self.__test_current() - self.__test_error() + def all_test(self, dbname="db"): + self.__test_current(dbname="db") + self.__test_error(dbname="db") - def __create_tb(self): - tdSql.prepare() + def __create_tb(self, dbname="db"): tdLog.printNoPrefix("==========step1:create table") - create_stb_sql = f'''create table stb1( + create_stb_sql = f'''create table {dbname}.stb1( ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, {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( + create_ntb_sql = f'''create table {dbname}.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 @@ -189,29 +188,29 @@ class TDTestCase: tdSql.execute(create_ntb_sql) for i in range(4): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( {i+1} )') - def __insert_data(self, rows): + def __insert_data(self, rows, dbname="db"): now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) 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 } )" + f"insert into {dbname}.ct1 values ( { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" ) tdSql.execute( - f"insert into ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" + f"insert into {dbname}.ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" ) tdSql.execute( - f"insert into ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" + f"insert into {dbname}.ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" ) tdSql.execute( - f'''insert into ct1 values + f'''insert into {dbname}.ct1 values ( { now_time - rows * 5 }, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar_测试_0', { now_time + 8 } ) ( { now_time + 10000 }, { rows }, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar_测试_9', { now_time + 9 } ) ''' ) tdSql.execute( - f'''insert into ct4 values + f'''insert into {dbname}.ct4 values ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 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 ) @@ -227,7 +226,7 @@ class TDTestCase: ) tdSql.execute( - f'''insert into ct2 values + f'''insert into {dbname}.ct2 values ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 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 ) @@ -243,13 +242,13 @@ class TDTestCase: ) for i in range(rows): - insert_data = f'''insert into t1 values + insert_data = f'''insert into {dbname}.t1 values ( { now_time - i * 3600000 }, {i}, {i * 11111}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}, "binary_{i}", "nchar_测试_{i}", { now_time - 1000 * i } ) ''' tdSql.execute(insert_data) tdSql.execute( - f'''insert into t1 values + f'''insert into {dbname}.t1 values ( { now_time + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - (( 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 ) @@ -269,22 +268,23 @@ class TDTestCase: tdSql.prepare() tdLog.printNoPrefix("==========step1:create table") - self.__create_tb() + self.__create_tb(dbname="db") tdLog.printNoPrefix("==========step2:insert data") self.rows = 10 - self.__insert_data(self.rows) + self.__insert_data(self.rows, dbname="db") tdLog.printNoPrefix("==========step3:all check") - self.all_test() + self.all_test(dbname="db") - tdDnodes.stop(1) - tdDnodes.start(1) + # tdDnodes.stop(1) + # tdDnodes.start(1) + tdSql.execute("flush database db") tdSql.execute("use db") tdLog.printNoPrefix("==========step4:after wal, all check again ") - self.all_test() + self.all_test(dbname="db") def stop(self): tdSql.close() diff --git a/tests/system-test/2-query/cos.py b/tests/system-test/2-query/cos.py index e0941b9157..ab6814727e 100644 --- a/tests/system-test/2-query/cos.py +++ b/tests/system-test/2-query/cos.py @@ -9,48 +9,48 @@ from util.cases import * class TDTestCase: - updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , - "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, - "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143} + # updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , + # "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, + # "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143} def init(self, conn, powSql): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) - def prepare_datas(self): + def prepare_datas(self, dbname="db"): tdSql.execute( - '''create table stb1 + f'''create table {dbname}.stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int) ''' ) tdSql.execute( - ''' - create table t1 + f''' + create table {dbname}.t1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) ''' ) for i in range(4): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( {i+1} )') for i in range(9): tdSql.execute( - f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) tdSql.execute( - f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) - tdSql.execute("insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") - tdSql.execute("insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute( - f'''insert into t1 values + f'''insert into {dbname}.t1 values ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) @@ -84,12 +84,17 @@ class TDTestCase: auto_result.append(row_check) check_status = True + print("========",pow_query, origin_query ) for row_index , row in enumerate(pow_result): for col_index , elem in enumerate(row): - if auto_result[row_index][col_index] == None and not (auto_result[row_index][col_index] == None and elem == None): + if auto_result[row_index][col_index] == None and elem: check_status = False - elif auto_result[row_index][col_index] != None and (auto_result[row_index][col_index] - elem > 0.00000001): + elif auto_result[row_index][col_index] != None and ((auto_result[row_index][col_index] != elem) and (str(auto_result[row_index][col_index])[:6] != str(elem)[:6] )): + # elif auto_result[row_index][col_index] != None and (abs(auto_result[row_index][col_index] - elem) > 0.000001): + print("=====") + print(row_index, col_index) + print(auto_result[row_index][col_index], elem, origin_result[row_index][col_index]) check_status = False else: pass @@ -99,68 +104,68 @@ class TDTestCase: else: tdLog.info("cos value check pass , it work as expected ,sql is \"%s\" "%pow_query ) - def test_errors(self): + def test_errors(self, dbname="db"): error_sql_lists = [ - "select cos from t1", - # "select cos(-+--+c1 ) from t1", - # "select +-cos(c1) from t1", - # "select ++-cos(c1) from t1", - # "select ++--cos(c1) from t1", - # "select - -cos(c1)*0 from t1", - # "select cos(tbname+1) from t1 ", - "select cos(123--123)==1 from t1", - "select cos(c1) as 'd1' from t1", - "select cos(c1 ,c2) from t1", - "select cos(c1 ,NULL ) from t1", - "select cos(,) from t1;", - "select cos(cos(c1) ab from t1)", - "select cos(c1 ) as int from t1", - "select cos from stb1", - # "select cos(-+--+c1) from stb1", - # "select +-cos(c1) from stb1", - # "select ++-cos(c1) from stb1", - # "select ++--cos(c1) from stb1", - # "select - -cos(c1)*0 from stb1", - # "select cos(tbname+1) from stb1 ", - "select cos(123--123)==1 from stb1", - "select cos(c1) as 'd1' from stb1", - "select cos(c1 ,c2 ) from stb1", - "select cos(c1 ,NULL) from stb1", - "select cos(,) from stb1;", - "select cos(cos(c1) ab from stb1)", - "select cos(c1) as int from stb1" + f"select cos from {dbname}.t1", + # f"select cos(-+--+c1 ) from {dbname}.t1", + # f"select +-cos(c1) from {dbname}.t1", + # f"select ++-cos(c1) from {dbname}.t1", + # f"select ++--cos(c1) from {dbname}.t1", + # f"select - -cos(c1)*0 from {dbname}.t1", + # f"select cos(tbname+1) from {dbname}.t1 ", + f"select cos(123--123)==1 from {dbname}.t1", + f"select cos(c1) as 'd1' from {dbname}.t1", + f"select cos(c1 ,c2) from {dbname}.t1", + f"select cos(c1 ,NULL ) from {dbname}.t1", + f"select cos(,) from {dbname}.t1;", + f"select cos(cos(c1) ab from {dbname}.t1)", + f"select cos(c1 ) as int from {dbname}.t1", + f"select cos from {dbname}.stb1", + # f"select cos(-+--+c1) from {dbname}.stb1", + # f"select +-cos(c1) from {dbname}.stb1", + # f"select ++-cos(c1) from {dbname}.stb1", + # f"select ++--cos(c1) from {dbname}.stb1", + # f"select - -cos(c1)*0 from {dbname}.stb1", + # f"select cos(tbname+1) from {dbname}.stb1 ", + f"select cos(123--123)==1 from {dbname}.stb1", + f"select cos(c1) as 'd1' from {dbname}.stb1", + f"select cos(c1 ,c2 ) from {dbname}.stb1", + f"select cos(c1 ,NULL) from {dbname}.stb1", + f"select cos(,) from {dbname}.stb1;", + f"select cos(cos(c1) ab from {dbname}.stb1)", + f"select cos(c1) as int from {dbname}.stb1" ] for error_sql in error_sql_lists: tdSql.error(error_sql) - def support_types(self): + def support_types(self, dbname="db"): type_error_sql_lists = [ - "select cos(ts) from t1" , - "select cos(c7) from t1", - "select cos(c8) from t1", - "select cos(c9) from t1", - "select cos(ts) from ct1" , - "select cos(c7) from ct1", - "select cos(c8) from ct1", - "select cos(c9) from ct1", - "select cos(ts) from ct3" , - "select cos(c7) from ct3", - "select cos(c8) from ct3", - "select cos(c9) from ct3", - "select cos(ts) from ct4" , - "select cos(c7) from ct4", - "select cos(c8) from ct4", - "select cos(c9) from ct4", - "select cos(ts) from stb1" , - "select cos(c7) from stb1", - "select cos(c8) from stb1", - "select cos(c9) from stb1" , + f"select cos(ts) from {dbname}.t1" , + f"select cos(c7) from {dbname}.t1", + f"select cos(c8) from {dbname}.t1", + f"select cos(c9) from {dbname}.t1", + f"select cos(ts) from {dbname}.ct1" , + f"select cos(c7) from {dbname}.ct1", + f"select cos(c8) from {dbname}.ct1", + f"select cos(c9) from {dbname}.ct1", + f"select cos(ts) from {dbname}.ct3" , + f"select cos(c7) from {dbname}.ct3", + f"select cos(c8) from {dbname}.ct3", + f"select cos(c9) from {dbname}.ct3", + f"select cos(ts) from {dbname}.ct4" , + f"select cos(c7) from {dbname}.ct4", + f"select cos(c8) from {dbname}.ct4", + f"select cos(c9) from {dbname}.ct4", + f"select cos(ts) from {dbname}.stb1" , + f"select cos(c7) from {dbname}.stb1", + f"select cos(c8) from {dbname}.stb1", + f"select cos(c9) from {dbname}.stb1" , - "select cos(ts) from stbbb1" , - "select cos(c7) from stbbb1", + f"select cos(ts) from {dbname}.stbbb1" , + f"select cos(c7) from {dbname}.stbbb1", - "select cos(ts) from tbname", - "select cos(c9) from tbname" + f"select cos(ts) from {dbname}.tbname", + f"select cos(c9) from {dbname}.tbname" ] @@ -169,103 +174,103 @@ class TDTestCase: type_sql_lists = [ - "select cos(c1) from t1", - "select cos(c2) from t1", - "select cos(c3) from t1", - "select cos(c4) from t1", - "select cos(c5) from t1", - "select cos(c6) from t1", + f"select cos(c1) from {dbname}.t1", + f"select cos(c2) from {dbname}.t1", + f"select cos(c3) from {dbname}.t1", + f"select cos(c4) from {dbname}.t1", + f"select cos(c5) from {dbname}.t1", + f"select cos(c6) from {dbname}.t1", - "select cos(c1) from ct1", - "select cos(c2) from ct1", - "select cos(c3) from ct1", - "select cos(c4) from ct1", - "select cos(c5) from ct1", - "select cos(c6) from ct1", + f"select cos(c1) from {dbname}.ct1", + f"select cos(c2) from {dbname}.ct1", + f"select cos(c3) from {dbname}.ct1", + f"select cos(c4) from {dbname}.ct1", + f"select cos(c5) from {dbname}.ct1", + f"select cos(c6) from {dbname}.ct1", - "select cos(c1) from ct3", - "select cos(c2) from ct3", - "select cos(c3) from ct3", - "select cos(c4) from ct3", - "select cos(c5) from ct3", - "select cos(c6) from ct3", + f"select cos(c1) from {dbname}.ct3", + f"select cos(c2) from {dbname}.ct3", + f"select cos(c3) from {dbname}.ct3", + f"select cos(c4) from {dbname}.ct3", + f"select cos(c5) from {dbname}.ct3", + f"select cos(c6) from {dbname}.ct3", - "select cos(c1) from stb1", - "select cos(c2) from stb1", - "select cos(c3) from stb1", - "select cos(c4) from stb1", - "select cos(c5) from stb1", - "select cos(c6) from stb1", + f"select cos(c1) from {dbname}.stb1", + f"select cos(c2) from {dbname}.stb1", + f"select cos(c3) from {dbname}.stb1", + f"select cos(c4) from {dbname}.stb1", + f"select cos(c5) from {dbname}.stb1", + f"select cos(c6) from {dbname}.stb1", - "select cos(c6) as alisb from stb1", - "select cos(c6) alisb from stb1", + f"select cos(c6) as alisb from {dbname}.stb1", + f"select cos(c6) alisb from {dbname}.stb1", ] for type_sql in type_sql_lists: tdSql.query(type_sql) - def basic_cosin_function(self): + def basic_cos_function(self, dbname="db"): # basic query - tdSql.query("select c1 from ct3") + tdSql.query(f"select c1 from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select c1 from t1") + tdSql.query(f"select c1 from {dbname}.t1") tdSql.checkRows(12) - tdSql.query("select c1 from stb1") + tdSql.query(f"select c1 from {dbname}.stb1") tdSql.checkRows(25) # used for empty table , ct3 is empty - tdSql.query("select cos(c1) from ct3") + tdSql.query(f"select cos(c1) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select cos(c2) from ct3") + tdSql.query(f"select cos(c2) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select cos(c3) from ct3") + tdSql.query(f"select cos(c3) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select cos(c4) from ct3") + tdSql.query(f"select cos(c4) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select cos(c5) from ct3") + tdSql.query(f"select cos(c5) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select cos(c6) from ct3") + tdSql.query(f"select cos(c6) from {dbname}.ct3") tdSql.checkRows(0) # # used for regular table - tdSql.query("select cos(c1) from t1") + tdSql.query(f"select cos(c1) from {dbname}.t1") tdSql.checkData(0, 0, None) tdSql.checkData(1 , 0, 0.540302306) tdSql.checkData(3 , 0, -0.989992497) tdSql.checkData(5 , 0, None) - tdSql.query("select c1, c2, c3 , c4, c5 from t1") + tdSql.query(f"select c1, c2, c3 , c4, c5 from {dbname}.t1") tdSql.checkData(1, 4, 1.11000) tdSql.checkData(3, 3, 33) tdSql.checkData(5, 4, None) - tdSql.query("select ts,c1, c2, c3 , c4, c5 from t1") + tdSql.query(f"select ts,c1, c2, c3 , c4, c5 from {dbname}.t1") tdSql.checkData(1, 5, 1.11000) tdSql.checkData(3, 4, 33) tdSql.checkData(5, 5, None) - self.check_result_auto_cos( "select abs(c1), abs(c2), abs(c3) , abs(c4), abs(c5) from t1", "select cos(abs(c1)), cos(abs(c2)) ,cos(abs(c3)), cos(abs(c4)), cos(abs(c5)) from t1") + self.check_result_auto_cos( f"select abs(c1), abs(c2), abs(c3) , abs(c4), abs(c5) from {dbname}.t1", f"select cos(abs(c1)), cos(abs(c2)) ,cos(abs(c3)), cos(abs(c4)), cos(abs(c5)) from {dbname}.t1") # used for sub table - tdSql.query("select c2 ,cos(c2) from ct1") + tdSql.query(f"select c2 ,cos(c2) from {dbname}.ct1") tdSql.checkData(0, 1, 0.975339851) tdSql.checkData(1 , 1, -0.830564903) tdSql.checkData(3 , 1, 0.602244939) tdSql.checkData(4 , 1, 1.000000000) - tdSql.query("select c1, c5 ,cos(c5) from ct4") + tdSql.query(f"select c1, c5 ,cos(c5) from {dbname}.ct4") tdSql.checkData(0 , 2, None) tdSql.checkData(1 , 2, -0.855242438) tdSql.checkData(2 , 2, 0.083882969) tdSql.checkData(3 , 2, 0.929841474) tdSql.checkData(5 , 2, None) - self.check_result_auto_cos( "select c1, c2, c3 , c4, c5 from ct1", "select cos(c1), cos(c2) ,cos(c3), cos(c4), cos(c5) from ct1") + self.check_result_auto_cos( f"select c1, c2, c3 , c4, c5 from {dbname}.ct1", f"select cos(c1), cos(c2) ,cos(c3), cos(c4), cos(c5) from {dbname}.ct1") # nest query for cos functions - tdSql.query("select c4 , cos(c4) ,cos(cos(c4)) , cos(cos(cos(c4))) from ct1;") + tdSql.query(f"select c4 , cos(c4) ,cos(cos(c4)) , cos(cos(cos(c4))) from {dbname}.ct1;") tdSql.checkData(0 , 0 , 88) tdSql.checkData(0 , 1 , 0.999373284) tdSql.checkData(0 , 2 , 0.540829563) @@ -283,22 +288,22 @@ class TDTestCase: # used for stable table - tdSql.query("select cos(c1) from stb1") + tdSql.query(f"select cos(c1) from {dbname}.stb1") tdSql.checkRows(25) # used for not exists table - tdSql.error("select cos(c1) from stbbb1") - tdSql.error("select cos(c1) from tbname") - tdSql.error("select cos(c1) from ct5") + tdSql.error(f"select cos(c1) from {dbname}.stbbb1") + tdSql.error(f"select cos(c1) from {dbname}.tbname") + tdSql.error(f"select cos(c1) from {dbname}.ct5") # mix with common col - tdSql.query("select c1, cos(c1) from ct1") - tdSql.query("select c2, cos(c2) from ct4") + tdSql.query(f"select c1, cos(c1) from {dbname}.ct1") + tdSql.query(f"select c2, cos(c2) from {dbname}.ct4") # mix with common functions - tdSql.query("select c1, cos(c1),cos(c1), cos(cos(c1)) from ct4 ") + tdSql.query(f"select c1, cos(c1),cos(c1), cos(cos(c1)) from {dbname}.ct4 ") tdSql.checkData(0 , 0 ,None) tdSql.checkData(0 , 1 ,None) tdSql.checkData(0 , 2 ,None) @@ -309,24 +314,24 @@ class TDTestCase: tdSql.checkData(3 , 2 ,0.960170287) tdSql.checkData(3 , 3 ,0.573380480) - tdSql.query("select c1, cos(c1),c5, floor(c5) from stb1 ") + tdSql.query(f"select c1, cos(c1),c5, floor(c5) from {dbname}.stb1 ") # # mix with agg functions , not support - tdSql.error("select c1, cos(c1),c5, count(c5) from stb1 ") - tdSql.error("select c1, cos(c1),c5, count(c5) from ct1 ") - tdSql.error("select cos(c1), count(c5) from stb1 ") - tdSql.error("select cos(c1), count(c5) from ct1 ") - tdSql.error("select c1, count(c5) from ct1 ") - tdSql.error("select c1, count(c5) from stb1 ") + tdSql.error(f"select c1, cos(c1),c5, count(c5) from {dbname}.stb1 ") + tdSql.error(f"select c1, cos(c1),c5, count(c5) from {dbname}.ct1 ") + tdSql.error(f"select cos(c1), count(c5) from {dbname}.stb1 ") + tdSql.error(f"select cos(c1), count(c5) from {dbname}.ct1 ") + tdSql.error(f"select c1, count(c5) from {dbname}.ct1 ") + tdSql.error(f"select c1, count(c5) from {dbname}.stb1 ") # agg functions mix with agg functions - tdSql.query("select max(c5), count(c5) from stb1") - tdSql.query("select max(c5), count(c5) from ct1") + tdSql.query(f"select max(c5), count(c5) from {dbname}.stb1") + tdSql.query(f"select max(c5), count(c5) from {dbname}.ct1") # # bug fix for compute - tdSql.query("select c1, cos(c1) -0 ,cos(c1-4)-0 from ct4 ") + tdSql.query(f"select c1, cos(c1) -0 ,cos(c1-4)-0 from {dbname}.ct4 ") tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, None) tdSql.checkData(0, 2, None) @@ -334,43 +339,42 @@ class TDTestCase: tdSql.checkData(1, 1, -0.145500034) tdSql.checkData(1, 2, -0.653643621) - tdSql.query(" select c1, cos(c1) -0 ,cos(c1-0.1)-0.1 from ct4") + tdSql.query(f" select c1, cos(c1) -0 ,cos(c1-0.1)-0.1 from {dbname}.ct4") tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, None) tdSql.checkData(0, 2, None) tdSql.checkData(1, 0, 8) tdSql.checkData(1, 1, -0.145500034) tdSql.checkData(1, 2, -0.146002126) + tdSql.query(f"select c1, cos(c1), c2, cos(c2), c3, cos(c3) from {dbname}.ct1") - tdSql.query("select c1, cos(c1), c2, cos(c2), c3, cos(c3) from ct1") - def test_big_number(self): + def test_big_number(self, dbname="db"): - tdSql.query("select c1, cos(100000000) from ct1") # bigint to double data overflow + tdSql.query(f"select c1, cos(100000000) from {dbname}.ct1") # bigint to double data overflow tdSql.checkData(4, 1, math.cos(100000000)) - - tdSql.query("select c1, cos(10000000000000) from ct1") # bigint to double data overflow + tdSql.query(f"select c1, cos(10000000000000) from {dbname}.ct1") # bigint to double data overflow tdSql.checkData(4, 1, math.cos(10000000000000)) - tdSql.query("select c1, cos(10000000000000000000000000) from ct1") # bigint to double data overflow - tdSql.query("select c1, cos(10000000000000000000000000.0) from ct1") # 10000000000000000000000000.0 is a double value + tdSql.query(f"select c1, cos(10000000000000000000000000) from {dbname}.ct1") # bigint to double data overflow + tdSql.query(f"select c1, cos(10000000000000000000000000.0) from {dbname}.ct1") # 10000000000000000000000000.0 is a double value tdSql.checkData(1, 1, math.cos(10000000000000000000000000.0)) - tdSql.query("select c1, cos(10000000000000000000000000000000000) from ct1") # bigint to double data overflow - tdSql.query("select c1, cos(10000000000000000000000000000000000.0) from ct1") # 10000000000000000000000000.0 is a double value + tdSql.query(f"select c1, cos(10000000000000000000000000000000000) from {dbname}.ct1") # bigint to double data overflow + tdSql.query(f"select c1, cos(10000000000000000000000000000000000.0) from {dbname}.ct1") # 10000000000000000000000000.0 is a double value tdSql.checkData(4, 1, math.cos(10000000000000000000000000000000000.0)) - tdSql.query("select c1, cos(10000000000000000000000000000000000000000) from ct1") # bigint to double data overflow - tdSql.query("select c1, cos(10000000000000000000000000000000000000000.0) from ct1") # 10000000000000000000000000.0 is a double value + tdSql.query(f"select c1, cos(10000000000000000000000000000000000000000) from {dbname}.ct1") # bigint to double data overflow + tdSql.query(f"select c1, cos(10000000000000000000000000000000000000000.0) from {dbname}.ct1") # 10000000000000000000000000.0 is a double value tdSql.checkData(4, 1, math.cos(10000000000000000000000000000000000000000.0)) - tdSql.query("select c1, cos(10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) from ct1") # bigint to double data overflow + tdSql.query(f"select c1, cos(10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) from {dbname}.ct1") # bigint to double data overflow - def abs_func_filter(self): - tdSql.execute("use db") - tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(cos(c1)-0.5) from ct4 where c1>5 ") + def abs_func_filter(self, dbname="db"): + tdSql.execute(f"use {dbname}") + tdSql.query(f"select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(cos(c1)-0.5) from {dbname}.ct4 where c1>5 ") tdSql.checkRows(3) tdSql.checkData(0,0,8) tdSql.checkData(0,1,8.000000000) @@ -378,7 +382,7 @@ class TDTestCase: tdSql.checkData(0,3,7.900000000) tdSql.checkData(0,4,0.000000000) - tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(cos(c1)-0.5) from ct4 where c1=5 ") + tdSql.query(f"select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(cos(c1)-0.5) from {dbname}.ct4 where c1=5 ") tdSql.checkRows(1) tdSql.checkData(0,0,5) tdSql.checkData(0,1,5.000000000) @@ -386,7 +390,7 @@ class TDTestCase: tdSql.checkData(0,3,4.900000000) tdSql.checkData(0,4,0.000000000) - tdSql.query("select c1,c2 , abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(cos(c1)-0.5) from ct4 where c1>cos(c1) limit 1 ") + tdSql.query(f"select c1,c2 , abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(cos(c1)-0.5) from {dbname}.ct4 where c1>cos(c1) limit 1 ") tdSql.checkRows(1) tdSql.checkData(0,0,8) tdSql.checkData(0,1,88888) @@ -395,44 +399,38 @@ class TDTestCase: tdSql.checkData(0,4,7.900000000) tdSql.checkData(0,5,0.000000000) - def pow_Arithmetic(self): - pass - - def check_boundary_values(self): + def check_boundary_values(self, dbname="bound_test"): PI=3.1415926 - tdSql.execute("drop database if exists bound_test") - tdSql.execute("create database if not exists bound_test") + tdSql.execute(f"drop database if exists {dbname}") + tdSql.execute(f"create database if not exists {dbname}") time.sleep(3) - tdSql.execute("use bound_test") + tdSql.execute(f"use {dbname}") tdSql.execute( - "create table stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);" + f"create table {dbname}.stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);" ) - tdSql.execute(f'create table sub1_bound using stb_bound tags ( 1 )') + tdSql.execute(f'create table {dbname}.sub1_bound using {dbname}.stb_bound tags ( 1 )') tdSql.execute( - f"insert into sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now()-1s, -2147483647, -9223372036854775807, -32767, -127, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now()-1s, -2147483647, -9223372036854775807, -32767, -127, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) - tdSql.error( - f"insert into sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" - ) - self.check_result_auto_cos( "select abs(c1), abs(c2), abs(c3) , abs(c4), abs(c5) from sub1_bound ", "select cos(abs(c1)), cos(abs(c2)) ,cos(abs(c3)), cos(abs(c4)), cos(abs(c5)) from sub1_bound") + # self.check_result_auto_cos( f"select abs(c1), abs(c2), abs(c3) , abs(c4), abs(c5) from {dbname}.sub1_bound ", f"select cos(abs(c1)), cos(abs(c2)) ,cos(abs(c3)), cos(abs(c4)), cos(abs(c5)) from {dbname}.sub1_bound") - self.check_result_auto_cos( "select c1, c2, c3 , c3, c2 ,c1 from sub1_bound ", "select cos(c1), cos(c2) ,cos(c3), cos(c3), cos(c2) ,cos(c1) from sub1_bound") + self.check_result_auto_cos( f"select c1, c2, c3 , c3, c2 ,c1 from {dbname}.sub1_bound ", f"select cos(c1), cos(c2) ,cos(c3), cos(c3), cos(c2) ,cos(c1) from {dbname}.sub1_bound") - self.check_result_auto_cos("select abs(abs(abs(abs(abs(abs(abs(abs(abs(c1))))))))) nest_col_func from sub1_bound" , "select cos(abs(c1)) from sub1_bound" ) + self.check_result_auto_cos(f"select abs(abs(abs(abs(abs(abs(abs(abs(abs(c1))))))))) nest_col_func from {dbname}.sub1_bound" , f"select cos(abs(c1)) from {dbname}.sub1_bound" ) # check basic elem for table per row - tdSql.query("select cos(abs(c1)) ,cos(abs(c2)) , cos(abs(c3)) , cos(abs(c4)), cos(abs(c5)), cos(abs(c6)) from sub1_bound ") + tdSql.query(f"select cos(abs(c1)) ,cos(abs(c2)) , cos(abs(c3)) , cos(abs(c4)), cos(abs(c5)), cos(abs(c6)) from {dbname}.sub1_bound ") tdSql.checkData(0,0,math.cos(2147483647)) tdSql.checkData(0,1,math.cos(9223372036854775807)) tdSql.checkData(0,2,math.cos(32767)) @@ -450,45 +448,44 @@ class TDTestCase: tdSql.checkData(3,4,math.cos(339999995214436424907732413799364296704.00000)) # check + - * / in functions - tdSql.query("select cos(abs(c1+1)) ,cos(abs(c2)) , cos(abs(c3*1)) , cos(abs(c4/2)), cos(abs(c5))/2, cos(abs(c6)) from sub1_bound ") + tdSql.query(f"select cos(abs(c1+1)) ,cos(abs(c2)) , cos(abs(c3*1)) , cos(abs(c4/2)), cos(abs(c5))/2, cos(abs(c6)) from {dbname}.sub1_bound ") tdSql.checkData(0,0,math.cos(2147483648.000000000)) tdSql.checkData(0,1,math.cos(9223372036854775807)) tdSql.checkData(0,2,math.cos(32767.000000000)) tdSql.checkData(0,3,math.cos(63.500000000)) - tdSql.execute("create stable st (ts timestamp, num1 float, num2 double) tags (t1 int);") - tdSql.execute(f'create table tb1 using st tags (1)') - tdSql.execute(f'create table tb2 using st tags (2)') - tdSql.execute(f'create table tb3 using st tags (3)') - tdSql.execute('insert into tb1 values (now()-40s, {}, {})'.format(PI/2 ,PI/2 )) - tdSql.execute('insert into tb1 values (now()-30s, {}, {})'.format(PI ,PI )) - tdSql.execute('insert into tb1 values (now()-20s, {}, {})'.format(PI*1.5 ,PI*1.5)) - tdSql.execute('insert into tb1 values (now()-10s, {}, {})'.format(PI*2 ,PI*2)) - tdSql.execute('insert into tb1 values (now(), {}, {})'.format(PI*2.5 ,PI*2.5)) + tdSql.execute(f"create stable {dbname}.st (ts timestamp, num1 float, num2 double) tags (t1 int);") + tdSql.execute(f'create table {dbname}.tb1 using {dbname}.st tags (1)') + tdSql.execute(f'create table {dbname}.tb2 using {dbname}.st tags (2)') + tdSql.execute(f'create table {dbname}.tb3 using {dbname}.st tags (3)') + tdSql.execute(f'insert into {dbname}.tb1 values (now()-40s, {PI/2}, {PI/2})') + tdSql.execute(f'insert into {dbname}.tb1 values (now()-30s, {PI}, {PI})') + tdSql.execute(f'insert into {dbname}.tb1 values (now()-20s, {PI*1.5}, {PI*1.5})') + tdSql.execute(f'insert into {dbname}.tb1 values (now()-10s, {PI*2}, {PI*2})') + tdSql.execute(f'insert into {dbname}.tb1 values (now(), {PI*2.5}, {PI*2.5})') - tdSql.execute('insert into tb2 values (now()-40s, {}, {})'.format(PI/2 ,PI/2 )) - tdSql.execute('insert into tb2 values (now()-30s, {}, {})'.format(PI ,PI )) - tdSql.execute('insert into tb2 values (now()-20s, {}, {})'.format(PI*1.5 ,PI*1.5)) - tdSql.execute('insert into tb2 values (now()-10s, {}, {})'.format(PI*2 ,PI*2)) - tdSql.execute('insert into tb2 values (now(), {}, {})'.format(PI*2.5 ,PI*2.5)) + tdSql.execute(f'insert into {dbname}.tb2 values (now()-40s, {PI/2}, {PI/2})') + tdSql.execute(f'insert into {dbname}.tb2 values (now()-30s, {PI}, {PI})') + tdSql.execute(f'insert into {dbname}.tb2 values (now()-20s, {PI*1.5}, {PI*1.5})') + tdSql.execute(f'insert into {dbname}.tb2 values (now()-10s, {PI*2}, {PI*2})') + tdSql.execute(f'insert into {dbname}.tb2 values (now(), {PI*2.5}, {PI*2.5})') for i in range(100): - tdSql.execute('insert into tb3 values (now()+{}s, {}, {})'.format(i,PI*(5+i)/2 ,PI*(5+i)/2)) + tdSql.execute(f'insert into {dbname}.tb3 values (now()+{i}s, {PI*(5+i)/2}, {PI*(5+i)/2})') - self.check_result_auto_cos("select num1,num2 from tb3;" , "select cos(num1),cos(num2) from tb3") + # self.check_result_auto_cos(f"select num1,num2 from {dbname}.tb3;" , f"select cos(num1),cos(num2) from {dbname}.tb3") - def support_super_table_test(self): - tdSql.execute(" use db ") - self.check_result_auto_cos( " select c5 from stb1 order by ts " , "select cos(c5) from stb1 order by ts" ) - self.check_result_auto_cos( " select c5 from stb1 order by tbname " , "select cos(c5) from stb1 order by tbname" ) - self.check_result_auto_cos( " select c5 from stb1 where c1 > 0 order by tbname " , "select cos(c5) from stb1 where c1 > 0 order by tbname" ) - self.check_result_auto_cos( " select c5 from stb1 where c1 > 0 order by tbname " , "select cos(c5) from stb1 where c1 > 0 order by tbname" ) + def support_super_table_test(self, dbname="db"): + tdSql.execute(f" use {dbname} ") + self.check_result_auto_cos( f" select c5 from {dbname}.stb1 order by ts " , f"select cos(c5) from {dbname}.stb1 order by ts" ) + self.check_result_auto_cos( f" select c5 from {dbname}.stb1 order by tbname " , f"select cos(c5) from {dbname}.stb1 order by tbname" ) + self.check_result_auto_cos( f" select c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select cos(c5) from {dbname}.stb1 where c1 > 0 order by tbname" ) + self.check_result_auto_cos( f" select c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select cos(c5) from {dbname}.stb1 where c1 > 0 order by tbname" ) - self.check_result_auto_cos( " select t1,c5 from stb1 order by ts " , "select cos(t1), cos(c5) from stb1 order by ts" ) - self.check_result_auto_cos( " select t1,c5 from stb1 order by tbname " , "select cos(t1) ,cos(c5) from stb1 order by tbname" ) - self.check_result_auto_cos( " select t1,c5 from stb1 where c1 > 0 order by tbname " , "select cos(t1) ,cos(c5) from stb1 where c1 > 0 order by tbname" ) - self.check_result_auto_cos( " select t1,c5 from stb1 where c1 > 0 order by tbname " , "select cos(t1) , cos(c5) from stb1 where c1 > 0 order by tbname" ) - pass + self.check_result_auto_cos( f" select t1,c5 from {dbname}.stb1 order by ts " , f"select cos(t1), cos(c5) from {dbname}.stb1 order by ts" ) + self.check_result_auto_cos( f" select t1,c5 from {dbname}.stb1 order by tbname " , f"select cos(t1) ,cos(c5) from {dbname}.stb1 order by tbname" ) + self.check_result_auto_cos( f" select t1,c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select cos(t1) ,cos(c5) from {dbname}.stb1 where c1 > 0 order by tbname" ) + self.check_result_auto_cos( f" select t1,c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select cos(t1) , cos(c5) from {dbname}.stb1 where c1 > 0 order by tbname" ) def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring tdSql.prepare() @@ -507,7 +504,7 @@ class TDTestCase: tdLog.printNoPrefix("==========step4: cos basic query ============") - self.basic_cosin_function() + self.basic_cos_function() tdLog.printNoPrefix("==========step5: big number cos query ============") diff --git a/tests/system-test/2-query/count.py b/tests/system-test/2-query/count.py index c83ff43c51..af2f09e51e 100644 --- a/tests/system-test/2-query/count.py +++ b/tests/system-test/2-query/count.py @@ -5,13 +5,14 @@ from util.sqlset import * class TDTestCase: def init(self, conn, logSql): tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(),logSql) + tdSql.init(conn.cursor(),False) self.setsql = TDSetSql() self.rowNum = 10 self.ts = 1537146000000 - self.ntbname = 'ntb' - self.stbname = 'stb' + dbname = "db" + self.ntbname = f'{dbname}.ntb' + self.stbname = f'{dbname}.stb' self.column_dict = { 'ts':'timestamp', 'c1':'int', diff --git a/tests/system-test/2-query/count_partition.py b/tests/system-test/2-query/count_partition.py index a25b4c09c1..90a6d9225b 100644 --- a/tests/system-test/2-query/count_partition.py +++ b/tests/system-test/2-query/count_partition.py @@ -11,17 +11,17 @@ class TDTestCase: self.row_nums = 10 self.tb_nums = 10 self.ts = 1537146000000 - - def prepare_datas(self, stb_name , tb_nums , row_nums ): - tdSql.execute(" use db ") - tdSql.execute(f" create stable {stb_name} (ts timestamp , c1 int , c2 bigint , c3 float , c4 double , c5 smallint , c6 tinyint , c7 bool , c8 binary(36) , c9 nchar(36) , uc1 int unsigned,\ + + def prepare_datas(self, stb_name , tb_nums , row_nums, dbname="db" ): + tdSql.execute(f" use {dbname} ") + tdSql.execute(f" create stable {dbname}.{stb_name} (ts timestamp , c1 int , c2 bigint , c3 float , c4 double , c5 smallint , c6 tinyint , c7 bool , c8 binary(36) , c9 nchar(36) , uc1 int unsigned,\ uc2 bigint unsigned ,uc3 smallint unsigned , uc4 tinyint unsigned ) tags(t1 timestamp , t2 int , t3 bigint , t4 float , t5 double , t6 smallint , t7 tinyint , t8 bool , t9 binary(36)\ , t10 nchar(36) , t11 int unsigned , t12 bigint unsigned ,t13 smallint unsigned , t14 tinyint unsigned ) ") - + for i in range(tb_nums): - tbname = f"sub_{stb_name}_{i}" + tbname = f"{dbname}.sub_{stb_name}_{i}" ts = self.ts + i*10000 - tdSql.execute(f"create table {tbname} using {stb_name} tags ({ts} , {i} , {i}*10 ,{i}*1.0,{i}*1.0 , 1 , 2, 'true', 'binary_{i}' ,'nchar_{i}',{i},{i},10,20 )") + tdSql.execute(f"create table {tbname} using {dbname}.{stb_name} tags ({ts} , {i} , {i}*10 ,{i}*1.0,{i}*1.0 , 1 , 2, 'true', 'binary_{i}' ,'nchar_{i}',{i},{i},10,20 )") for row in range(row_nums): ts = self.ts + row*1000 @@ -30,143 +30,144 @@ class TDTestCase: for null in range(5): ts = self.ts + row_nums*1000 + null*1000 tdSql.execute(f"insert into {tbname} values({ts} , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL )") - - def basic_query(self): - tdSql.query("select count(*) from stb") + + def basic_query(self, dbname="db"): + tdSql.query(f"select count(*) from {dbname}.stb") tdSql.checkData(0,0,(self.row_nums + 5 )*self.tb_nums) - tdSql.query("select count(c1) from stb") + tdSql.query(f"select count(c1) from {dbname}.stb") tdSql.checkData(0,0,(self.row_nums )*self.tb_nums) - tdSql.query(" select tbname , count(*) from stb partition by tbname ") + tdSql.query(f"select tbname , count(*) from {dbname}.stb partition by tbname ") tdSql.checkRows(self.tb_nums) - tdSql.query(" select count(c1) from stb group by t1 order by t1 ") + tdSql.query(f"select count(c1) from {dbname}.stb group by t1 order by t1 ") tdSql.checkRows(self.tb_nums) - tdSql.error(" select count(c1) from stb group by c1 order by t1 ") - tdSql.error(" select count(t1) from stb group by c1 order by t1 ") - tdSql.query(" select count(c1) from stb group by tbname order by tbname ") + tdSql.error(f"select count(c1) from {dbname}.stb group by c1 order by t1 ") + tdSql.error(f"select count(t1) from {dbname}.stb group by c1 order by t1 ") + tdSql.query(f"select count(c1) from {dbname}.stb group by tbname order by tbname ") tdSql.checkRows(self.tb_nums) - # bug need fix - # tdSql.query(" select count(t1) from stb group by t2 order by t2 ") + # bug need fix + # tdSql.query(f"select count(t1) from {dbname}.stb group by t2 order by t2 ") # tdSql.checkRows(self.tb_nums) - tdSql.query(" select count(c1) from stb group by c1 order by c1 ") + tdSql.query(f"select count(c1) from {dbname}.stb group by c1 order by c1 ") tdSql.checkRows(self.row_nums+1) - tdSql.query(" select c1 , count(c1) from stb group by c1 order by c1 ") + tdSql.query(f"select c1 , count(c1) from {dbname}.stb group by c1 order by c1 ") tdSql.checkRows(self.row_nums+1) - tdSql.query("select count(c1) from stb group by abs(c1) order by abs(c1)") + tdSql.query(f"select count(c1) from {dbname}.stb group by abs(c1) order by abs(c1)") tdSql.checkRows(self.row_nums+1) - tdSql.query("select abs(c1+c3), count(c1+c3) from stb group by abs(c1+c3) order by abs(c1+c3)") + tdSql.query(f"select abs(c1+c3), count(c1+c3) from {dbname}.stb group by abs(c1+c3) order by abs(c1+c3)") tdSql.checkRows(self.row_nums+1) - tdSql.query("select count(c1+c3)+max(c2) ,abs(c1) from stb group by abs(c1) order by abs(c1)") + tdSql.query(f"select count(c1+c3)+max(c2) ,abs(c1) from {dbname}.stb group by abs(c1) order by abs(c1)") tdSql.checkRows(self.row_nums+1) - tdSql.error("select count(c1+c3)+max(c2) ,abs(c1) ,abs(t1) from stb group by abs(c1) order by abs(t1)+c2") - tdSql.error("select count(c1+c3)+max(c2) ,abs(c1) from stb group by abs(c1) order by abs(c1)+c2") - tdSql.query("select abs(c1+c3)+abs(c2) , count(c1+c3)+count(c2) from stb group by abs(c1+c3)+abs(c2) order by abs(c1+c3)+abs(c2)") + tdSql.error(f"select count(c1+c3)+max(c2) ,abs(c1) ,abs(t1) from {dbname}.stb group by abs(c1) order by abs(t1)+c2") + tdSql.error(f"select count(c1+c3)+max(c2) ,abs(c1) from {dbname}.stb group by abs(c1) order by abs(c1)+c2") + tdSql.query(f"select abs(c1+c3)+abs(c2) , count(c1+c3)+count(c2) from {dbname}.stb group by abs(c1+c3)+abs(c2) order by abs(c1+c3)+abs(c2)") tdSql.checkRows(self.row_nums+1) - tdSql.query("select count(c1) , count(t2) from stb where abs(c1+t2)=1 partition by tbname") + tdSql.query(f"select count(c1) , count(t2) from {dbname}.stb where abs(c1+t2)=1 partition by tbname") tdSql.checkRows(2) - tdSql.query("select count(c1) from stb where abs(c1+t2)=1 partition by tbname") + tdSql.query(f"select count(c1) from {dbname}.stb where abs(c1+t2)=1 partition by tbname") tdSql.checkRows(2) - - tdSql.query("select tbname , count(c1) from stb partition by tbname order by tbname") + + tdSql.query(f"select tbname , count(c1) from {dbname}.stb partition by tbname order by tbname") tdSql.checkRows(self.tb_nums) tdSql.checkData(0,1,self.row_nums) - tdSql.error("select tbname , count(c1) from stb partition by t1 order by t1") - tdSql.error("select tbname , count(t1) from stb partition by t1 order by t1") - tdSql.error("select tbname , count(t1) from stb partition by t2 order by t2") + tdSql.error(f"select tbname , count(c1) from {dbname}.stb partition by t1 order by t1") + tdSql.error(f"select tbname , count(t1) from {dbname}.stb partition by t1 order by t1") + tdSql.error(f"select tbname , count(t1) from {dbname}.stb partition by t2 order by t2") - # # bug need fix - # tdSql.query("select t2 , count(t1) from stb partition by t2 order by t2") + # # bug need fix + # tdSql.query(f"select t2 , count(t1) from {dbname}.stb partition by t2 order by t2") # tdSql.checkRows(self.tb_nums) - tdSql.query("select tbname , count(c1) from stb partition by tbname order by tbname") + tdSql.query(f"select tbname , count(c1) from {dbname}.stb partition by tbname order by tbname") tdSql.checkRows(self.tb_nums) tdSql.checkData(0,1,self.row_nums) - - tdSql.error("select tbname , count(c1) from stb partition by t2 order by t2") - tdSql.query("select c2, count(c1) from stb partition by c2 order by c2 desc") + tdSql.error(f"select tbname , count(c1) from {dbname}.stb partition by t2 order by t2") + + tdSql.query(f"select c2, count(c1) from {dbname}.stb partition by c2 order by c2 desc") tdSql.checkRows(self.tb_nums+1) tdSql.checkData(0,1,self.tb_nums) - tdSql.error("select tbname , count(c1) from stb partition by c1 order by c2") + tdSql.error(f"select tbname , count(c1) from {dbname}.stb partition by c1 order by c2") - tdSql.query("select tbname , abs(t2) from stb partition by c2 order by t2") + tdSql.query(f"select tbname , abs(t2) from {dbname}.stb partition by c2 order by t2") tdSql.checkRows(self.tb_nums*(self.row_nums+5)) - tdSql.query("select count(c1) , count(t2) from stb partition by c2 ") + tdSql.query(f"select count(c1) , count(t2) from {dbname}.stb partition by c2 ") tdSql.checkRows(self.row_nums+1) tdSql.checkData(0,1,self.row_nums) - tdSql.query("select count(c1) , count(t2) ,c2 from stb partition by c2 order by c2") + tdSql.query(f"select count(c1) , count(t2) ,c2 from {dbname}.stb partition by c2 order by c2") tdSql.checkRows(self.row_nums+1) - tdSql.query("select count(c1) , count(t1) ,max(c2) ,tbname from stb partition by tbname order by tbname") + tdSql.query(f"select count(c1) , count(t1) ,max(c2) ,tbname from {dbname}.stb partition by tbname order by tbname") tdSql.checkRows(self.tb_nums) tdSql.checkCols(4) - tdSql.query("select count(c1) , count(t2) ,t1 from stb partition by t1 order by t1") + tdSql.query(f"select count(c1) , count(t2) ,t1 from {dbname}.stb partition by t1 order by t1") tdSql.checkRows(self.tb_nums) tdSql.checkData(0,0,self.row_nums) - # bug need fix - # tdSql.query("select count(c1) , count(t1) ,abs(c1) from stb partition by abs(c1) order by abs(c1)") + # bug need fix + # tdSql.query(f"select count(c1) , count(t1) ,abs(c1) from {dbname}.stb partition by abs(c1) order by abs(c1)") # tdSql.checkRows(self.row_nums+1) - - tdSql.query("select count(ceil(c2)) , count(floor(t2)) ,count(floor(c2)) from stb partition by abs(c2) order by abs(c2)") + + tdSql.query(f"select count(ceil(c2)) , count(floor(t2)) ,count(floor(c2)) from {dbname}.stb partition by abs(c2) order by abs(c2)") tdSql.checkRows(self.row_nums+1) - tdSql.query("select count(ceil(c1-2)) , count(floor(t2+1)) ,max(c2-c1) from stb partition by abs(floor(c1)) order by abs(floor(c1))") + tdSql.query(f"select count(ceil(c1-2)) , count(floor(t2+1)) ,max(c2-c1) from {dbname}.stb partition by abs(floor(c1)) order by abs(floor(c1))") tdSql.checkRows(self.row_nums+1) - - # interval - tdSql.query("select count(c1) from stb interval(2s) sliding(1s)") + + # interval + tdSql.query(f"select count(c1) from {dbname}.stb interval(2s) sliding(1s)") # bug need fix - tdSql.query('select max(c1) from stb where ts>="2022-07-06 16:00:00.000 " and ts < "2022-07-06 17:00:00.000 " interval(50s) sliding(30s) fill(NULL)') + tdSql.query(f'select max(c1) from {dbname}.stb where ts>="2022-07-06 16:00:00.000 " and ts < "2022-07-06 17:00:00.000 " interval(50s) sliding(30s) fill(NULL)') - tdSql.query(" select tbname , count(c1) from stb partition by tbname interval(10s) slimit 5 soffset 1 ") + tdSql.query(f"select tbname , count(c1) from {dbname}.stb partition by tbname interval(10s) slimit 5 soffset 1 ") - tdSql.query("select tbname , count(c1) from stb partition by tbname interval(10s)") + tdSql.query(f"select tbname , count(c1) from {dbname}.stb partition by tbname interval(10s)") - tdSql.query("select tbname , count(c1) from sub_stb_1 partition by tbname interval(10s)") + tdSql.query(f"select tbname , count(c1) from {dbname}.sub_stb_1 partition by tbname interval(10s)") tdSql.checkData(0,0,'sub_stb_1') tdSql.checkData(0,1,self.row_nums) - # tdSql.query(" select tbname , count(c1) from stb partition by tbname order by tbname slimit 5 soffset 0 ") + # tdSql.query(f"select tbname , count(c1) from {dbname}.stb partition by tbname order by tbname slimit 5 soffset 0 ") # tdSql.checkRows(5) - - # tdSql.query(" select tbname , count(c1) from stb partition by tbname order by tbname slimit 5 soffset 1 ") - # tdSql.checkRows(5) - - tdSql.query(" select tbname , count(c1) from sub_stb_1 partition by tbname interval(10s) sliding(5s) ") - - tdSql.query(f'select max(c1) from stb where ts>={self.ts} and ts < {self.ts}+10000 partition by tbname interval(50s) sliding(30s)') - tdSql.query(f'select max(c1) from stb where ts>={self.ts} and ts < {self.ts}+10000 interval(50s) sliding(30s)') - tdSql.query(f'select tbname , count(c1) from stb where ts>={self.ts} and ts < {self.ts}+10000 partition by tbname interval(50s) sliding(30s)') + + # tdSql.query(f"select tbname , count(c1) from {dbname}.stb partition by tbname order by tbname slimit 5 soffset 1 ") + # tdSql.checkRows(5) + + tdSql.query(f"select tbname , count(c1) from {dbname}.sub_stb_1 partition by tbname interval(10s) sliding(5s) ") + + tdSql.query(f'select max(c1) from {dbname}.stb where ts>={self.ts} and ts < {self.ts}+10000 partition by tbname interval(50s) sliding(30s)') + tdSql.query(f'select max(c1) from {dbname}.stb where ts>={self.ts} and ts < {self.ts}+10000 interval(50s) sliding(30s)') + tdSql.query(f'select tbname , count(c1) from {dbname}.stb where ts>={self.ts} and ts < {self.ts}+10000 partition by tbname interval(50s) sliding(30s)') def run(self): tdSql.prepare() self.prepare_datas("stb",self.tb_nums,self.row_nums) self.basic_query() + dbname="db" + + # # coverage case for taosd crash about bug fix + tdSql.query(f"select sum(c1) from {dbname}.stb where t2+10 >1 ") + tdSql.query(f"select count(c1),count(t1) from {dbname}.stb where -t2<1 ") + tdSql.query(f"select tbname ,max(ceil(c1)) from {dbname}.stb group by tbname ") + tdSql.query(f"select avg(abs(c1)) , tbname from {dbname}.stb group by tbname ") + tdSql.query(f"select t1,c1 from {dbname}.stb where abs(t2+c1)=1 ") - # # coverage case for taosd crash about bug fix - tdSql.query(" select sum(c1) from stb where t2+10 >1 ") - tdSql.query(" select count(c1),count(t1) from stb where -t2<1 ") - tdSql.query(" select tbname ,max(ceil(c1)) from stb group by tbname ") - tdSql.query(" select avg(abs(c1)) , tbname from stb group by tbname ") - tdSql.query(" select t1,c1 from stb where abs(t2+c1)=1 ") - def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/system-test/2-query/db.py b/tests/system-test/2-query/db.py index a4d603bada..f2d85ebf65 100644 --- a/tests/system-test/2-query/db.py +++ b/tests/system-test/2-query/db.py @@ -10,9 +10,6 @@ import random class TDTestCase: - updatecfgDict = {'debugFlag': 143, "cDebugFlag": 143, "uDebugFlag": 143, "rpcDebugFlag": 143, "tmrDebugFlag": 143, - "jniDebugFlag": 143, "simDebugFlag": 143, "dDebugFlag": 143, "dDebugFlag": 143, "vDebugFlag": 143, "mDebugFlag": 143, "qDebugFlag": 143, - "wDebugFlag": 143, "sDebugFlag": 143, "tsdbDebugFlag": 143, "tqDebugFlag": 143, "fsDebugFlag": 143, "udfDebugFlag": 143} def init(self, conn, logSql): tdLog.debug(f"start to excute {__file__}") @@ -26,22 +23,22 @@ class TDTestCase: tdSql.execute("create table dbms.ntb (ts timestamp, c1 int, c2 bigint)") tdSql.execute("create table dbus.ntb (ts timestamp, c1 int, c2 bigint)") tdSql.execute("create table dbns.ntb (ts timestamp, c1 int, c2 bigint)") - + tdSql.execute("insert into dbms.ntb values ('2022-01-01 08:00:00.001', 1, 2)") tdSql.execute("insert into dbms.ntb values ('2022-01-01 08:00:00.002', 3, 4)") - + tdSql.execute("insert into dbus.ntb values ('2022-01-01 08:00:00.000001', 1, 2)") tdSql.execute("insert into dbus.ntb values ('2022-01-01 08:00:00.000002', 3, 4)") - + tdSql.execute("insert into dbns.ntb values ('2022-01-01 08:00:00.000000001', 1, 2)") tdSql.execute("insert into dbns.ntb values ('2022-01-01 08:00:00.000000002', 3, 4)") - + tdSql.query("select count(c1) from dbms.ntb interval(1a)") tdSql.checkRows(2) - + tdSql.query("select count(c1) from dbus.ntb interval(1u)") tdSql.checkRows(2) - + tdSql.query("select count(c1) from dbns.ntb interval(1b)") tdSql.checkRows(2) diff --git a/tests/system-test/2-query/diff.py b/tests/system-test/2-query/diff.py index 30b588fa97..9eac56b9e3 100644 --- a/tests/system-test/2-query/diff.py +++ b/tests/system-test/2-query/diff.py @@ -18,116 +18,117 @@ class TDTestCase: def run(self): tdSql.prepare() + dbname = "db" tdSql.execute( - "create table ntb(ts timestamp,c1 int,c2 double,c3 float)") + f"create table {dbname}.ntb(ts timestamp,c1 int,c2 double,c3 float)") tdSql.execute( - "insert into ntb values(now,1,1.0,10.5)(now+1s,10,-100.0,5.1)(now+10s,-1,15.1,5.0)") + f"insert into {dbname}.ntb values(now,1,1.0,10.5)(now+1s,10,-100.0,5.1)(now+10s,-1,15.1,5.0)") - tdSql.query("select diff(c1,0) from ntb") + tdSql.query(f"select diff(c1,0) from {dbname}.ntb") tdSql.checkRows(2) tdSql.checkData(0, 0, 9) tdSql.checkData(1, 0, -11) - tdSql.query("select diff(c1,1) from ntb") + tdSql.query(f"select diff(c1,1) from {dbname}.ntb") tdSql.checkRows(2) tdSql.checkData(0, 0, 9) tdSql.checkData(1, 0, None) - tdSql.query("select diff(c2,0) from ntb") + tdSql.query(f"select diff(c2,0) from {dbname}.ntb") tdSql.checkRows(2) tdSql.checkData(0, 0, -101) tdSql.checkData(1, 0, 115.1) - tdSql.query("select diff(c2,1) from ntb") + tdSql.query(f"select diff(c2,1) from {dbname}.ntb") tdSql.checkRows(2) tdSql.checkData(0, 0, None) tdSql.checkData(1, 0, 115.1) - tdSql.query("select diff(c3,0) from ntb") + tdSql.query(f"select diff(c3,0) from {dbname}.ntb") tdSql.checkRows(2) tdSql.checkData(0, 0, -5.4) tdSql.checkData(1, 0, -0.1) - tdSql.query("select diff(c3,1) from ntb") + tdSql.query(f"select diff(c3,1) from {dbname}.ntb") tdSql.checkRows(2) tdSql.checkData(0, 0, None) tdSql.checkData(1, 0, None) - tdSql.execute('''create table stb(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + tdSql.execute(f'''create table {dbname}.stb(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(loc nchar(20))''') - tdSql.execute("create table stb_1 using stb tags('beijing')") + tdSql.execute(f"create table {dbname}.stb_1 using {dbname}.stb tags('beijing')") tdSql.execute( - "insert into stb_1 values(%d, 0, 0, 0, 0, 0.0, 0.0, False, ' ', ' ', 0, 0, 0, 0)" % (self.ts - 1)) + f"insert into {dbname}.stb_1 values(%d, 0, 0, 0, 0, 0.0, 0.0, False, ' ', ' ', 0, 0, 0, 0)" % (self.ts - 1)) # diff verifacation - tdSql.query("select diff(col1) from stb_1") + tdSql.query(f"select diff(col1) from {dbname}.stb_1") tdSql.checkRows(0) - tdSql.query("select diff(col2) from stb_1") + tdSql.query(f"select diff(col2) from {dbname}.stb_1") tdSql.checkRows(0) - tdSql.query("select diff(col3) from stb_1") + tdSql.query(f"select diff(col3) from {dbname}.stb_1") tdSql.checkRows(0) - tdSql.query("select diff(col4) from stb_1") + tdSql.query(f"select diff(col4) from {dbname}.stb_1") tdSql.checkRows(0) - tdSql.query("select diff(col5) from stb_1") + tdSql.query(f"select diff(col5) from {dbname}.stb_1") tdSql.checkRows(0) - tdSql.query("select diff(col6) from stb_1") + tdSql.query(f"select diff(col6) from {dbname}.stb_1") tdSql.checkRows(0) - tdSql.query("select diff(col7) from stb_1") + tdSql.query(f"select diff(col7) from {dbname}.stb_1") tdSql.checkRows(0) for i in range(self.rowNum): - tdSql.execute("insert into stb_1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)" + tdSql.execute(f"insert into {dbname}.stb_1 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)) - tdSql.error("select diff(ts) from stb") - tdSql.error("select diff(ts) from stb_1") + tdSql.error(f"select diff(ts) from {dbname}.stb") + tdSql.error(f"select diff(ts) from {dbname}.stb_1") - # tdSql.error("select diff(col7) from stb") + # tdSql.error(f"select diff(col7) from {dbname}.stb") - tdSql.error("select diff(col8) from stb") - tdSql.error("select diff(col8) from stb_1") - tdSql.error("select diff(col9) from stb") - tdSql.error("select diff(col9) from stb_1") - tdSql.error("select diff(col11) from stb_1") - tdSql.error("select diff(col12) from stb_1") - tdSql.error("select diff(col13) from stb_1") - tdSql.error("select diff(col14) from stb_1") - tdSql.error("select ts,diff(col1),ts from stb_1") + tdSql.error(f"select diff(col8) from {dbname}.stb") + tdSql.error(f"select diff(col8) from {dbname}.stb_1") + tdSql.error(f"select diff(col9) from {dbname}.stb") + tdSql.error(f"select diff(col9) from {dbname}.stb_1") + tdSql.error(f"select diff(col11) from {dbname}.stb_1") + tdSql.error(f"select diff(col12) from {dbname}.stb_1") + tdSql.error(f"select diff(col13) from {dbname}.stb_1") + tdSql.error(f"select diff(col14) from {dbname}.stb_1") + tdSql.error(f"select ts,diff(col1),ts from {dbname}.stb_1") - tdSql.query("select diff(col1) from stb_1") + tdSql.query(f"select diff(col1) from {dbname}.stb_1") tdSql.checkRows(10) - tdSql.query("select diff(col2) from stb_1") + tdSql.query(f"select diff(col2) from {dbname}.stb_1") tdSql.checkRows(10) - tdSql.query("select diff(col3) from stb_1") + tdSql.query(f"select diff(col3) from {dbname}.stb_1") tdSql.checkRows(10) - tdSql.query("select diff(col4) from stb_1") + tdSql.query(f"select diff(col4) from {dbname}.stb_1") tdSql.checkRows(10) - tdSql.query("select diff(col5) from stb_1") + tdSql.query(f"select diff(col5) from {dbname}.stb_1") tdSql.checkRows(10) - tdSql.query("select diff(col6) from stb_1") + tdSql.query(f"select diff(col6) from {dbname}.stb_1") tdSql.checkRows(10) - tdSql.execute('''create table stb1(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + tdSql.execute(f'''create table {dbname}.stb1(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(loc nchar(20))''') - tdSql.execute("create table stb1_1 using stb tags('shanghai')") + tdSql.execute(f"create table {dbname}.stb1_1 using {dbname}.stb tags('shanghai')") for i in range(self.rowNum): - tdSql.execute("insert into stb1_1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)" + tdSql.execute(f"insert into {dbname}.stb1_1 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)) for i in range(self.rowNum): - tdSql.execute("insert into stb1_1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)" + tdSql.execute(f"insert into {dbname}.stb1_1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)" % (self.ts - i-1, 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.query("select diff(col1,0) from stb1_1") + tdSql.query(f"select diff(col1,0) from {dbname}.stb1_1") tdSql.checkRows(19) - tdSql.query("select diff(col1,1) from stb1_1") + tdSql.query(f"select diff(col1,1) from {dbname}.stb1_1") tdSql.checkRows(19) tdSql.checkData(0,0,None) diff --git a/tests/system-test/2-query/distinct.py b/tests/system-test/2-query/distinct.py index 937ff78c71..7214caec96 100644 --- a/tests/system-test/2-query/distinct.py +++ b/tests/system-test/2-query/distinct.py @@ -16,6 +16,8 @@ class TDTestCase: def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring tdSql.prepare() + dbname = "db" + tdLog.printNoPrefix("==========step1:create table") tdSql.execute("create stable db.stb1 (ts timestamp, c1 int, c2 int) tags(t0 tinyint, t1 int, t2 int)") tdSql.execute("create stable db.stb2 (ts timestamp, c2 int, c3 binary(16)) tags(t2 binary(16), t3 binary(16), t4 int)") @@ -34,223 +36,224 @@ class TDTestCase: tdSql.execute(f"insert into db.t0{i} values (now-9d, {i}, '{(i+2)%3}')") tdSql.execute(f"insert into db.t0{i} values (now-8d, {i}, '{(i)%3}')") tdSql.execute(f"insert into db.t0{i} (ts )values (now-7d)") - # tdSql.execute("create table db.t100num using db.stb1 tags(null, null, null)") - # tdSql.execute("create table db.t0100num using db.stb2 tags(null, null, null)") - # tdSql.execute(f"insert into db.t100num values (now-10d, {tbnum-1}, 1)") - # tdSql.execute(f"insert into db.t100num values (now-9d, {tbnum-1}, 0)") - # tdSql.execute(f"insert into db.t100num values (now-8d, {tbnum-1}, 2)") - # tdSql.execute(f"insert into db.t100num (ts )values (now-7d)") - # tdSql.execute(f"insert into db.t0100num values (now-10d, {tbnum-1}, 1)") - # tdSql.execute(f"insert into db.t0100num values (now-9d, {tbnum-1}, 0)") - # tdSql.execute(f"insert into db.t0100num values (now-8d, {tbnum-1}, 2)") - # tdSql.execute(f"insert into db.t0100num (ts )values (now-7d)") + tdSql.execute("create table db.t100num using db.stb1 tags(null, null, null)") + tdSql.execute("create table db.t0100num using db.stb2 tags(null, null, null)") + tdSql.execute(f"insert into db.t100num values (now-10d, {tbnum-1}, 1)") + tdSql.execute(f"insert into db.t100num values (now-9d, {tbnum-1}, 0)") + tdSql.execute(f"insert into db.t100num values (now-8d, {tbnum-1}, 2)") + tdSql.execute(f"insert into db.t100num (ts )values (now-7d)") + tdSql.execute(f"insert into db.t0100num values (now-10d, {tbnum-1}, 1)") + tdSql.execute(f"insert into db.t0100num values (now-9d, {tbnum-1}, 0)") + tdSql.execute(f"insert into db.t0100num values (now-8d, {tbnum-1}, 2)") + tdSql.execute(f"insert into db.t0100num (ts )values (now-7d)") - #========== distinct multi-data-coloumn ========== - # tdSql.query(f"select distinct c1 from stb1 where c1 <{tbnum}") - # tdSql.checkRows(tbnum) - # tdSql.query(f"select distinct c2 from stb1") - # tdSql.checkRows(4) - # tdSql.query(f"select distinct c1,c2 from stb1 where c1 <{tbnum}") - # tdSql.checkRows(tbnum*3) - # tdSql.query(f"select distinct c1,c1 from stb1 where c1 <{tbnum}") - # tdSql.checkRows(tbnum) - # tdSql.query(f"select distinct c1,c2 from stb1 where c1 <{tbnum} limit 3") - # tdSql.checkRows(3) - # tdSql.query(f"select distinct c1,c2 from stb1 where c1 <{tbnum} limit 3 offset {tbnum*3-2}") - # tdSql.checkRows(2) - - tdSql.query(f"select distinct c1 from t1 where c1 <{tbnum}") - tdSql.checkRows(1) - tdSql.query(f"select distinct c2 from t1") + # #========== distinct multi-data-coloumn ========== + tdSql.query(f"select distinct c1 from {dbname}.stb1 where c1 <{tbnum}") + tdSql.checkRows(tbnum) + tdSql.query(f"select distinct c2 from {dbname}.stb1") tdSql.checkRows(4) - tdSql.query(f"select distinct c1,c2 from t1 where c1 <{tbnum}") + tdSql.query(f"select distinct c1,c2 from {dbname}.stb1 where c1 <{tbnum}") + tdSql.checkRows(tbnum*3) + tdSql.query(f"select distinct c1,c1 from {dbname}.stb1 where c1 <{tbnum}") + tdSql.checkRows(tbnum) + tdSql.query(f"select distinct c1,c2 from {dbname}.stb1 where c1 <{tbnum} limit 3") tdSql.checkRows(3) - tdSql.query(f"select distinct c1,c1 from t1 ") + tdSql.query(f"select distinct c1,c2 from {dbname}.stb1 where c1 <{tbnum} limit 3 offset {tbnum*3-2}") tdSql.checkRows(2) - tdSql.query(f"select distinct c1,c1 from t1 where c1 <{tbnum}") + + tdSql.query(f"select distinct c1 from {dbname}.t1 where c1 <{tbnum}") tdSql.checkRows(1) - tdSql.query(f"select distinct c1,c2 from t1 where c1 <{tbnum} limit 3") + tdSql.query(f"select distinct c2 from {dbname}.t1") + tdSql.checkRows(4) + tdSql.query(f"select distinct c1,c2 from {dbname}.t1 where c1 <{tbnum}") tdSql.checkRows(3) - tdSql.query(f"select distinct c1,c2 from t1 where c1 <{tbnum} limit 3 offset 2") + tdSql.query(f"select distinct c1,c1 from {dbname}.t1 ") + tdSql.checkRows(2) + tdSql.query(f"select distinct c1,c1 from {dbname}.t1 where c1 <{tbnum}") + tdSql.checkRows(1) + tdSql.query(f"select distinct c1,c2 from {dbname}.t1 where c1 <{tbnum} limit 3") + tdSql.checkRows(3) + tdSql.query(f"select distinct c1,c2 from {dbname}.t1 where c1 <{tbnum} limit 3 offset 2") tdSql.checkRows(1) - # tdSql.query(f"select distinct c3 from stb2 where c2 <{tbnum} ") + # tdSql.query(f"select distinct c3 from {dbname}.stb2 where c2 <{tbnum} ") # tdSql.checkRows(3) - # tdSql.query(f"select distinct c3, c2 from stb2 where c2 <{tbnum} limit 2") + # tdSql.query(f"select distinct c3, c2 from {dbname}.stb2 where c2 <{tbnum} limit 2") # tdSql.checkRows(2) - # tdSql.error("select distinct c5 from stb1") - tdSql.error("select distinct c5 from t1") - tdSql.error("select distinct c1 from db.*") - tdSql.error("select c2, distinct c1 from stb1") - tdSql.error("select c2, distinct c1 from t1") - tdSql.error("select distinct c2 from ") - tdSql.error("distinct c2 from stb1") - tdSql.error("distinct c2 from t1") - tdSql.error("select distinct c1, c2, c3 from stb1") - tdSql.error("select distinct c1, c2, c3 from t1") - tdSql.error("select distinct stb1.c1, stb1.c2, stb2.c2, stb2.c3 from stb1") - tdSql.error("select distinct stb1.c1, stb1.c2, stb2.c2, stb2.c3 from t1") - tdSql.error("select distinct t1.c1, t1.c2, t2.c1, t2.c2 from t1") - # tdSql.query(f"select distinct c1 c2, c2 c3 from stb1 where c1 <{tbnum}") - # tdSql.checkRows(tbnum*3) - tdSql.query(f"select distinct c1 c2, c2 c3 from t1 where c1 <{tbnum}") + # tdSql.error(f"select distinct c5 from {dbname}.stb1") + tdSql.error(f"select distinct c5 from {dbname}.t1") + tdSql.error(f"select distinct c1 from db.*") + tdSql.error(f"select c2, distinct c1 from {dbname}.stb1") + tdSql.error(f"select c2, distinct c1 from {dbname}.t1") + tdSql.error(f"select distinct c2 from ") + tdSql.error("distinct c2 from {dbname}.stb1") + tdSql.error("distinct c2 from {dbname}.t1") + tdSql.error(f"select distinct c1, c2, c3 from {dbname}.stb1") + tdSql.error(f"select distinct c1, c2, c3 from {dbname}.t1") + tdSql.error(f"select distinct stb1.c1, stb1.c2, stb2.c2, stb2.c3 from {dbname}.stb1") + tdSql.error(f"select distinct stb1.c1, stb1.c2, stb2.c2, stb2.c3 from {dbname}.t1") + tdSql.error(f"select distinct t1.c1, t1.c2, t2.c1, t2.c2 from {dbname}.t1") + tdSql.query(f"select distinct c1 c2, c2 c3 from {dbname}.stb1 where c1 <{tbnum}") + tdSql.checkRows(tbnum*3) + tdSql.query(f"select distinct c1 c2, c2 c3 from {dbname}.t1 where c1 <{tbnum}") tdSql.checkRows(3) - # tdSql.error("select distinct c1, c2 from stb1 order by ts") - tdSql.error("select distinct c1, c2 from t1 order by ts") - # tdSql.error("select distinct c1, ts from stb1 group by c2") - tdSql.error("select distinct c1, ts from t1 group by c2") - # tdSql.error("select distinct c1, max(c2) from stb1 ") - # tdSql.error("select distinct c1, max(c2) from t1 ") - # tdSql.error("select max(c2), distinct c1 from stb1 ") - tdSql.error("select max(c2), distinct c1 from t1 ") - # tdSql.error("select distinct c1, c2 from stb1 where c1 > 3 group by t0") - tdSql.error("select distinct c1, c2 from t1 where c1 > 3 group by t0") - # tdSql.error("select distinct c1, c2 from stb1 where c1 > 3 interval(1d) ") - tdSql.error("select distinct c1, c2 from t1 where c1 > 3 interval(1d) ") - # tdSql.error("select distinct c1, c2 from stb1 where c1 > 3 interval(1d) fill(next)") - tdSql.error("select distinct c1, c2 from t1 where c1 > 3 interval(1d) fill(next)") - # tdSql.error("select distinct c1, c2 from stb1 where ts > now-10d and ts < now interval(1d) fill(next)") - tdSql.error("select distinct c1, c2 from t1 where ts > now-10d and ts < now interval(1d) fill(next)") - # tdSql.error("select distinct c1, c2 from stb1 where c1 > 3 slimit 1") - # tdSql.error("select distinct c1, c2 from t1 where c1 > 3 slimit 1") - # tdSql.query(f"select distinct c1, c2 from stb1 where c1 between {tbnum-2} and {tbnum} ") - # tdSql.checkRows(6) - tdSql.query(f"select distinct c1, c2 from t1 where c1 between {tbnum-2} and {tbnum} ") + tdSql.error(f"select distinct c1, c2 from {dbname}.stb1 order by ts") + tdSql.error(f"select distinct c1, c2 from {dbname}.t1 order by ts") + tdSql.error(f"select distinct c1, ts from {dbname}.stb1 group by c2") + tdSql.error(f"select distinct c1, ts from {dbname}.t1 group by c2") + tdSql.query(f"select distinct c1, max(c2) from {dbname}.stb1 ") + tdSql.query(f"select distinct c1, max(c2) from {dbname}.t1 ") + tdSql.error(f"select max(c2), distinct c1 from {dbname}.stb1 ") + tdSql.error(f"select max(c2), distinct c1 from {dbname}.t1 ") + tdSql.error(f"select distinct c1, c2 from {dbname}.stb1 where c1 > 3 group by t0") + tdSql.error(f"select distinct c1, c2 from {dbname}.t1 where c1 > 3 group by t0") + tdSql.error(f"select distinct c1, c2 from {dbname}.stb1 where c1 > 3 interval(1d) ") + tdSql.error(f"select distinct c1, c2 from {dbname}.t1 where c1 > 3 interval(1d) ") + tdSql.error(f"select distinct c1, c2 from {dbname}.stb1 where c1 > 3 interval(1d) fill(next)") + tdSql.error(f"select distinct c1, c2 from {dbname}.t1 where c1 > 3 interval(1d) fill(next)") + tdSql.error(f"select distinct c1, c2 from {dbname}.stb1 where ts > now-10d and ts < now interval(1d) fill(next)") + tdSql.error(f"select distinct c1, c2 from {dbname}.t1 where ts > now-10d and ts < now interval(1d) fill(next)") + tdSql.error(f"select distinct c1, c2 from {dbname}.stb1 where c1 > 3 slimit 1") + tdSql.error(f"select distinct c1, c2 from {dbname}.t1 where c1 > 3 slimit 1") + tdSql.query(f"select distinct c1, c2 from {dbname}.stb1 where c1 between {tbnum-2} and {tbnum} ") + tdSql.checkRows(6) + tdSql.query(f"select distinct c1, c2 from {dbname}.t1 where c1 between {tbnum-2} and {tbnum} ") # tdSql.checkRows(1) - # tdSql.query("select distinct c1, c2 from stb1 where c1 in (1,2,3,4,5)") - # tdSql.checkRows(15) - tdSql.query("select distinct c1, c2 from t1 where c1 in (1,2,3,4,5)") + tdSql.query(f"select distinct c1, c2 from {dbname}.stb1 where c1 in (1,2,3,4,5)") + tdSql.checkRows(15) + tdSql.query(f"select distinct c1, c2 from {dbname}.t1 where c1 in (1,2,3,4,5)") # tdSql.checkRows(1) - # tdSql.query("select distinct c1, c2 from stb1 where c1 in (100,1000,10000)") - # tdSql.checkRows(3) - tdSql.query("select distinct c1, c2 from t1 where c1 in (100,1000,10000)") - # tdSql.checkRows(0) + tdSql.query(f"select distinct c1, c2 from {dbname}.stb1 where c1 in (100,1000,10000)") + tdSql.checkRows(3) + tdSql.query(f"select distinct c1, c2 from {dbname}.t1 where c1 in (100,1000,10000)") + tdSql.checkRows(0) - # tdSql.query(f"select distinct c1,c2 from (select * from stb1 where c1 > {tbnum-2}) ") - # tdSql.checkRows(3) - # tdSql.query(f"select distinct c1,c2 from (select * from t1 where c1 < {tbnum}) ") - # tdSql.checkRows(3) - # tdSql.query(f"select distinct c1,c2 from (select * from stb1 where t2 !=0 and t2 != 1) ") - # tdSql.checkRows(0) - # tdSql.error("select distinct c1, c2 from (select distinct c1, c2 from stb1 where t0 > 2 and t1 < 3) ") - # tdSql.error("select c1, c2 from (select distinct c1, c2 from stb1 where t0 > 2 and t1 < 3) ") - # tdSql.query("select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 ) where c1 < 4") - # tdSql.checkRows(3) - # tdSql.error("select distinct c1, c2 from (select c1 from stb1 where t0 > 2 ) where t1 < 3") - # tdSql.error("select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 order by ts)") - # tdSql.error("select distinct c1, c2 from (select c2, c1 from t1 where c1 > 2 order by ts)") - # tdSql.error("select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 group by c1)") - # tdSql.error("select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from stb1 group by c1)") - # tdSql.error("select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from t1 group by c1)") - # tdSql.query("select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from stb1 )") - # tdSql.checkRows(1) - # tdSql.query("select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from t1 )") - # tdSql.checkRows(1) - # tdSql.error("select distinct stb1.c1, stb1.c2 from stb1 , stb2 where stb1.ts=stb2.ts and stb1.t2=stb2.t4") - # tdSql.error("select distinct t1.c1, t1.c2 from t1 , t2 where t1.ts=t2.ts ") + tdSql.query(f"select distinct c1,c2 from (select * from {dbname}.stb1 where c1 > {tbnum-2}) ") + tdSql.checkRows(3) + tdSql.query(f"select distinct c1,c2 from (select * from {dbname}.t1 where c1 < {tbnum}) ") + tdSql.checkRows(3) + tdSql.query(f"select distinct c1,c2 from (select * from {dbname}.stb1 where t2 !=0 and t2 != 1) ") + tdSql.checkRows(0) + tdSql.query(f"select distinct c1, c2 from (select distinct c1, c2 from {dbname}.stb1 where t0 > 2 and t1 < 3) ") + tdSql.query(f"select c1, c2 from (select distinct c1, c2 from {dbname}.stb1 where t0 > 2 and t1 < 3) ") + tdSql.query(f"select distinct c1, c2 from (select c2, c1 from {dbname}.stb1 where c1 > 2 ) where c1 < 4") + tdSql.checkRows(3) + tdSql.error(f"select distinct c1, c2 from (select c1 from {dbname}.stb1 where t0 > 2 ) where t1 < 3") + tdSql.query(f"select distinct c1, c2 from (select c2, c1 from {dbname}.stb1 where c1 > 2 order by ts)") + tdSql.query(f"select distinct c1, c2 from (select c2, c1 from {dbname}.t1 where c1 > 2 order by ts)") + tdSql.error(f"select distinct c1, c2 from (select c2, c1 from {dbname}.stb1 where c1 > 2 group by c1)") + tdSql.query(f"select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from {dbname}.stb1 group by c1)") + tdSql.query(f"select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from {dbname}.t1 group by c1)") + tdSql.query(f"select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from {dbname}.stb1 )") + tdSql.checkRows(1) + tdSql.query(f"select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from {dbname}.t1 )") + tdSql.checkRows(1) + tdSql.query(f"select distinct stb1.c1, stb1.c2 from {dbname}.stb1, {dbname}.stb2 where stb1.ts=stb2.ts and stb1.t2=stb2.t4") + tdSql.query(f"select distinct t1.c1, t1.c2 from {dbname}.t1, {dbname}.t2 where t1.ts=t2.ts ") - # tdSql.error("select distinct c1, c2 from (select count(c1) c1, count(c2) c2 from stb1 group by ts)") - # tdSql.error("select distinct c1, c2 from (select count(c1) c1, count(c2) c2 from t1 group by ts)") + tdSql.query(f"select distinct c1, c2 from (select count(c1) c1, count(c2) c2 from {dbname}.stb1 group by ts)") + tdSql.query(f"select distinct c1, c2 from (select count(c1) c1, count(c2) c2 from {dbname}.t1 group by ts)") - # #========== suport distinct multi-tags-coloumn ========== - # tdSql.query("select distinct t1 from stb1") - # tdSql.checkRows(maxRemainderNum+1) - # tdSql.query("select distinct t0, t1 from stb1") - # tdSql.checkRows(maxRemainderNum+1) - # tdSql.query("select distinct t1, t0 from stb1") - # tdSql.checkRows(maxRemainderNum+1) - # tdSql.query("select distinct t1, t2 from stb1") - # tdSql.checkRows(maxRemainderNum*2+1) - # tdSql.query("select distinct t0, t1, t2 from stb1") - # tdSql.checkRows(maxRemainderNum*2+1) - # tdSql.query("select distinct t0 t1, t1 t2 from stb1") - # tdSql.checkRows(maxRemainderNum+1) - # tdSql.query("select distinct t0, t0, t0 from stb1") - # tdSql.checkRows(maxRemainderNum+1) - # tdSql.query("select distinct t0, t1 from t1") - # tdSql.checkRows(1) - # tdSql.query("select distinct t0, t1 from t100num") - # tdSql.checkRows(1) + #========== suport distinct multi-tags-coloumn ========== + tdSql.query(f"select distinct t1 from {dbname}.stb1") + tdSql.checkRows(maxRemainderNum+1) + tdSql.query(f"select distinct t0, t1 from {dbname}.stb1") + tdSql.checkRows(maxRemainderNum+1) + tdSql.query(f"select distinct t1, t0 from {dbname}.stb1") + tdSql.checkRows(maxRemainderNum+1) + tdSql.query(f"select distinct t1, t2 from {dbname}.stb1") + tdSql.checkRows(maxRemainderNum*2+1) + tdSql.query(f"select distinct t0, t1, t2 from {dbname}.stb1") + tdSql.checkRows(maxRemainderNum*2+1) + tdSql.query(f"select distinct t0 t1, t1 t2 from {dbname}.stb1") + tdSql.checkRows(maxRemainderNum+1) + tdSql.query(f"select distinct t0, t0, t0 from {dbname}.stb1") + tdSql.checkRows(maxRemainderNum+1) + tdSql.query(f"select distinct t0, t1 from {dbname}.t1") + tdSql.checkRows(1) + tdSql.query(f"select distinct t0, t1 from {dbname}.t100num") + tdSql.checkRows(1) - # tdSql.query("select distinct t3 from stb2") - # tdSql.checkRows(maxRemainderNum+1) - # tdSql.query("select distinct t2, t3 from stb2") - # tdSql.checkRows(maxRemainderNum+1) - # tdSql.query("select distinct t3, t2 from stb2") - # tdSql.checkRows(maxRemainderNum+1) - # tdSql.query("select distinct t4, t2 from stb2") - # tdSql.checkRows(maxRemainderNum*3+1) - # tdSql.query("select distinct t2, t3, t4 from stb2") - # tdSql.checkRows(maxRemainderNum*3+1) - # tdSql.query("select distinct t2 t1, t3 t2 from stb2") - # tdSql.checkRows(maxRemainderNum+1) - # tdSql.query("select distinct t3, t3, t3 from stb2") - # tdSql.checkRows(maxRemainderNum+1) - # tdSql.query("select distinct t2, t3 from t01") - # tdSql.checkRows(1) - # tdSql.query("select distinct t3, t4 from t0100num") - # tdSql.checkRows(1) + tdSql.query(f"select distinct t3 from {dbname}.stb2") + tdSql.checkRows(maxRemainderNum+1) + tdSql.query(f"select distinct t2, t3 from {dbname}.stb2") + tdSql.checkRows(maxRemainderNum+1) + tdSql.query(f"select distinct t3, t2 from {dbname}.stb2") + tdSql.checkRows(maxRemainderNum+1) + tdSql.query(f"select distinct t4, t2 from {dbname}.stb2") + tdSql.checkRows(maxRemainderNum*3+1) + tdSql.query(f"select distinct t2, t3, t4 from {dbname}.stb2") + tdSql.checkRows(maxRemainderNum*3+1) + tdSql.query(f"select distinct t2 t1, t3 t2 from {dbname}.stb2") + tdSql.checkRows(maxRemainderNum+1) + tdSql.query(f"select distinct t3, t3, t3 from {dbname}.stb2") + tdSql.checkRows(maxRemainderNum+1) + tdSql.query(f"select distinct t2, t3 from {dbname}.t01") + tdSql.checkRows(1) + tdSql.query(f"select distinct t3, t4 from {dbname}.t0100num") + tdSql.checkRows(1) - # ########## should be error ######### - # tdSql.error("select distinct from stb1") - # tdSql.error("select distinct t3 from stb1") - # tdSql.error("select distinct t1 from db.*") - # tdSql.error("select distinct t2 from ") - # tdSql.error("distinct t2 from stb1") - # tdSql.error("select distinct stb1") - # tdSql.error("select distinct t0, t1, t2, t3 from stb1") - # tdSql.error("select distinct stb1.t0, stb1.t1, stb2.t2, stb2.t3 from stb1") + ########## should be error ######### + tdSql.error(f"select distinct from {dbname}.stb1") + tdSql.error(f"select distinct t3 from {dbname}.stb1") + tdSql.error(f"select distinct t1 from db.*") + tdSql.error(f"select distinct t2 from ") + tdSql.error(f"distinct t2 from {dbname}.stb1") + tdSql.error(f"select distinct stb1") + tdSql.error(f"select distinct t0, t1, t2, t3 from {dbname}.stb1") + tdSql.error(f"select distinct stb1.t0, stb1.t1, stb2.t2, stb2.t3 from {dbname}.stb1") - # tdSql.error("select dist t0 from stb1") - # tdSql.error("select distinct stb2.t2, stb2.t3 from stb1") - # tdSql.error("select distinct stb2.t2 t1, stb2.t3 t2 from stb1") + tdSql.error(f"select dist t0 from {dbname}.stb1") + tdSql.error(f"select distinct stb2.t2, stb2.t3 from {dbname}.stb1") + tdSql.error(f"select distinct stb2.t2 t1, stb2.t3 t2 from {dbname}.stb1") - # tdSql.error("select distinct t0, t1 from t1 where t0 < 7") + tdSql.query(f"select distinct t0, t1 from {dbname}.t1 where t0 < 7") - # ########## add where condition ########## - # tdSql.query("select distinct t0, t1 from stb1 where t1 > 3") - # tdSql.checkRows(3) - # tdSql.query("select distinct t0, t1 from stb1 where t1 > 3 limit 2") - # tdSql.checkRows(2) - # tdSql.query("select distinct t0, t1 from stb1 where t1 > 3 limit 2 offset 2") - # tdSql.checkRows(1) - # tdSql.query("select distinct t0, t1 from stb1 where t1 > 3 slimit 2") - # tdSql.checkRows(3) - # tdSql.error("select distinct t0, t1 from stb1 where c1 > 2") - # tdSql.query("select distinct t0, t1 from stb1 where t1 > 3 and t1 < 5") - # tdSql.checkRows(1) - # tdSql.error("select distinct stb1.t0, stb1.t1 from stb1, stb2 where stb1.t2=stb2.t4") - # tdSql.error("select distinct t0, t1 from stb1 where stb2.t4 > 2") - # tdSql.error("select distinct t0, t1 from stb1 where t1 > 3 group by t0") - # tdSql.error("select distinct t0, t1 from stb1 where t1 > 3 interval(1d) ") - # tdSql.error("select distinct t0, t1 from stb1 where t1 > 3 interval(1d) fill(next)") - # tdSql.error("select distinct t0, t1 from stb1 where ts > now-10d and ts < now interval(1d) fill(next)") + ########## add where condition ########## + tdSql.query(f"select distinct t0, t1 from {dbname}.stb1 where t1 > 3") + tdSql.checkRows(3) + tdSql.query(f"select distinct t0, t1 from {dbname}.stb1 where t1 > 3 limit 2") + tdSql.checkRows(2) + tdSql.query(f"select distinct t0, t1 from {dbname}.stb1 where t1 > 3 limit 2 offset 2") + tdSql.checkRows(1) + tdSql.error(f"select distinct t0, t1 from {dbname}.stb1 where t1 > 3 slimit 2") + tdSql.query(f"select distinct t0, t1 from {dbname}.stb1 where c1 > 2") + tdSql.query(f"select distinct t0, t1 from {dbname}.stb1 where t1 > 3 and t1 < 5") + tdSql.checkRows(1) + tdSql.error(f"select distinct stb1.t0, stb1.t1 from {dbname}.stb1, {dbname}.stb2 where stb1.t2=stb2.t4") + tdSql.error(f"select distinct t0, t1 from {dbname}.stb1 where stb2.t4 > 2") + tdSql.error(f"select distinct t0, t1 from {dbname}.stb1 where t1 > 3 group by t0") + tdSql.error(f"select distinct t0, t1 from {dbname}.stb1 where t1 > 3 interval(1d) ") + tdSql.error(f"select distinct t0, t1 from {dbname}.stb1 where t1 > 3 interval(1d) fill(next)") + tdSql.error(f"select distinct t0, t1 from {dbname}.stb1 where ts > now-10d and ts < now interval(1d) fill(next)") - # tdSql.error("select max(c1), distinct t0 from stb1 where t0 > 2") - # tdSql.error("select distinct t0, max(c1) from stb1 where t0 > 2") - # tdSql.error("select distinct t0 from stb1 where t0 in (select t0 from stb1 where t0 > 2)") - # tdSql.query("select distinct t0, t1 from stb1 where t0 in (1,2,3,4,5)") - # tdSql.checkRows(5) - # tdSql.query("select distinct t1 from (select t0, t1 from stb1 where t0 > 2) ") - # tdSql.checkRows(4) - # tdSql.error("select distinct t1 from (select distinct t0, t1 from stb1 where t0 > 2 and t1 < 3) ") - # tdSql.error("select distinct t1 from (select distinct t0, t1 from stb1 where t0 > 2 ) where t1 < 3") - # tdSql.query("select distinct t1 from (select t0, t1 from stb1 where t0 > 2 ) where t1 < 3") - # tdSql.checkRows(1) - # tdSql.error("select distinct t1, t0 from (select t1 from stb1 where t0 > 2 ) where t1 < 3") - # tdSql.error("select distinct t1, t0 from (select max(t1) t1, max(t0) t0 from stb1 group by t1)") - # tdSql.error("select distinct t1, t0 from (select max(t1) t1, max(t0) t0 from stb1)") - # tdSql.query("select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 ) where t1 < 3") - # tdSql.checkRows(1) - # tdSql.error(" select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 order by ts) where t1 < 3") - # tdSql.error("select t1, t0 from (select distinct t1,t0 from stb1 where t0 > 2 ) where t1 < 3") - # tdSql.error(" select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 group by ts) where t1 < 3") - # tdSql.error("select distinct stb1.t1, stb1.t2 from stb1 , stb2 where stb1.ts=stb2.ts and stb1.t2=stb2.t4") - # tdSql.error("select distinct t1.t1, t1.t2 from t1 , t2 where t1.ts=t2.ts ") + tdSql.error(f"select max(c1), distinct t0 from {dbname}.stb1 where t0 > 2") + tdSql.query(f"select distinct t0, max(c1) from {dbname}.stb1 where t0 > 2") + tdSql.error(f"select distinct t0 from {dbname}.stb1 where t0 in (select t0 from {dbname}.stb1 where t0 > 2)") + tdSql.query(f"select distinct t0, t1 from {dbname}.stb1 where t0 in (1,2,3,4,5)") + tdSql.checkRows(5) + tdSql.query(f"select distinct t1 from (select t0, t1 from {dbname}.stb1 where t0 > 2) ") + tdSql.checkRows(4) + tdSql.query(f"select distinct t1 from (select distinct t0, t1 from {dbname}.stb1 where t0 > 2 and t1 < 3) ") + # TODO: BUG of TD-17561 + # tdSql.query(f"select distinct t1 from (select distinct t0, t1 from {dbname}.stb1 where t0 > 2 ) where t1 < 3") + tdSql.query(f"select distinct t1 from (select t0, t1 from {dbname}.stb1 where t0 > 2 ) where t1 < 3") + tdSql.checkRows(1) + tdSql.error(f"select distinct t1, t0 from (select t1 from {dbname}.stb1 where t0 > 2 ) where t1 < 3") + tdSql.query(f"select distinct t1, t0 from (select max(t1) t1, max(t0) t0 from {dbname}.stb1 group by t1)") + tdSql.query(f"select distinct t1, t0 from (select max(t1) t1, max(t0) t0 from {dbname}.stb1)") + tdSql.query(f"select distinct t1, t0 from (select t1,t0 from {dbname}.stb1 where t0 > 2 ) where t1 < 3") + tdSql.checkRows(1) + tdSql.query(f"select distinct t1, t0 from (select t1,t0 from {dbname}.stb1 where t0 > 2 order by ts) where t1 < 3") + # TODO: BUG of TD-17561 + # tdSql.error(f"select t1, t0 from (select distinct t1,t0 from {dbname}.stb1 where t0 > 2 ) where t1 < 3") + tdSql.error(f"select distinct t1, t0 from (select t1,t0 from {dbname}.stb1 where t0 > 2 group by ts) where t1 < 3") + tdSql.query(f"select distinct stb1.t1, stb1.t2 from {dbname}.stb1, {dbname}.stb2 where stb1.ts=stb2.ts and stb1.t2=stb2.t4") + tdSql.query(f"select distinct t1.t1, t1.t2 from {dbname}.t1, {dbname}.t2 where t1.ts=t2.ts ") diff --git a/tests/system-test/2-query/distribute_agg_apercentile.py b/tests/system-test/2-query/distribute_agg_apercentile.py index 632bda6bc6..591824fdd3 100644 --- a/tests/system-test/2-query/distribute_agg_apercentile.py +++ b/tests/system-test/2-query/distribute_agg_apercentile.py @@ -2,14 +2,10 @@ from util.log import * from util.cases import * from util.sql import * import numpy as np -import random +import random class TDTestCase: - updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , - "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, - "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143, - "maxTablesPerVnode":2 ,"minTablesPerVnode":2,"tableIncStepPerVnode":2 } def init(self, conn, logSql): tdLog.debug("start to execute %s" % __file__) @@ -17,89 +13,66 @@ class TDTestCase: self.vnode_disbutes = None self.ts = 1537146000000 - def prepare_datas_of_distribute(self): - + def prepare_datas_of_distribute(self, dbname="testdb"): + # prepate datas for 20 tables distributed at different vgroups - tdSql.execute("create database if not exists testdb keep 3650 duration 1000 vgroups 5") - tdSql.execute(" use testdb ") + tdSql.execute(f"create database if not exists {dbname} keep 3650 duration 1000 vgroups 5") + tdSql.execute(f" use {dbname} ") tdSql.execute( - '''create table stb1 + f'''create table {dbname}.stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t0 timestamp, t1 int, t2 bigint, t3 smallint, t4 tinyint, t5 float, t6 double, t7 bool, t8 binary(16),t9 nchar(32)) ''' ) - tdSql.execute( - ''' - create table t1 - (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) - ''' - ) for i in range(20): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( now(), {1*i}, {11111*i}, {111*i}, {1*i}, {1.11*i}, {11.11*i}, {i%2}, "binary{i}", "nchar{i}" )') + tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( now(), {1*i}, {11111*i}, {111*i}, {1*i}, {1.11*i}, {11.11*i}, {i%2}, "binary{i}", "nchar{i}" )') for i in range(9): tdSql.execute( - f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) tdSql.execute( - f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) for i in range(1,21): if i ==1 or i == 4: continue else: - tbname = "ct"+f'{i}' + tbname = f"{dbname}.ct{i}" for j in range(9): tdSql.execute( f"insert into {tbname} values ( now()-{(i+j)*10}s, {1*(j+i)}, {11111*(j+i)}, {111*(j+i)}, {11*(j)}, {1.11*(j+i)}, {11.11*(j+i)}, {(j+i)%2}, 'binary{j}', 'nchar{j}', now()+{1*j}a )" ) - tdSql.execute("insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") - tdSql.execute("insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - - tdSql.execute( - f'''insert into t1 values - ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) - ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) - ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now()+3a ) - ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now()+4a ) - ( '2021-07-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now()+5a ) - ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now()+6a ) - ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) - ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) - ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) - ( '2023-02-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ''' - ) + tdSql.execute(f"insert into {dbname}.ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdLog.info(" prepare data for distributed_aggregate done! ") - def check_distribute_datas(self): + def check_distribute_datas(self, dbname="testdb"): # get vgroup_ids of all - tdSql.query("show vgroups ") + tdSql.query(f"show {dbname}.vgroups ") vgroups = tdSql.queryResult vnode_tables={} - + for vgroup_id in vgroups: vnode_tables[vgroup_id[0]]=[] - + # check sub_table of per vnode ,make sure sub_table has been distributed - tdSql.query("show tables like 'ct%'") + tdSql.query(f"show {dbname}.tables like 'ct%'") table_names = tdSql.queryResult tablenames = [] for table_name in table_names: - vnode_tables[table_name[6]].append(table_name[0]) + vnode_tables[table_name[6]].append(table_name[0]) self.vnode_disbutes = vnode_tables count = 0 @@ -108,74 +81,74 @@ class TDTestCase: count+=1 if count < 2: tdLog.exit(" the datas of all not satisfy sub_table has been distributed ") - - def distribute_agg_query(self): + + def distribute_agg_query(self, dbname="testdb"): # basic filter - tdSql.query("select apercentile(c1 , 20) from stb1 where c1 is null") + tdSql.query(f"select apercentile(c1 , 20) from {dbname}.stb1 where c1 is null") tdSql.checkRows(0) - tdSql.query("select apercentile(c1 , 20) from stb1 where t1=1") + tdSql.query(f"select apercentile(c1 , 20) from {dbname}.stb1 where t1=1") tdSql.checkData(0,0,2.800000000) - tdSql.query("select apercentile(c1+c2 ,100) from stb1 where c1 =1 ") + tdSql.query(f"select apercentile(c1+c2 ,100) from {dbname}.stb1 where c1 =1 ") tdSql.checkData(0,0,11112.000000000) - tdSql.query("select apercentile(c1 ,10 ) from stb1 where tbname=\"ct2\"") + tdSql.query(f"select apercentile(c1 ,10 ) from {dbname}.stb1 where tbname=\"ct2\"") tdSql.checkData(0,0,2.000000000) - tdSql.query("select apercentile(c1,20) from stb1 partition by tbname") + tdSql.query(f"select apercentile(c1,20) from {dbname}.stb1 partition by tbname") tdSql.checkRows(20) - tdSql.query("select apercentile(c1,20) from stb1 where t1> 4 partition by tbname") + tdSql.query(f"select apercentile(c1,20) from {dbname}.stb1 where t1> 4 partition by tbname") tdSql.checkRows(15) - # union all - tdSql.query("select apercentile(c1,20) from stb1 union all select apercentile(c1,20) from stb1 ") + # union all + tdSql.query(f"select apercentile(c1,20) from {dbname}.stb1 union all select apercentile(c1,20) from {dbname}.stb1 ") tdSql.checkRows(2) tdSql.checkData(0,0,7.389181281) - # join + # join tdSql.execute(" create database if not exists db ") tdSql.execute(" use db ") - tdSql.execute(" create stable st (ts timestamp , c1 int ,c2 float) tags(t1 int) ") - tdSql.execute(" create table tb1 using st tags(1) ") - tdSql.execute(" create table tb2 using st tags(2) ") + tdSql.execute(" create stable db.st (ts timestamp , c1 int ,c2 float) tags(t1 int) ") + tdSql.execute(" create table db.tb1 using db.st tags(1) ") + tdSql.execute(" create table db.tb2 using db.st tags(2) ") + - for i in range(10): ts = i*10 + self.ts - tdSql.execute(f" insert into tb1 values({ts},{i},{i}.0)") - tdSql.execute(f" insert into tb2 values({ts},{i},{i}.0)") + tdSql.execute(f" insert into db.tb1 values({ts},{i},{i}.0)") + tdSql.execute(f" insert into db.tb2 values({ts},{i},{i}.0)") - tdSql.query("select apercentile(tb1.c1,100), apercentile(tb2.c2,100) from tb1, tb2 where tb1.ts=tb2.ts") + tdSql.query(f"select apercentile(tb1.c1,100), apercentile(tb2.c2,100) from db.tb1 tb1, db.tb2 tb2 where tb1.ts=tb2.ts") tdSql.checkRows(1) tdSql.checkData(0,0,9.000000000) tdSql.checkData(0,0,9.000000000) - # group by - tdSql.execute(" use testdb ") - tdSql.query(" select max(c1),c1 from stb1 group by t1 ") + # group by + tdSql.execute(f"use {dbname} ") + tdSql.query(f" select max(c1),c1 from {dbname}.stb1 group by t1 ") tdSql.checkRows(20) - tdSql.query(" select max(c1),c1 from stb1 group by c1 ") + tdSql.query(f" select max(c1),c1 from {dbname}.stb1 group by c1 ") tdSql.checkRows(30) - tdSql.query(" select max(c1),c2 from stb1 group by c2 ") + tdSql.query(f" select max(c1),c2 from {dbname}.stb1 group by c2 ") tdSql.checkRows(31) # partition by tbname or partition by tag - tdSql.query("select apercentile(c1 ,10)from stb1 partition by tbname") + tdSql.query(f"select apercentile(c1 ,10)from {dbname}.stb1 partition by tbname") query_data = tdSql.queryResult # nest query for support max - tdSql.query("select apercentile(c2+2,10)+1 from (select max(c1) c2 from stb1)") + tdSql.query(f"select apercentile(c2+2,10)+1 from (select max(c1) c2 from {dbname}.stb1)") tdSql.checkData(0,0,31.000000000) - tdSql.query("select apercentile(c1+2,10)+1 as c2 from (select ts ,c1 ,c2 from stb1)") + tdSql.query(f"select apercentile(c1+2,10)+1 as c2 from (select ts ,c1 ,c2 from {dbname}.stb1)") tdSql.checkData(0,0,7.560701700) - tdSql.query("select apercentile(a+2,10)+1 as c2 from (select ts ,abs(c1) a ,c2 from stb1)") + tdSql.query(f"select apercentile(a+2,10)+1 as c2 from (select ts ,abs(c1) a ,c2 from {dbname}.stb1)") tdSql.checkData(0,0,7.560701700) # mixup with other functions - tdSql.query("select max(c1),count(c1),last(c2,c3),spread(c1), apercentile(c1,10) from stb1") + tdSql.query(f"select max(c1),count(c1),last(c2,c3),spread(c1), apercentile(c1,10) from {dbname}.stb1") tdSql.checkData(0,0,28) tdSql.checkData(0,1,184) tdSql.checkData(0,2,-99999) @@ -189,7 +162,7 @@ class TDTestCase: self.check_distribute_datas() self.distribute_agg_query() - + def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/system-test/2-query/distribute_agg_avg.py b/tests/system-test/2-query/distribute_agg_avg.py index d23a597e92..1b89bb1ff0 100644 --- a/tests/system-test/2-query/distribute_agg_avg.py +++ b/tests/system-test/2-query/distribute_agg_avg.py @@ -7,10 +7,6 @@ import platform class TDTestCase: - updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , - "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, - "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143, - "maxTablesPerVnode":2 ,"minTablesPerVnode":2,"tableIncStepPerVnode":2 } def init(self, conn, logSql): tdLog.debug("start to execute %s" % __file__) @@ -24,7 +20,7 @@ class TDTestCase: avg_sql = f"select avg({col_name}) from {tbname};" same_sql = f"select {col_name} from {tbname} where {col_name} is not null " - + tdSql.query(same_sql) pre_data = np.array(tdSql.queryResult)[np.array(tdSql.queryResult) != None] if (platform.system().lower() == 'windows' and pre_data.dtype == 'int32'): @@ -34,89 +30,66 @@ class TDTestCase: tdSql.query(avg_sql) tdSql.checkData(0,0,pre_avg) - def prepare_datas_of_distribute(self): - + def prepare_datas_of_distribute(self, dbname="testdb"): + # prepate datas for 20 tables distributed at different vgroups - tdSql.execute("create database if not exists testdb keep 3650 duration 1000 vgroups 5") - tdSql.execute(" use testdb ") + tdSql.execute(f"create database if not exists {dbname} keep 3650 duration 1000 vgroups 5") + tdSql.execute(f" use {dbname} ") tdSql.execute( - '''create table stb1 + f'''create table {dbname}.stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t0 timestamp, t1 int, t2 bigint, t3 smallint, t4 tinyint, t5 float, t6 double, t7 bool, t8 binary(16),t9 nchar(32)) ''' ) - tdSql.execute( - ''' - create table t1 - (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) - ''' - ) for i in range(20): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( now(), {1*i}, {11111*i}, {111*i}, {1*i}, {1.11*i}, {11.11*i}, {i%2}, "binary{i}", "nchar{i}" )') + tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( now(), {1*i}, {11111*i}, {111*i}, {1*i}, {1.11*i}, {11.11*i}, {i%2}, "binary{i}", "nchar{i}" )') for i in range(9): tdSql.execute( - f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) tdSql.execute( - f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) for i in range(1,21): if i ==1 or i == 4: continue else: - tbname = "ct"+f'{i}' + tbname = f"{dbname}.ct{i}" for j in range(9): tdSql.execute( f"insert into {tbname} values ( now()-{(i+j)*10}s, {1*(j+i)}, {11111*(j+i)}, {111*(j+i)}, {11*(j)}, {1.11*(j+i)}, {11.11*(j+i)}, {(j+i)%2}, 'binary{j}', 'nchar{j}', now()+{1*j}a )" ) - tdSql.execute("insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") - tdSql.execute("insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - - tdSql.execute( - f'''insert into t1 values - ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) - ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) - ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now()+3a ) - ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now()+4a ) - ( '2021-07-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now()+5a ) - ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now()+6a ) - ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) - ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) - ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) - ( '2023-02-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ''' - ) + tdSql.execute(f"insert into {dbname}.ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdLog.info(" prepare data for distributed_aggregate done! ") - def check_distribute_datas(self): + def check_distribute_datas(self, dbname="testdb"): # get vgroup_ids of all - tdSql.query("show vgroups ") + tdSql.query(f"show {dbname}.vgroups ") vgroups = tdSql.queryResult vnode_tables={} - + for vgroup_id in vgroups: vnode_tables[vgroup_id[0]]=[] - + # check sub_table of per vnode ,make sure sub_table has been distributed - tdSql.query("show tables like 'ct%'") + tdSql.query(f"show {dbname}.tables like 'ct%'") table_names = tdSql.queryResult tablenames = [] for table_name in table_names: - vnode_tables[table_name[6]].append(table_name[0]) + vnode_tables[table_name[6]].append(table_name[0]) self.vnode_disbutes = vnode_tables count = 0 @@ -126,15 +99,15 @@ class TDTestCase: if count < 2: tdLog.exit(" the datas of all not satisfy sub_table has been distributed ") - def check_avg_distribute_diff_vnode(self,col_name): - + def check_avg_distribute_diff_vnode(self,col_name, dbname="testdb"): + vgroup_ids = [] for k ,v in self.vnode_disbutes.items(): if len(v)>=2: vgroup_ids.append(k) - + distribute_tbnames = [] - + for vgroup_id in vgroup_ids: vnode_tables = self.vnode_disbutes[vgroup_id] distribute_tbnames.append(random.sample(vnode_tables,1)[0]) @@ -143,10 +116,10 @@ class TDTestCase: tbname_ins += "'%s' ,"%tbname tbname_filters = tbname_ins[:-1] - - avg_sql = f"select avg({col_name}) from stb1 where tbname in ({tbname_filters});" - same_sql = f"select {col_name} from stb1 where tbname in ({tbname_filters}) and {col_name} is not null " + avg_sql = f"select avg({col_name}) from {dbname}.stb1 where tbname in ({tbname_filters});" + + same_sql = f"select {col_name} from {dbname}.stb1 where tbname in ({tbname_filters}) and {col_name} is not null " tdSql.query(same_sql) pre_data = np.array(tdSql.queryResult)[np.array(tdSql.queryResult) != None] @@ -157,105 +130,105 @@ class TDTestCase: tdSql.query(avg_sql) tdSql.checkData(0,0,pre_avg) - def check_avg_status(self): - # check max function work status - - tdSql.query("show tables like 'ct%'") + def check_avg_status(self, dbname="testdb"): + # check max function work status + + tdSql.query(f"show {dbname}.tables like 'ct%'") table_names = tdSql.queryResult tablenames = [] for table_name in table_names: - tablenames.append(table_name[0]) + tablenames.append(f"{dbname}.{table_name[0]}") - tdSql.query("desc stb1") + tdSql.query(f"desc {dbname}.stb1") col_names = tdSql.queryResult - + colnames = [] for col_name in col_names: if col_name[1] in ["INT" ,"BIGINT" ,"SMALLINT" ,"TINYINT" , "FLOAT" ,"DOUBLE"]: colnames.append(col_name[0]) - + for tablename in tablenames: for colname in colnames: self.check_avg_functions(tablename,colname) - # check max function for different vnode + # check max function for different vnode for colname in colnames: if colname.startswith("c"): - self.check_avg_distribute_diff_vnode(colname) + self.check_avg_distribute_diff_vnode(colname, dbname) else: - # self.check_avg_distribute_diff_vnode(colname) # bug for tag + # self.check_avg_distribute_diff_vnode(colname, dbname) # bug for tag pass - - def distribute_agg_query(self): + + def distribute_agg_query(self, dbname="testdb"): # basic filter - tdSql.query(" select avg(c1) from stb1 ") + tdSql.query(f"select avg(c1) from {dbname}.stb1 ") tdSql.checkData(0,0,14.086956522) - tdSql.query(" select avg(a) from (select avg(c1) a from stb1 partition by tbname) ") + tdSql.query(f"select avg(a) from (select avg(c1) a from {dbname}.stb1 partition by tbname) ") tdSql.checkData(0,0,14.292307692) - tdSql.query(" select avg(c1) from stb1 where t1=1") + tdSql.query(f"select avg(c1) from {dbname}.stb1 where t1=1") tdSql.checkData(0,0,6.000000000) - tdSql.query("select avg(c1+c2) from stb1 where c1 =1 ") + tdSql.query(f"select avg(c1+c2) from {dbname}.stb1 where c1 =1 ") tdSql.checkData(0,0,11112.000000000) - tdSql.query("select avg(c1) from stb1 where tbname=\"ct2\"") + tdSql.query(f"select avg(c1) from {dbname}.stb1 where tbname=\"ct2\"") tdSql.checkData(0,0,6.000000000) - tdSql.query("select avg(c1) from stb1 partition by tbname") + tdSql.query(f"select avg(c1) from {dbname}.stb1 partition by tbname") tdSql.checkRows(20) - tdSql.query("select avg(c1) from stb1 where t1> 4 partition by tbname") + tdSql.query(f"select avg(c1) from {dbname}.stb1 where t1> 4 partition by tbname") tdSql.checkRows(15) - # union all - tdSql.query("select avg(c1) from stb1 union all select avg(c1) from stb1 ") + # union all + tdSql.query(f"select avg(c1) from {dbname}.stb1 union all select avg(c1) from {dbname}.stb1 ") tdSql.checkRows(2) tdSql.checkData(0,0,14.086956522) - tdSql.query("select avg(a) from (select avg(c1) a from stb1 union all select avg(c1) a from stb1)") + tdSql.query(f"select avg(a) from (select avg(c1) a from {dbname}.stb1 union all select avg(c1) a from {dbname}.stb1)") tdSql.checkRows(1) tdSql.checkData(0,0,14.086956522) - # join + # join tdSql.execute(" create database if not exists db ") tdSql.execute(" use db ") - tdSql.execute(" create stable st (ts timestamp , c1 int ,c2 float) tags(t1 int) ") - tdSql.execute(" create table tb1 using st tags(1) ") - tdSql.execute(" create table tb2 using st tags(2) ") + tdSql.execute(" create stable db.st (ts timestamp , c1 int ,c2 float) tags(t1 int) ") + tdSql.execute(" create table db.tb1 using db.st tags(1) ") + tdSql.execute(" create table db.tb2 using db.st tags(2) ") + - for i in range(10): ts = i*10 + self.ts - tdSql.execute(f" insert into tb1 values({ts},{i},{i}.0)") - tdSql.execute(f" insert into tb2 values({ts},{i},{i}.0)") + tdSql.execute(f" insert into db.tb1 values({ts},{i},{i}.0)") + tdSql.execute(f" insert into db.tb2 values({ts},{i},{i}.0)") - tdSql.query("select avg(tb1.c1), avg(tb2.c2) from tb1, tb2 where tb1.ts=tb2.ts") + tdSql.query(f"select avg(tb1.c1), avg(tb2.c2) from db.tb1 tb1, db.tb2 tb2 where tb1.ts=tb2.ts") tdSql.checkRows(1) tdSql.checkData(0,0,4.500000000) tdSql.checkData(0,1,4.500000000) - # group by - tdSql.execute(" use testdb ") + # group by + tdSql.execute(f" use {dbname} ") # partition by tbname or partition by tag - tdSql.query("select avg(c1) from stb1 partition by tbname") + tdSql.query(f"select avg(c1) from {dbname}.stb1 partition by tbname") tdSql.checkRows(20) # nest query for support max - tdSql.query("select avg(c2+2)+1 from (select avg(c1) c2 from stb1)") + tdSql.query(f"select avg(c2+2)+1 from (select avg(c1) c2 from {dbname}.stb1)") tdSql.checkData(0,0,17.086956522) - tdSql.query("select avg(c1+2) as c2 from (select ts ,c1 ,c2 from stb1)") + tdSql.query(f"select avg(c1+2) as c2 from (select ts ,c1 ,c2 from {dbname}.stb1)") tdSql.checkData(0,0,16.086956522) - tdSql.query("select avg(a+2) as c2 from (select ts ,abs(c1) a ,c2 from stb1)") + tdSql.query(f"select avg(a+2) as c2 from (select ts ,abs(c1) a ,c2 from {dbname}.stb1)") tdSql.checkData(0,0,16.086956522) # mixup with other functions - tdSql.query("select max(c1),count(c1),last(c2,c3),sum(c1+c2),avg(c1) from stb1") + tdSql.query(f"select max(c1),count(c1),last(c2,c3),sum(c1+c2),avg(c1) from {dbname}.stb1") tdSql.checkData(0,0,28) tdSql.checkData(0,1,184) tdSql.checkData(0,2,-99999) @@ -270,7 +243,7 @@ class TDTestCase: self.check_avg_status() self.distribute_agg_query() - + def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/system-test/7-tmq/tmqShow.py b/tests/system-test/7-tmq/tmqShow.py index 6b7e7375ff..6f8183bf06 100644 --- a/tests/system-test/7-tmq/tmqShow.py +++ b/tests/system-test/7-tmq/tmqShow.py @@ -51,32 +51,32 @@ class TDTestCase: tdCom.create_ctable(tdSql, dbname=paraDict["dbName"],stbname=paraDict["stbName"],tag_elm_list=paraDict['tagSchema'],count=paraDict["ctbNum"], default_ctbname_prefix=paraDict['ctbPrefix']) # tdLog.info("insert data") # tmqCom.insert_data(tdSql,paraDict["dbName"],paraDict["ctbPrefix"],paraDict["ctbNum"],paraDict["rowsPerTbl"],paraDict["batchNum"],paraDict["startTs"]) - + tdLog.info("create 4 topics") sqlString = "create topic %s as database %s" %(topicNameList[0], paraDict['dbName']) tdLog.info("create topic sql: %s"%sqlString) tdSql.execute(sqlString) - + sqlString = "create topic %s as stable %s.%s" %(topicNameList[1], paraDict['dbName'], paraDict['stbName']) tdLog.info("create topic sql: %s"%sqlString) - tdSql.execute(sqlString) + tdSql.execute(sqlString) queryString = "select * from %s.%s where c1 %% 7 == 0" %(paraDict['dbName'], paraDict['stbName']) sqlString = "create topic %s as %s" %(topicNameList[2], queryString) tdLog.info("create topic sql: %s"%sqlString) tdSql.execute(sqlString) - + queryString = "select ts, log(c1), ceil(pow(c1,3)) from %s.%s where c1 %% 7 == 0" %(paraDict['dbName'], paraDict['stbName']) sqlString = "create topic %s as %s " %(topicNameList[3], queryString) tdLog.info("create topic sql: %s"%sqlString) tdSql.execute(sqlString) tdSql.query("show topics") - tdLog.debug(tdSql.queryResult) + tdLog.debug(tdSql.queryResult) rows = tdSql.getRows() if rows != len(consumerIdList): tdLog.exit("topic rows error") - + for i in range (rows): topicName = tdSql.getData(i,0) matchFlag = 0 @@ -87,24 +87,24 @@ class TDTestCase: break if matchFlag == 0: tdLog.exit("topic name: %s is error", topicName) - + # init consume info, and start tmq_sim, then check consume result tdLog.info("insert consume info to consume processor") expectrowcnt = paraDict["rowsPerTbl"] * paraDict["ctbNum"] topicList = topicNameList[0] ifcheckdata = 0 - ifManualCommit = 0 + ifManualCommit = 0 keyList = 'group.id:%s, enable.auto.commit:false, auto.commit.interval.ms:6000, auto.offset.reset:earliest'%consumeGroupIdList[0] tmqCom.insertConsumerInfo(consumerIdList[0], expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) - + topicList = topicNameList[1] keyList = 'group.id:%s, enable.auto.commit:false, auto.commit.interval.ms:6000, auto.offset.reset:earliest'%consumeGroupIdList[1] tmqCom.insertConsumerInfo(consumerIdList[1], expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) - + topicList = topicNameList[2] keyList = 'group.id:%s, enable.auto.commit:false, auto.commit.interval.ms:6000, auto.offset.reset:earliest'%consumeGroupIdList[2] tmqCom.insertConsumerInfo(consumerIdList[2], expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) - + topicList = topicNameList[3] keyList = 'group.id:%s, enable.auto.commit:false, auto.commit.interval.ms:6000, auto.offset.reset:earliest'%consumeGroupIdList[3] tmqCom.insertConsumerInfo(consumerIdList[3], expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) @@ -118,27 +118,27 @@ class TDTestCase: time.sleep(5) tdLog.info("check show consumers") tdSql.query("show consumers") - # tdLog.info(tdSql.queryResult) + # tdLog.info(tdSql.queryResult) rows = tdSql.getRows() tdLog.info("show consumers rows: %d"%rows) if rows != len(topicNameList): tdLog.exit("show consumers rows error") - - tdLog.info("check show subscriptions") + + tdLog.info("check show subscriptions") tdSql.query("show subscriptions") - # tdLog.debug(tdSql.queryResult) + # tdLog.debug(tdSql.queryResult) rows = tdSql.getRows() tdLog.info("show subscriptions rows: %d"%rows) if rows != paraDict['vgroups'] * len(topicNameList): tdLog.exit("show subscriptions rows error") pThread.join() - + tdLog.info("insert process end, and start to check consume result") expectRows = len(consumerIdList) _ = tmqCom.selectConsumeResult(expectRows) - - time.sleep(10) + + time.sleep(10) for i in range(len(topicNameList)): tdSql.query("drop topic %s"%topicNameList[i]) diff --git a/tests/system-test/fulltest.sh b/tests/system-test/fulltest.sh index 4588474753..d2cbba19b2 100755 --- a/tests/system-test/fulltest.sh +++ b/tests/system-test/fulltest.sh @@ -58,14 +58,36 @@ python3 ./test.py -f 2-query/char_length.py python3 ./test.py -f 2-query/char_length.py -R python3 ./test.py -f 2-query/check_tsdb.py python3 ./test.py -f 2-query/check_tsdb.py -R +python3 ./test.py -f 2-query/concat.py +python3 ./test.py -f 2-query/concat.py -R +python3 ./test.py -f 2-query/concat_ws.py +python3 ./test.py -f 2-query/concat_ws.py -R +python3 ./test.py -f 2-query/concat_ws2.py +python3 ./test.py -f 2-query/concat_ws2.py -R +python3 ./test.py -f 2-query/cos.py +python3 ./test.py -f 2-query/cos.py -R +python3 ./test.py -f 2-query/count_partition.py +python3 ./test.py -f 2-query/count_partition.py -R +python3 ./test.py -f 2-query/count.py +python3 ./test.py -f 2-query/count.py -R +python3 ./test.py -f 2-query/db.py +python3 ./test.py -f 2-query/db.py -R +python3 ./test.py -f 2-query/diff.py +python3 ./test.py -f 2-query/diff.py -R +python3 ./test.py -f 2-query/distinct.py +python3 ./test.py -f 2-query/distinct.py -R +python3 ./test.py -f 2-query/distribute_agg_apercentile.py +python3 ./test.py -f 2-query/distribute_agg_apercentile.py -R +python3 ./test.py -f 2-query/distribute_agg_avg.py +python3 ./test.py -f 2-query/distribute_agg_avg.py -R + + + + python3 ./test.py -f 1-insert/update_data.py python3 ./test.py -f 1-insert/delete_data.py -python3 ./test.py -f 2-query/db.py - -python3 ./test.py -f 2-query/db.py -python3 ./test.py -f 2-query/distinct.py python3 ./test.py -f 2-query/varchar.py python3 ./test.py -f 2-query/ltrim.py python3 ./test.py -f 2-query/rtrim.py @@ -77,10 +99,7 @@ python3 ./test.py -f 2-query/join2.py python3 ./test.py -f 2-query/substr.py python3 ./test.py -f 2-query/union.py python3 ./test.py -f 2-query/union1.py -python3 ./test.py -f 2-query/concat.py python3 ./test.py -f 2-query/concat2.py -python3 ./test.py -f 2-query/concat_ws.py -python3 ./test.py -f 2-query/concat_ws2.py python3 ./test.py -f 2-query/spread.py python3 ./test.py -f 2-query/hyperloglog.py python3 ./test.py -f 2-query/explain.py @@ -93,13 +112,11 @@ python3 ./test.py -f 2-query/Now.py python3 ./test.py -f 2-query/Today.py python3 ./test.py -f 2-query/max.py python3 ./test.py -f 2-query/min.py -python3 ./test.py -f 2-query/count.py python3 ./test.py -f 2-query/last.py python3 ./test.py -f 2-query/first.py python3 ./test.py -f 2-query/To_iso8601.py python3 ./test.py -f 2-query/To_unixtimestamp.py python3 ./test.py -f 2-query/timetruncate.py -python3 ./test.py -f 2-query/diff.py python3 ./test.py -f 2-query/Timediff.py python3 ./test.py -f 2-query/json_tag.py @@ -111,7 +128,6 @@ python3 ./test.py -f 2-query/log.py python3 ./test.py -f 2-query/pow.py python3 ./test.py -f 2-query/sqrt.py python3 ./test.py -f 2-query/sin.py -python3 ./test.py -f 2-query/cos.py python3 ./test.py -f 2-query/tan.py python3 ./test.py -f 2-query/query_cols_tags_and_or.py # python3 ./test.py -f 2-query/nestedQuery.py @@ -122,7 +138,6 @@ python3 ./test.py -f 2-query/query_cols_tags_and_or.py python3 ./test.py -f 2-query/elapsed.py python3 ./test.py -f 2-query/csum.py python3 ./test.py -f 2-query/mavg.py -python3 ./test.py -f 2-query/diff.py python3 ./test.py -f 2-query/sample.py python3 ./test.py -f 2-query/function_diff.py python3 ./test.py -f 2-query/unique.py @@ -136,12 +151,9 @@ python3 ./test.py -f 2-query/distribute_agg_max.py python3 ./test.py -f 2-query/distribute_agg_min.py python3 ./test.py -f 2-query/distribute_agg_sum.py python3 ./test.py -f 2-query/distribute_agg_spread.py -python3 ./test.py -f 2-query/distribute_agg_apercentile.py -python3 ./test.py -f 2-query/distribute_agg_avg.py python3 ./test.py -f 2-query/distribute_agg_stddev.py python3 ./test.py -f 2-query/twa.py python3 ./test.py -f 2-query/irate.py -python3 ./test.py -f 2-query/count_partition.py python3 ./test.py -f 2-query/function_null.py python3 ./test.py -f 2-query/queryQnode.py python3 ./test.py -f 2-query/max_partition.py @@ -162,9 +174,9 @@ python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateStb.py -N 5 # python3 test.py -f 6-cluster/5dnode3mnodeStopConnect.py -N 5 -M 3 # BUG Redict python3 ./test.py -f 6-cluster/5dnode3mnodeAdd1Ddnoe.py -N 6 -M 3 -C 5 # python3 ./test.py -f 6-cluster/5dnode3mnodeRestartDnodeInsertData.py -N 5 -M 3 - python3 ./test.py -f 6-cluster/5dnode3mnodeAdd1Ddnoe.py -N 6 -M 3 -C 5 + python3 ./test.py -f 6-cluster/5dnode3mnodeAdd1Ddnoe.py -N 6 -M 3 -C 5 + - python3 ./test.py -f 7-tmq/basic5.py python3 ./test.py -f 7-tmq/subscribeDb.py python3 ./test.py -f 7-tmq/subscribeDb0.py @@ -281,7 +293,6 @@ python3 ./test.py -f 2-query/avg.py -Q 2 # python3 ./test.py -f 2-query/elapsed.py -Q 2 python3 ./test.py -f 2-query/csum.py -Q 2 python3 ./test.py -f 2-query/mavg.py -Q 2 -python3 ./test.py -f 2-query/diff.py -Q 2 python3 ./test.py -f 2-query/sample.py -Q 2 python3 ./test.py -f 2-query/function_diff.py -Q 2 python3 ./test.py -f 2-query/unique.py -Q 2 @@ -369,7 +380,6 @@ python3 ./test.py -f 2-query/query_cols_tags_and_or.py -Q 3 # python3 ./test.py -f 2-query/elapsed.py -Q 3 python3 ./test.py -f 2-query/csum.py -Q 3 python3 ./test.py -f 2-query/mavg.py -Q 3 -python3 ./test.py -f 2-query/diff.py -Q 3 python3 ./test.py -f 2-query/sample.py -Q 3 python3 ./test.py -f 2-query/function_diff.py -Q 3 python3 ./test.py -f 2-query/unique.py -Q 3 From cd0e66a694c5a5315847349f4e51a73b197b5d89 Mon Sep 17 00:00:00 2001 From: cpwu Date: Fri, 22 Jul 2022 09:45:56 +0800 Subject: [PATCH 02/20] fix case --- .../2-query/distribute_agg_apercentile.py | 1 + .../system-test/2-query/distribute_agg_avg.py | 1 + .../2-query/distribute_agg_count.py | 186 +++++++--------- .../system-test/2-query/distribute_agg_max.py | 195 ++++++++--------- .../system-test/2-query/distribute_agg_min.py | 201 ++++++++---------- tests/system-test/fulltest.sh | 9 +- 6 files changed, 257 insertions(+), 336 deletions(-) diff --git a/tests/system-test/2-query/distribute_agg_apercentile.py b/tests/system-test/2-query/distribute_agg_apercentile.py index 591824fdd3..1fd853f9eb 100644 --- a/tests/system-test/2-query/distribute_agg_apercentile.py +++ b/tests/system-test/2-query/distribute_agg_apercentile.py @@ -7,6 +7,7 @@ import random class TDTestCase: + updatecfgDict = {"maxTablesPerVnode":2 ,"minTablesPerVnode":2,"tableIncStepPerVnode":2 } def init(self, conn, logSql): tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/distribute_agg_avg.py b/tests/system-test/2-query/distribute_agg_avg.py index 1b89bb1ff0..3892ae0da1 100644 --- a/tests/system-test/2-query/distribute_agg_avg.py +++ b/tests/system-test/2-query/distribute_agg_avg.py @@ -8,6 +8,7 @@ import platform class TDTestCase: + updatecfgDict = {"maxTablesPerVnode":2 ,"minTablesPerVnode":2,"tableIncStepPerVnode":2 } def init(self, conn, logSql): tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/distribute_agg_count.py b/tests/system-test/2-query/distribute_agg_count.py index ebca81545c..835d1eeb57 100644 --- a/tests/system-test/2-query/distribute_agg_count.py +++ b/tests/system-test/2-query/distribute_agg_count.py @@ -2,15 +2,12 @@ from util.log import * from util.cases import * from util.sql import * import numpy as np -import random +import random class TDTestCase: - updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , - "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, - "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143, - "maxTablesPerVnode":2 ,"minTablesPerVnode":2,"tableIncStepPerVnode":2 } + updatecfgDict = {"maxTablesPerVnode":2 ,"minTablesPerVnode":2,"tableIncStepPerVnode":2 } def init(self, conn, logSql): tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) @@ -25,7 +22,7 @@ class TDTestCase: same_sql = f"select sum(c) from (select {col_name} ,1 as c from {tbname} where {col_name} is not null) " tdSql.query(max_sql) - max_result = tdSql.queryResult + max_result = tdSql.queryResult tdSql.query(same_sql) same_result = tdSql.queryResult @@ -35,90 +32,66 @@ class TDTestCase: else: tdLog.info(" count function work as expected, sql : %s "% max_sql) + def prepare_datas_of_distribute(self, dbname="testdb"): - def prepare_datas_of_distribute(self): - # prepate datas for 20 tables distributed at different vgroups - tdSql.execute("create database if not exists testdb keep 3650 duration 1000 vgroups 5") - tdSql.execute(" use testdb ") + tdSql.execute(f"create database if not exists {dbname} keep 3650 duration 1000 vgroups 5") + tdSql.execute(f" use {dbname} ") tdSql.execute( - '''create table stb1 + f'''create table {dbname}.stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t0 timestamp, t1 int, t2 bigint, t3 smallint, t4 tinyint, t5 float, t6 double, t7 bool, t8 binary(16),t9 nchar(32)) ''' ) - tdSql.execute( - ''' - create table t1 - (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) - ''' - ) for i in range(20): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( now(), {1*i}, {11111*i}, {111*i}, {1*i}, {1.11*i}, {11.11*i}, {i%2}, "binary{i}", "nchar{i}" )') + tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( now(), {1*i}, {11111*i}, {111*i}, {1*i}, {1.11*i}, {11.11*i}, {i%2}, "binary{i}", "nchar{i}" )') for i in range(9): tdSql.execute( - f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) tdSql.execute( - f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) for i in range(1,21): if i ==1 or i == 4: continue else: - tbname = "ct"+f'{i}' + tbname = f"{dbname}.ct{i}" for j in range(9): tdSql.execute( f"insert into {tbname} values ( now()-{(i+j)*10}s, {1*(j+i)}, {11111*(j+i)}, {111*(j+i)}, {11*(j)}, {1.11*(j+i)}, {11.11*(j+i)}, {(j+i)%2}, 'binary{j}', 'nchar{j}', now()+{1*j}a )" ) - tdSql.execute("insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") - tdSql.execute("insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - - tdSql.execute( - f'''insert into t1 values - ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) - ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) - ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now()+3a ) - ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now()+4a ) - ( '2021-07-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now()+5a ) - ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now()+6a ) - ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) - ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) - ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) - ( '2023-02-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ''' - ) + tdSql.execute(f"insert into {dbname}.ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdLog.info(" prepare data for distributed_aggregate done! ") - def check_distribute_datas(self): + def check_distribute_datas(self, dbname="testdb"): # get vgroup_ids of all - tdSql.query("show vgroups ") + tdSql.query(f"show {dbname}.vgroups ") vgroups = tdSql.queryResult vnode_tables={} - + for vgroup_id in vgroups: vnode_tables[vgroup_id[0]]=[] - + # check sub_table of per vnode ,make sure sub_table has been distributed - tdSql.query("show tables like 'ct%'") + tdSql.query(f"show {dbname}.tables like 'ct%'") table_names = tdSql.queryResult tablenames = [] for table_name in table_names: - vnode_tables[table_name[6]].append(table_name[0]) + vnode_tables[table_name[6]].append(table_name[0]) self.vnode_disbutes = vnode_tables count = 0 @@ -128,15 +101,15 @@ class TDTestCase: if count < 2: tdLog.exit(" the datas of all not satisfy sub_table has been distributed ") - def check_count_distribute_diff_vnode(self,col_name): - + def check_count_distribute_diff_vnode(self,col_name, dbname="testdb"): + vgroup_ids = [] for k ,v in self.vnode_disbutes.items(): if len(v)>=2: vgroup_ids.append(k) - + distribute_tbnames = [] - + for vgroup_id in vgroup_ids: vnode_tables = self.vnode_disbutes[vgroup_id] distribute_tbnames.append(random.sample(vnode_tables,1)[0]) @@ -145,13 +118,13 @@ class TDTestCase: tbname_ins += "'%s' ,"%tbname tbname_filters = tbname_ins[:-1] - - max_sql = f"select count({col_name}) from stb1 where tbname in ({tbname_filters});" - same_sql = f"select sum(c) from (select {col_name} ,1 as c from stb1 where tbname in ({tbname_filters}) and {col_name} is not null) " + max_sql = f"select count({col_name}) from {dbname}.stb1 where tbname in ({tbname_filters});" + + same_sql = f"select sum(c) from (select {col_name} ,1 as c from {dbname}.stb1 where tbname in ({tbname_filters}) and {col_name} is not null) " tdSql.query(max_sql) - max_result = tdSql.queryResult + max_result = tdSql.queryResult tdSql.query(same_sql) same_result = tdSql.queryResult @@ -161,120 +134,119 @@ class TDTestCase: else: tdLog.info(" count function work as expected, sql : %s "% max_sql) - def check_count_status(self): - # check max function work status - - tdSql.query("show tables like 'ct%'") + def check_count_status(self, dbname="testdb"): + # check max function work status + + tdSql.query(f"show {dbname}.tables like 'ct%'") table_names = tdSql.queryResult tablenames = [] for table_name in table_names: - tablenames.append(table_name[0]) + tablenames.append(f"{dbname}.{table_name[0]}") - tdSql.query("desc stb1") + tdSql.query(f"desc {dbname}.stb1") col_names = tdSql.queryResult - + colnames = [] for col_name in col_names: if col_name[1] in ["INT" ,"BIGINT" ,"SMALLINT" ,"TINYINT" , "FLOAT" ,"DOUBLE"]: colnames.append(col_name[0]) - + for tablename in tablenames: for colname in colnames: self.check_count_functions(tablename,colname) - # check max function for different vnode + # check max function for different vnode for colname in colnames: if colname.startswith("c"): - self.check_count_distribute_diff_vnode(colname) + self.check_count_distribute_diff_vnode(colname, dbname) else: - # self.check_count_distribute_diff_vnode(colname) # bug for tag + # self.check_count_distribute_diff_vnode(colname, dbname) # bug for tag pass - - def distribute_agg_query(self): + def distribute_agg_query(self, dbname="testdb"): # basic filter - tdSql.query("select count(c1) from stb1 ") + tdSql.query(f"select count(c1) from {dbname}.stb1 ") tdSql.checkData(0,0,184) - tdSql.query("select count(c1) from stb1 where t1=1") + tdSql.query(f"select count(c1) from {dbname}.stb1 where t1=1") tdSql.checkData(0,0,9) - tdSql.query("select count(c1+c2) from stb1 where c1 =1 ") + tdSql.query(f"select count(c1+c2) from {dbname}.stb1 where c1 =1 ") tdSql.checkData(0,0,2) - tdSql.query("select count(c1) from stb1 where tbname=\"ct2\"") + tdSql.query(f"select count(c1) from {dbname}.stb1 where tbname=\"ct2\"") tdSql.checkData(0,0,9) - tdSql.query("select count(c1) from stb1 partition by tbname") + tdSql.query(f"select count(c1) from {dbname}.stb1 partition by tbname") tdSql.checkRows(20) - tdSql.query("select count(c1) from stb1 where t1> 4 partition by tbname") + tdSql.query(f"select count(c1) from {dbname}.stb1 where t1> 4 partition by tbname") tdSql.checkRows(15) - # union all - tdSql.query("select count(c1) from stb1 union all select count(c1) from stb1 ") + # union all + tdSql.query(f"select count(c1) from {dbname}.stb1 union all select count(c1) from {dbname}.stb1 ") tdSql.checkRows(2) tdSql.checkData(0,0,184) - # join + # join tdSql.execute(" create database if not exists db ") tdSql.execute(" use db ") - tdSql.execute(" create stable st (ts timestamp , c1 int ,c2 float) tags(t1 int) ") - tdSql.execute(" create table tb1 using st tags(1) ") - tdSql.execute(" create table tb2 using st tags(2) ") + tdSql.execute(" create stable db.st (ts timestamp , c1 int ,c2 float) tags(t1 int) ") + tdSql.execute(" create table db.tb1 using db.st tags(1) ") + tdSql.execute(" create table db.tb2 using db.st tags(2) ") + - for i in range(10): ts = i*10 + self.ts - tdSql.execute(f" insert into tb1 values({ts},{i},{i}.0)") - tdSql.execute(f" insert into tb2 values({ts},{i},{i}.0)") + tdSql.execute(f" insert into db.tb1 values({ts},{i},{i}.0)") + tdSql.execute(f" insert into db.tb2 values({ts},{i},{i}.0)") - tdSql.query("select count(tb1.c1), count(tb2.c2) from tb1, tb2 where tb1.ts=tb2.ts") + tdSql.query(f"select count(tb1.c1), count(tb2.c2) from db.tb1 tb1, db.tb2 tb2 where tb1.ts=tb2.ts") tdSql.checkRows(1) tdSql.checkData(0,0,10) tdSql.checkData(0,1,10) - # group by - tdSql.execute(" use testdb ") + # group by + tdSql.execute(f" use {dbname} ") - tdSql.query(" select count(*) from stb1 ") + tdSql.query(f"select count(*) from {dbname}.stb1 ") tdSql.checkData(0,0,187) - tdSql.query(" select count(*) from stb1 group by t1 ") + tdSql.query(f"select count(*) from {dbname}.stb1 group by t1 ") tdSql.checkRows(20) - tdSql.query(" select count(*) from stb1 group by c1 ") + tdSql.query(f"select count(*) from {dbname}.stb1 group by c1 ") tdSql.checkRows(30) - tdSql.query(" select count(*) from stb1 group by c2 ") + tdSql.query(f"select count(*) from {dbname}.stb1 group by c2 ") tdSql.checkRows(31) # partition by tbname or partition by tag - tdSql.query("select max(c1),tbname from stb1 partition by tbname") + tdSql.query(f"select max(c1),tbname from {dbname}.stb1 partition by tbname") query_data = tdSql.queryResult - + for row in query_data: - tbname = row[1] - tdSql.query(" select max(c1) from %s "%tbname) + tbname = f"{dbname}.{row[1]}" + tdSql.query(f"select max(c1) from %s "%tbname) tdSql.checkData(0,0,row[0]) - tdSql.query("select max(c1),tbname from stb1 partition by t1") + tdSql.query(f"select max(c1),tbname from {dbname}.stb1 partition by t1") query_data = tdSql.queryResult - + for row in query_data: - tbname = row[1] - tdSql.query(" select max(c1) from %s "%tbname) + tbname = f"{dbname}.{row[1]}" + tdSql.query(f"select max(c1) from %s "%tbname) tdSql.checkData(0,0,row[0]) # nest query for support max - tdSql.query("select abs(c2+2)+1 from (select count(c1) c2 from stb1)") + tdSql.query(f"select abs(c2+2)+1 from (select count(c1) c2 from {dbname}.stb1)") tdSql.checkData(0,0,187.000000000) - tdSql.query("select count(c1+2) as c2 from (select ts ,c1 ,c2 from stb1)") + tdSql.query(f"select count(c1+2) as c2 from (select ts ,c1 ,c2 from {dbname}.stb1)") tdSql.checkData(0,0,184) - tdSql.query("select count(a+2) as c2 from (select ts ,abs(c1) a ,c2 from stb1)") + tdSql.query(f"select count(a+2) as c2 from (select ts ,abs(c1) a ,c2 from {dbname}.stb1)") tdSql.checkData(0,0,184) # mixup with other functions - tdSql.query("select max(c1),count(c1),last(c2,c3) from stb1") + tdSql.query(f"select max(c1),count(c1),last(c2,c3) from {dbname}.stb1") tdSql.checkData(0,0,28) tdSql.checkData(0,1,184) tdSql.checkData(0,2,-99999) @@ -287,7 +259,7 @@ class TDTestCase: self.check_count_status() self.distribute_agg_query() - + def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/system-test/2-query/distribute_agg_max.py b/tests/system-test/2-query/distribute_agg_max.py index c7e074095b..a7b31a2084 100644 --- a/tests/system-test/2-query/distribute_agg_max.py +++ b/tests/system-test/2-query/distribute_agg_max.py @@ -2,14 +2,12 @@ from util.log import * from util.cases import * from util.sql import * import numpy as np -import random +import random class TDTestCase: - updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , - "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, - "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143, - "maxTablesPerVnode":2 ,"minTablesPerVnode":2,"tableIncStepPerVnode":2 } + + updatecfgDict = {"maxTablesPerVnode":2 ,"minTablesPerVnode":2,"tableIncStepPerVnode":2 } def init(self, conn, logSql): tdLog.debug("start to execute %s" % __file__) @@ -25,7 +23,7 @@ class TDTestCase: same_sql = f"select {col_name} from {tbname} order by {col_name} desc limit 1" tdSql.query(max_sql) - max_result = tdSql.queryResult + max_result = tdSql.queryResult tdSql.query(same_sql) same_result = tdSql.queryResult @@ -36,89 +34,65 @@ class TDTestCase: tdLog.info(" max function work as expected, sql : %s "% max_sql) - def prepare_datas_of_distribute(self): - + def prepare_datas_of_distribute(self, dbname="testdb"): + # prepate datas for 20 tables distributed at different vgroups - tdSql.execute("create database if not exists testdb keep 3650 duration 1000 vgroups 5") - tdSql.execute(" use testdb ") + tdSql.execute(f"create database if not exists {dbname} keep 3650 duration 1000 vgroups 5") + tdSql.execute(f" use {dbname} ") tdSql.execute( - '''create table stb1 + f'''create table {dbname}.stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t0 timestamp, t1 int, t2 bigint, t3 smallint, t4 tinyint, t5 float, t6 double, t7 bool, t8 binary(16),t9 nchar(32)) ''' ) - tdSql.execute( - ''' - create table t1 - (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) - ''' - ) for i in range(20): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( now(), {1*i}, {11111*i}, {111*i}, {1*i}, {1.11*i}, {11.11*i}, {i%2}, "binary{i}", "nchar{i}" )') + tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( now(), {1*i}, {11111*i}, {111*i}, {1*i}, {1.11*i}, {11.11*i}, {i%2}, "binary{i}", "nchar{i}" )') for i in range(9): tdSql.execute( - f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) tdSql.execute( - f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) for i in range(1,21): if i ==1 or i == 4: continue else: - tbname = "ct"+f'{i}' + tbname = f"{dbname}.ct{i}" for j in range(9): tdSql.execute( f"insert into {tbname} values ( now()-{(i+j)*10}s, {1*(j+i)}, {11111*(j+i)}, {111*(j+i)}, {11*(j)}, {1.11*(j+i)}, {11.11*(j+i)}, {(j+i)%2}, 'binary{j}', 'nchar{j}', now()+{1*j}a )" ) - tdSql.execute("insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") - tdSql.execute("insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - - tdSql.execute( - f'''insert into t1 values - ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) - ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) - ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now()+3a ) - ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now()+4a ) - ( '2021-07-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now()+5a ) - ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now()+6a ) - ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) - ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) - ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) - ( '2023-02-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ''' - ) + tdSql.execute(f"insert into {dbname}.ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdLog.info(" prepare data for distributed_aggregate done! ") - def check_distribute_datas(self): + def check_distribute_datas(self, dbname="testdb"): # get vgroup_ids of all - tdSql.query("show vgroups ") + tdSql.query(f"show {dbname}.vgroups ") vgroups = tdSql.queryResult vnode_tables={} - + for vgroup_id in vgroups: vnode_tables[vgroup_id[0]]=[] - # check sub_table of per vnode ,make sure sub_table has been distributed - tdSql.query("show tables like 'ct%'") + tdSql.query(f"show {dbname}.tables like 'ct%'") table_names = tdSql.queryResult tablenames = [] for table_name in table_names: - vnode_tables[table_name[6]].append(table_name[0]) + vnode_tables[table_name[6]].append(table_name[0]) self.vnode_disbutes = vnode_tables count = 0 @@ -128,15 +102,15 @@ class TDTestCase: if count < 2: tdLog.exit(" the datas of all not satisfy sub_table has been distributed ") - def check_max_distribute_diff_vnode(self,col_name): - + def check_max_distribute_diff_vnode(self,col_name, dbname="testdb"): + vgroup_ids = [] for k ,v in self.vnode_disbutes.items(): if len(v)>=2: vgroup_ids.append(k) - + distribute_tbnames = [] - + for vgroup_id in vgroup_ids: vnode_tables = self.vnode_disbutes[vgroup_id] distribute_tbnames.append(random.sample(vnode_tables,1)[0]) @@ -145,13 +119,13 @@ class TDTestCase: tbname_ins += "'%s' ,"%tbname tbname_filters = tbname_ins[:-1] - - max_sql = f"select max({col_name}) from stb1 where tbname in ({tbname_filters});" - same_sql = f"select {col_name} from stb1 where tbname in ({tbname_filters}) order by {col_name} desc limit 1" + max_sql = f"select max({col_name}) from {dbname}.stb1 where tbname in ({tbname_filters});" + + same_sql = f"select {col_name} from {dbname}.stb1 where tbname in ({tbname_filters}) order by {col_name} desc limit 1" tdSql.query(max_sql) - max_result = tdSql.queryResult + max_result = tdSql.queryResult tdSql.query(same_sql) same_result = tdSql.queryResult @@ -161,138 +135,137 @@ class TDTestCase: else: tdLog.info(" max function work as expected, sql : %s "% max_sql) - def check_max_status(self): - # check max function work status - - tdSql.query("show tables like 'ct%'") + def check_max_status(self, dbname="testdb"): + # check max function work status + + tdSql.query(f"show {dbname}.tables like 'ct%'") table_names = tdSql.queryResult tablenames = [] for table_name in table_names: - tablenames.append(table_name[0]) + tablenames.append(f"{dbname}.{table_name[0]}") - tdSql.query("desc stb1") + tdSql.query(f"desc {dbname}.stb1") col_names = tdSql.queryResult - + colnames = [] for col_name in col_names: if col_name[1] in ["INT" ,"BIGINT" ,"SMALLINT" ,"TINYINT" , "FLOAT" ,"DOUBLE"]: colnames.append(col_name[0]) - + for tablename in tablenames: for colname in colnames: self.check_max_functions(tablename,colname) - # check max function for different vnode + # check max function for different vnode for colname in colnames: if colname.startswith("c"): - self.check_max_distribute_diff_vnode(colname) + self.check_max_distribute_diff_vnode(colname, dbname) else: - # self.check_max_distribute_diff_vnode(colname) # bug for tag + # self.check_max_distribute_diff_vnode(colname, dbname) # bug for tag pass - - def distribute_agg_query(self): + def distribute_agg_query(self, dbname="testdb"): # basic filter - tdSql.query("select max(c1) from stb1 where c1 is null") + tdSql.query(f"select max(c1) from {dbname}.stb1 where c1 is null") tdSql.checkRows(0) - tdSql.query("select max(c1) from stb1 where t1=1") + tdSql.query(f"select max(c1) from {dbname}.stb1 where t1=1") tdSql.checkData(0,0,10) - tdSql.query("select max(c1+c2) from stb1 where c1 =1 ") + tdSql.query(f"select max(c1+c2) from {dbname}.stb1 where c1 =1 ") tdSql.checkData(0,0,11112.000000000) - tdSql.query("select max(c1) from stb1 where tbname=\"ct2\"") + tdSql.query(f"select max(c1) from {dbname}.stb1 where tbname=\"ct2\"") tdSql.checkData(0,0,10) - tdSql.query("select max(c1) from stb1 partition by tbname") + tdSql.query(f"select max(c1) from {dbname}.stb1 partition by tbname") tdSql.checkRows(20) - tdSql.query("select max(c1) from stb1 where t1> 4 partition by tbname") + tdSql.query(f"select max(c1) from {dbname}.stb1 where t1> 4 partition by tbname") tdSql.checkRows(15) - # union all - tdSql.query("select max(c1) from stb1 union all select max(c1) from stb1 ") + # union all + tdSql.query(f"select max(c1) from {dbname}.stb1 union all select max(c1) from {dbname}.stb1 ") tdSql.checkRows(2) tdSql.checkData(0,0,28) - # join + # join tdSql.execute(" create database if not exists db ") tdSql.execute(" use db ") - tdSql.execute(" create stable st (ts timestamp , c1 int ,c2 float) tags(t1 int) ") - tdSql.execute(" create table tb1 using st tags(1) ") - tdSql.execute(" create table tb2 using st tags(2) ") + tdSql.execute(" create stable db.st (ts timestamp , c1 int ,c2 float) tags(t1 int) ") + tdSql.execute(" create table db.tb1 using db.st tags(1) ") + tdSql.execute(" create table db.tb2 using db.st tags(2) ") + - for i in range(10): ts = i*10 + self.ts - tdSql.execute(f" insert into tb1 values({ts},{i},{i}.0)") - tdSql.execute(f" insert into tb2 values({ts},{i},{i}.0)") + tdSql.execute(f" insert into db.tb1 values({ts},{i},{i}.0)") + tdSql.execute(f" insert into db.tb2 values({ts},{i},{i}.0)") - tdSql.query("select max(tb1.c1), tb2.c2 from tb1, tb2 where tb1.ts=tb2.ts") + tdSql.query(f"select max(tb1.c1), tb2.c2 from db.tb1 tb1, db.tb2 tb2 where tb1.ts=tb2.ts") tdSql.checkRows(1) tdSql.checkData(0,0,9) tdSql.checkData(0,0,9.00000) - # group by - tdSql.execute(" use testdb ") - tdSql.query(" select max(c1),c1 from stb1 group by t1 ") + # group by + tdSql.execute("use testdb ") + tdSql.query(f"select max(c1),c1 from {dbname}.stb1 group by t1 ") tdSql.checkRows(20) - tdSql.query(" select max(c1),c1 from stb1 group by c1 ") + tdSql.query(f"select max(c1),c1 from {dbname}.stb1 group by c1 ") tdSql.checkRows(30) - tdSql.query(" select max(c1),c2 from stb1 group by c2 ") + tdSql.query(f"select max(c1),c2 from {dbname}.stb1 group by c2 ") tdSql.checkRows(31) # selective common cols of datas - tdSql.query("select max(c1),c2,c3,c5 from stb1") + tdSql.query(f"select max(c1),c2,c3,c5 from {dbname}.stb1") tdSql.checkRows(1) tdSql.checkData(0,0,28) tdSql.checkData(0,1,311108) tdSql.checkData(0,2,3108) tdSql.checkData(0,3,31.08000) - tdSql.query("select max(c1),t1,c2,t3 from stb1") + tdSql.query(f"select max(c1),t1,c2,t3 from {dbname}.stb1") tdSql.checkRows(1) tdSql.checkData(0,0,28) tdSql.checkData(0,1,19) tdSql.checkData(0,2,311108) - tdSql.query("select max(c1),ceil(t1),pow(c2,1)+2,abs(t3) from stb1") + tdSql.query(f"select max(c1),ceil(t1),pow(c2,1)+2,abs(t3) from {dbname}.stb1") tdSql.checkRows(1) tdSql.checkData(0,0,28) tdSql.checkData(0,1,19) - tdSql.checkData(0,2,311110.000000000) - tdSql.checkData(0,3,2109) + tdSql.checkData(0,2,311110.000000000) + tdSql.checkData(0,3,2109) # partition by tbname or partition by tag - tdSql.query("select max(c1),tbname from stb1 partition by tbname") + tdSql.query(f"select max(c1),tbname from {dbname}.stb1 partition by tbname") query_data = tdSql.queryResult - + for row in query_data: - tbname = row[1] - tdSql.query(" select max(c1) from %s "%tbname) + tbname = f"{dbname}.{row[1]}" + tdSql.query(f"select max(c1) from %s "%tbname) tdSql.checkData(0,0,row[0]) - tdSql.query("select max(c1),tbname from stb1 partition by t1") + tdSql.query(f"select max(c1),tbname from {dbname}.stb1 partition by t1") query_data = tdSql.queryResult - + for row in query_data: - tbname = row[1] - tdSql.query(" select max(c1) from %s "%tbname) + tbname = f"{dbname}.{row[1]}" + tdSql.query(f"select max(c1) from %s "%tbname) tdSql.checkData(0,0,row[0]) # nest query for support max - tdSql.query("select abs(c2+2)+1 from (select max(c1) c2 from stb1)") + tdSql.query(f"select abs(c2+2)+1 from (select max(c1) c2 from {dbname}.stb1)") tdSql.checkData(0,0,31.000000000) - tdSql.query("select max(c1+2)+1 as c2 from (select ts ,c1 ,c2 from stb1)") + tdSql.query(f"select max(c1+2)+1 as c2 from (select ts ,c1 ,c2 from {dbname}.stb1)") tdSql.checkData(0,0,31.000000000) - tdSql.query("select max(a+2)+1 as c2 from (select ts ,abs(c1) a ,c2 from stb1)") + tdSql.query(f"select max(a+2)+1 as c2 from (select ts ,abs(c1) a ,c2 from {dbname}.stb1)") tdSql.checkData(0,0,31.000000000) # mixup with other functions - tdSql.query("select max(c1),count(c1),last(c2,c3) from stb1") + tdSql.query(f"select max(c1),count(c1),last(c2,c3) from {dbname}.stb1") tdSql.checkData(0,0,28) tdSql.checkData(0,1,184) tdSql.checkData(0,2,-99999) @@ -305,7 +278,7 @@ class TDTestCase: self.check_max_status() self.distribute_agg_query() - + def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/system-test/2-query/distribute_agg_min.py b/tests/system-test/2-query/distribute_agg_min.py index d8f93a01f5..6fea94b61f 100644 --- a/tests/system-test/2-query/distribute_agg_min.py +++ b/tests/system-test/2-query/distribute_agg_min.py @@ -2,14 +2,12 @@ from util.log import * from util.cases import * from util.sql import * import numpy as np -import random +import random class TDTestCase: - updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , - "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, - "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143, - "maxTablesPerVnode":2 ,"minTablesPerVnode":2,"tableIncStepPerVnode":2 } + + updatecfgDict = {"maxTablesPerVnode":2 ,"minTablesPerVnode":2,"tableIncStepPerVnode":2 } def init(self, conn, logSql): tdLog.debug("start to execute %s" % __file__) @@ -25,7 +23,7 @@ class TDTestCase: same_sql = f"select {col_name} from {tbname} where {col_name} is not null order by {col_name} asc limit 1" tdSql.query(min_sql) - min_result = tdSql.queryResult + min_result = tdSql.queryResult tdSql.query(same_sql) same_result = tdSql.queryResult @@ -35,90 +33,65 @@ class TDTestCase: else: tdLog.info(" min function work as expected, sql : %s "% min_sql) + def prepare_datas_of_distribute(self, dbname="testdb"): - def prepare_datas_of_distribute(self): - # prepate datas for 20 tables distributed at different vgroups - tdSql.execute("create database if not exists testdb keep 3650 duration 1000 vgroups 5") - tdSql.execute(" use testdb ") + tdSql.execute(f"create database if not exists {dbname} keep 3650 duration 1000 vgroups 5") + tdSql.execute(f" use {dbname} ") tdSql.execute( - '''create table stb1 + f'''create table {dbname}.stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t0 timestamp, t1 int, t2 bigint, t3 smallint, t4 tinyint, t5 float, t6 double, t7 bool, t8 binary(16),t9 nchar(32)) ''' ) - tdSql.execute( - ''' - create table t1 - (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) - ''' - ) for i in range(20): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( now(), {1*i}, {11111*i}, {111*i}, {1*i}, {1.11*i}, {11.11*i}, {i%2}, "binary{i}", "nchar{i}" )') + tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( now(), {1*i}, {11111*i}, {111*i}, {1*i}, {1.11*i}, {11.11*i}, {i%2}, "binary{i}", "nchar{i}" )') for i in range(9): tdSql.execute( - f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) tdSql.execute( - f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) for i in range(1,21): if i ==1 or i == 4: continue else: - tbname = "ct"+f'{i}' + tbname = f"{dbname}.ct{i}" for j in range(9): tdSql.execute( f"insert into {tbname} values ( now()-{(i+j)*10}s, {1*(j+i)}, {11111*(j+i)}, {111*(j+i)}, {11*(j)}, {1.11*(j+i)}, {11.11*(j+i)}, {(j+i)%2}, 'binary{j}', 'nchar{j}', now()+{1*j}a )" ) - tdSql.execute("insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") - tdSql.execute("insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - - tdSql.execute( - f'''insert into t1 values - ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) - ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) - ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now()+3a ) - ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now()+4a ) - ( '2021-07-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now()+5a ) - ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now()+6a ) - ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) - ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) - ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) - ( '2023-02-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ''' - ) + tdSql.execute(f"insert into {dbname}.ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdLog.info(" prepare data for distributed_aggregate done! ") - def check_distribute_datas(self): + def check_distribute_datas(self, dbname="testdb"): # get vgroup_ids of all - tdSql.query("show vgroups ") + tdSql.query(f"show {dbname}.vgroups ") vgroups = tdSql.queryResult vnode_tables={} - + for vgroup_id in vgroups: vnode_tables[vgroup_id[0]]=[] - # check sub_table of per vnode ,make sure sub_table has been distributed - tdSql.query("show tables like 'ct%'") + tdSql.query(f"show {dbname}.tables like 'ct%'") table_names = tdSql.queryResult tablenames = [] for table_name in table_names: - vnode_tables[table_name[6]].append(table_name[0]) + vnode_tables[table_name[6]].append(table_name[0]) self.vnode_disbutes = vnode_tables count = 0 @@ -128,15 +101,15 @@ class TDTestCase: if count < 2: tdLog.exit(" the datas of all not satisfy sub_table has been distributed ") - def check_min_distribute_diff_vnode(self,col_name): - + def check_min_distribute_diff_vnode(self,col_name, dbname="testdb"): + vgroup_ids = [] for k ,v in self.vnode_disbutes.items(): if len(v)>=2: vgroup_ids.append(k) - + distribute_tbnames = [] - + for vgroup_id in vgroup_ids: vnode_tables = self.vnode_disbutes[vgroup_id] distribute_tbnames.append(random.sample(vnode_tables,1)[0]) @@ -145,13 +118,13 @@ class TDTestCase: tbname_ins += "'%s' ,"%tbname tbname_filters = tbname_ins[:-1] - - min_sql = f"select min({col_name}) from stb1 where tbname in ({tbname_filters});" - same_sql = f"select {col_name} from stb1 where tbname in ({tbname_filters}) and {col_name} is not null order by {col_name} asc limit 1" + min_sql = f"select min({col_name}) from {dbname}.stb1 where tbname in ({tbname_filters});" + + same_sql = f"select {col_name} from {dbname}.stb1 where tbname in ({tbname_filters}) and {col_name} is not null order by {col_name} asc limit 1" tdSql.query(min_sql) - min_result = tdSql.queryResult + min_result = tdSql.queryResult tdSql.query(same_sql) same_result = tdSql.queryResult @@ -161,140 +134,138 @@ class TDTestCase: else: tdLog.info(" min function work as expected, sql : %s "% min_sql) - def check_min_status(self): - # check max function work status - - tdSql.query("show tables like 'ct%'") + def check_min_status(self, dbname="testdb"): + # check min function work status + + tdSql.query(f"show {dbname}.tables like 'ct%'") table_names = tdSql.queryResult tablenames = [] for table_name in table_names: - tablenames.append(table_name[0]) + tablenames.append(f"{dbname}.{table_name[0]}") - tdSql.query("desc stb1") + tdSql.query(f"desc {dbname}.stb1") col_names = tdSql.queryResult - + colnames = [] for col_name in col_names: if col_name[1] in ["INT" ,"BIGINT" ,"SMALLINT" ,"TINYINT" , "FLOAT" ,"DOUBLE"]: colnames.append(col_name[0]) - + for tablename in tablenames: for colname in colnames: self.check_min_functions(tablename,colname) - # check max function for different vnode + # check min function for different vnode for colname in colnames: if colname.startswith("c"): - self.check_min_distribute_diff_vnode(colname) + self.check_min_distribute_diff_vnode(colname, dbname) else: - # self.check_min_distribute_diff_vnode(colname) # bug for tag + # self.check_min_distribute_diff_vnode(colname, dbname) # bug for tag pass - - def distribute_agg_query(self): + def distribute_agg_query(self, dbname="testdb"): # basic filter - tdSql.query("select min(c1) from stb1 where c1 is null") + tdSql.query(f"select min(c1) from {dbname}.stb1 where c1 is null") tdSql.checkRows(0) - tdSql.query("select min(c1) from stb1 where t1=1") + tdSql.query(f"select min(c1) from {dbname}.stb1 where t1=1") tdSql.checkData(0,0,2) - tdSql.query("select min(c1+c2) from stb1 where c1 =1 ") + tdSql.query(f"select min(c1+c2) from {dbname}.stb1 where c1 =1 ") tdSql.checkData(0,0,11112.000000000) - tdSql.query("select min(c1) from stb1 where tbname=\"ct2\"") - tdSql.checkData(0,0,2) + tdSql.query(f"select min(c1) from {dbname}.stb1 where tbname=\"ct2\"") + tdSql.checkData(0, 0, 2) - tdSql.query("select min(c1) from stb1 partition by tbname") + tdSql.query(f"select min(c1) from {dbname}.stb1 partition by tbname") tdSql.checkRows(20) - tdSql.query("select min(c1) from stb1 where t1> 4 partition by tbname") + tdSql.query(f"select min(c1) from {dbname}.stb1 where t1> 4 partition by tbname") tdSql.checkRows(15) - # union all - tdSql.query("select min(c1) from stb1 union all select min(c1) from stb1 ") + # union all + tdSql.query(f"select min(c1) from {dbname}.stb1 union all select min(c1) from {dbname}.stb1 ") tdSql.checkRows(2) - tdSql.checkData(0,0,0) + tdSql.checkData(0, 0, 0) - # join + # join tdSql.execute(" create database if not exists db ") tdSql.execute(" use db ") - tdSql.execute(" create stable st (ts timestamp , c1 int ,c2 float) tags(t1 int) ") - tdSql.execute(" create table tb1 using st tags(1) ") - tdSql.execute(" create table tb2 using st tags(2) ") + tdSql.execute(" create stable db.st (ts timestamp , c1 int ,c2 float) tags(t1 int) ") + tdSql.execute(" create table db.tb1 using db.st tags(1) ") + tdSql.execute(" create table db.tb2 using db.st tags(2) ") + - for i in range(10): ts = i*10 + self.ts - tdSql.execute(f" insert into tb1 values({ts},{i},{i}.0)") - tdSql.execute(f" insert into tb2 values({ts},{i},{i}.0)") + tdSql.execute(f" insert into db.tb1 values({ts},{i},{i}.0)") + tdSql.execute(f" insert into db.tb2 values({ts},{i},{i}.0)") - tdSql.query("select min(tb1.c1), tb2.c2 from tb1, tb2 where tb1.ts=tb2.ts") + tdSql.query(f"select min(tb1.c1), tb2.c2 from db.tb1 tb1, db.tb2 tb2 where tb1.ts=tb2.ts") tdSql.checkRows(1) tdSql.checkData(0,0,0) tdSql.checkData(0,0,0.00000) - # group by - tdSql.execute(" use testdb ") - tdSql.query(" select min(c1),c1 from stb1 group by t1 ") + # group by + tdSql.execute("use testdb ") + tdSql.query(f"select min(c1),c1 from {dbname}.stb1 group by t1 ") tdSql.checkRows(20) - tdSql.query(" select min(c1),c1 from stb1 group by c1 ") + tdSql.query(f"select min(c1),c1 from {dbname}.stb1 group by c1 ") tdSql.checkRows(30) - tdSql.query(" select min(c1),c2 from stb1 group by c2 ") + tdSql.query(f"select min(c1),c2 from {dbname}.stb1 group by c2 ") tdSql.checkRows(31) # selective common cols of datas - tdSql.query("select min(c1),c2,c3,c5 from stb1") + tdSql.query(f"select min(c1),c2,c3,c5 from {dbname}.stb1") tdSql.checkRows(1) tdSql.checkData(0,0,0) tdSql.checkData(0,1,0) tdSql.checkData(0,2,0) tdSql.checkData(0,3,0) - tdSql.query("select min(c1),t1,c2,t3 from stb1 where c1 >5") + tdSql.query(f"select min(c1),t1,c2,t3 from {dbname}.stb1 where c1 > 5") tdSql.checkRows(1) tdSql.checkData(0,0,6) tdSql.checkData(0,2,66666) - tdSql.query("select min(c1),ceil(t1),pow(c2,1)+2,abs(t3) from stb1 where c1>12") + tdSql.query(f"select min(c1),ceil(t1),pow(c2,1)+2,abs(t3) from {dbname}.stb1 where c1 > 12") tdSql.checkRows(1) tdSql.checkData(0,0,13) - tdSql.checkData(0,2,144445.000000000) - + tdSql.checkData(0,2,144445.000000000) + # partition by tbname or partition by tag - tdSql.query("select min(c1),tbname from stb1 partition by tbname") + tdSql.query(f"select min(c1),tbname from {dbname}.stb1 partition by tbname") query_data = tdSql.queryResult - + for row in query_data: - tbname = row[1] - tdSql.query(" select min(c1) from %s "%tbname) + tbname = f"{dbname}.{row[1]}" + tdSql.query(f"select min(c1) from %s "%tbname) tdSql.checkData(0,0,row[0]) - tdSql.query("select min(c1),tbname from stb1 partition by t1") + tdSql.query(f"select min(c1),tbname from {dbname}.stb1 partition by t1") query_data = tdSql.queryResult - + for row in query_data: - tbname = row[1] - tdSql.query(" select min(c1) from %s "%tbname) + tbname = f"{dbname}.{row[1]}" + tdSql.query(f"select min(c1) from %s "%tbname) tdSql.checkData(0,0,row[0]) - # nest query for support max - tdSql.query("select abs(c2+2)+1 from (select min(c1) c2 from stb1)") + # nest query for support min + tdSql.query(f"select abs(c2+2)+1 from (select min(c1) c2 from {dbname}.stb1)") tdSql.checkData(0,0,3.000000000) - tdSql.query("select min(c1+2)+1 as c2 from (select ts ,c1 ,c2 from stb1)") + tdSql.query(f"select min(c1+2)+1 as c2 from (select ts ,c1 ,c2 from {dbname}.stb1)") tdSql.checkData(0,0,3.000000000) - tdSql.query("select min(a+2)+1 as c2 from (select ts ,abs(c1) a ,c2 from stb1)") + tdSql.query(f"select min(a+2)+1 as c2 from (select ts ,abs(c1) a ,c2 from {dbname}.stb1)") tdSql.checkData(0,0,3.000000000) # mixup with other functions - tdSql.query("select max(c1),count(c1),last(c2,c3),min(c1) from stb1") + tdSql.query(f"select max(c1),count(c1),last(c2,c3) from {dbname}.stb1") tdSql.checkData(0,0,28) tdSql.checkData(0,1,184) tdSql.checkData(0,2,-99999) tdSql.checkData(0,3,-999) - tdSql.checkData(0,4,0) def run(self): @@ -303,7 +274,7 @@ class TDTestCase: self.check_min_status() self.distribute_agg_query() - + def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/system-test/fulltest.sh b/tests/system-test/fulltest.sh index d2cbba19b2..15bebd5593 100755 --- a/tests/system-test/fulltest.sh +++ b/tests/system-test/fulltest.sh @@ -80,6 +80,12 @@ python3 ./test.py -f 2-query/distribute_agg_apercentile.py python3 ./test.py -f 2-query/distribute_agg_apercentile.py -R python3 ./test.py -f 2-query/distribute_agg_avg.py python3 ./test.py -f 2-query/distribute_agg_avg.py -R +python3 ./test.py -f 2-query/distribute_agg_count.py +python3 ./test.py -f 2-query/distribute_agg_count.py -R +python3 ./test.py -f 2-query/distribute_agg_max.py +python3 ./test.py -f 2-query/distribute_agg_max.py -R +python3 ./test.py -f 2-query/distribute_agg_min.py +python3 ./test.py -f 2-query/distribute_agg_min.py -R @@ -146,9 +152,6 @@ python3 ./test.py -f 2-query/function_stateduration.py python3 ./test.py -f 2-query/statecount.py python3 ./test.py -f 2-query/tail.py python3 ./test.py -f 2-query/ttl_comment.py -python3 ./test.py -f 2-query/distribute_agg_count.py -python3 ./test.py -f 2-query/distribute_agg_max.py -python3 ./test.py -f 2-query/distribute_agg_min.py python3 ./test.py -f 2-query/distribute_agg_sum.py python3 ./test.py -f 2-query/distribute_agg_spread.py python3 ./test.py -f 2-query/distribute_agg_stddev.py From 6740dc1077550b7f0a253dfae2406b5d74497b7e Mon Sep 17 00:00:00 2001 From: cpwu Date: Mon, 25 Jul 2022 11:16:05 +0800 Subject: [PATCH 03/20] add case --- tests/system-test/1-insert/mutil_stage.py | 201 ++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 tests/system-test/1-insert/mutil_stage.py diff --git a/tests/system-test/1-insert/mutil_stage.py b/tests/system-test/1-insert/mutil_stage.py new file mode 100644 index 0000000000..6813a67808 --- /dev/null +++ b/tests/system-test/1-insert/mutil_stage.py @@ -0,0 +1,201 @@ +import datetime + +from dataclasses import dataclass, field +from typing import List, Any, Tuple +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * + +PRIMARY_COL = "ts" + +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" + +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.datetime.timestamp(datetime.datetime.now()) * 1000) + +# init db/table +DBNAME = "db" +STBNAME = f"{DBNAME}.stb1" +CTBNAME = f"{DBNAME}.ct1" +NTBNAME = f"{DBNAME}.nt1" + +L0 = 0 +L1 = 1 +L2 = 2 + +PRIMARY_DIR = 1 +NON_PRIMARY_DIR = 0 + +DATA_PRE0 = f"data0" +DATA_PRE1 = f"data1" +DATA_PRE2 = f"data2" + +@dataclass +class DataSet: + ts_data : List[int] = field(default_factory=list) + int_data : List[int] = field(default_factory=list) + bint_data : List[int] = field(default_factory=list) + sint_data : List[int] = field(default_factory=list) + tint_data : List[int] = field(default_factory=list) + int_un_data : List[int] = field(default_factory=list) + bint_un_data: List[int] = field(default_factory=list) + sint_un_data: List[int] = field(default_factory=list) + tint_un_data: List[int] = field(default_factory=list) + float_data : List[float] = field(default_factory=list) + double_data : List[float] = field(default_factory=list) + bool_data : List[int] = field(default_factory=list) + binary_data : List[str] = field(default_factory=list) + nchar_data : List[str] = field(default_factory=list) + + +class TDTestCase: + + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor(), False) + self.taos_cfg_path = tdDnodes.dnodes[0].cfgPath + self.taos_data_dir = tdDnodes.dnodes[0].dataDir + + + def cfg(self, filename, **update_dict): + self.del_old_datadir(filename) + cmd = "echo " + for k, v in update_dict.items(): + cmd += f"{k} {v}\n" + + cmd += f" >> {filename}" + if os.system(cmd) != 0: + tdLog.exit(cmd) + + def cfg_str(self, filename, update_str): + self.del_old_datadir(filename) + cmd = f'echo "{update_str}" >> {filename}' + if os.system(cmd) != 0: + tdLog.exit(cmd) + + def cfg_str_list(self, filename, update_list): + for update_str in update_list: + self.cfg_str(filename, update_str) + + def del_old_datadir(self, filename): + cmd = f"sed -i '/^dataDir/d' {filename}" + if os.system(cmd) != 0: + tdLog.exit(cmd) + + @property + def __err_cfg(self): + cfg_list = [] + err_case1 = [ + f"dataDir {self.taos_data_dir}/{DATA_PRE0}0 {L0} {NON_PRIMARY_DIR}", + f"dataDir {self.taos_data_dir}/{DATA_PRE1}1 {L1} {PRIMARY_DIR}", + f"dataDir {self.taos_data_dir}/{DATA_PRE2}2 {L2} {NON_PRIMARY_DIR}" + ] + err_case2 = [ + f"dataDir {self.taos_data_dir}/{DATA_PRE0}0 {L0} {NON_PRIMARY_DIR}", + f"dataDir {self.taos_data_dir}/{DATA_PRE1}1 {L1} {NON_PRIMARY_DIR}", + f"dataDir {self.taos_data_dir}/{DATA_PRE2}2 {L2} {PRIMARY_DIR}" + ] + err_case3 = [ + f"dataDir {self.taos_data_dir}/data33 3 {NON_PRIMARY_DIR}" + ] + err_case4 = [ + f"dataDir {self.taos_data_dir}/{DATA_PRE0}0 {L0} {NON_PRIMARY_DIR}", + f"dataDir {self.taos_data_dir}/{DATA_PRE1}1 {L1} {NON_PRIMARY_DIR}", + f"dataDir {self.taos_data_dir}/{DATA_PRE2}2 {L2} {NON_PRIMARY_DIR}", + f"dataDir {self.taos_data_dir}/{DATA_PRE2}2 {L1} {NON_PRIMARY_DIR}" + ] + err_case5 = [] + for i in range(17): + err_case5.append(f"dataDir {self.taos_data_dir}/{DATA_PRE0}{i} {L0} {NON_PRIMARY_DIR}") + + err_case6 = [ + f"dataDir {self.taos_data_dir}/{DATA_PRE0}0 {L0} {PRIMARY_DIR}", + f"dataDir {self.taos_data_dir}/{DATA_PRE0}1 {L0} {PRIMARY_DIR}", + ] + err_case7 = [ + f"dataDir {self.taos_data_dir}/{DATA_PRE0}0 {L0} {PRIMARY_DIR}", + f"dataDir {self.taos_data_dir}/{DATA_PRE2}2 {L2} {PRIMARY_DIR}", + ] + err_case8 = [ + f"dataDir {self.taos_data_dir}/data33 3 {PRIMARY_DIR}" + ] + err_case9 = [ + f"dataDir {self.taos_data_dir}/data33 -1 {NON_PRIMARY_DIR}" + ] + + cfg_list.append(err_case1) + cfg_list.append(err_case2) + cfg_list.append(err_case3) + cfg_list.append(err_case4) + cfg_list.append(err_case5) + cfg_list.append(err_case6) + cfg_list.append(err_case7) + cfg_list.append(err_case8) + cfg_list.append(err_case9) + + return cfg_list + + @property + def __current_cfg(self): + cfg_list = [] + current_case1 = [ + f"dataDir {self.taos_data_dir}/{DATA_PRE0}0 {L0} {PRIMARY_COL}", + f"dataDir {self.taos_data_dir}/{DATA_PRE0}1 {L0} 0", + f"dataDir {self.taos_data_dir}/{DATA_PRE1}1 {L1} 0", + f"dataDir {self.taos_data_dir}/{DATA_PRE2}2 {L2} 0" + ] + + current_case2 = [ + f"dataDir {self.taos_data_dir}/{DATA_PRE0}0 0 1", + f"dataDir {self.taos_data_dir}/{DATA_PRE0}1 0 1", + f"dataDir {self.taos_data_dir}/{DATA_PRE0}0 0 1", + f"dataDir {self.taos_data_dir}/{DATA_PRE0}0 0 1", + + ] + + cfg_list.append(current_case1) + + return cfg_list + + def cfg_check(self): + for cfg_case in self.__err_cfg: + tdDnodes.stop(1) + self.cfg_str_list(filename=self.taos_cfg_path, update_list=cfg_case) + tdDnodes.start(1) + + tdSql.error(f"show databases") + + + def run(self): + self.cfg_check() + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) From 76f0747bb3a15ddaef2ca56b76efaac46aee11b7 Mon Sep 17 00:00:00 2001 From: cpwu Date: Mon, 25 Jul 2022 16:08:15 +0800 Subject: [PATCH 04/20] fix case --- tests/system-test/1-insert/mutil_stage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/system-test/1-insert/mutil_stage.py b/tests/system-test/1-insert/mutil_stage.py index 6813a67808..4088649b2b 100644 --- a/tests/system-test/1-insert/mutil_stage.py +++ b/tests/system-test/1-insert/mutil_stage.py @@ -82,7 +82,6 @@ class TDTestCase: def cfg(self, filename, **update_dict): - self.del_old_datadir(filename) cmd = "echo " for k, v in update_dict.items(): cmd += f"{k} {v}\n" @@ -92,7 +91,6 @@ class TDTestCase: tdLog.exit(cmd) def cfg_str(self, filename, update_str): - self.del_old_datadir(filename) cmd = f'echo "{update_str}" >> {filename}' if os.system(cmd) != 0: tdLog.exit(cmd) @@ -183,6 +181,8 @@ class TDTestCase: def cfg_check(self): for cfg_case in self.__err_cfg: + tdLog.info("---------", self.__err_cfg.index(cfg_case)) + self.del_old_datadir(filename=self.taos_cfg_path) tdDnodes.stop(1) self.cfg_str_list(filename=self.taos_cfg_path, update_list=cfg_case) tdDnodes.start(1) From 592041c65c101a43ea386f51bead0265c1f83134 Mon Sep 17 00:00:00 2001 From: cpwu Date: Mon, 25 Jul 2022 16:09:07 +0800 Subject: [PATCH 05/20] fix case --- tests/system-test/1-insert/mutil_stage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system-test/1-insert/mutil_stage.py b/tests/system-test/1-insert/mutil_stage.py index 4088649b2b..db8c43b009 100644 --- a/tests/system-test/1-insert/mutil_stage.py +++ b/tests/system-test/1-insert/mutil_stage.py @@ -185,7 +185,7 @@ class TDTestCase: self.del_old_datadir(filename=self.taos_cfg_path) tdDnodes.stop(1) self.cfg_str_list(filename=self.taos_cfg_path, update_list=cfg_case) - tdDnodes.start(1) + tdDnodes.starttaosd(1) tdSql.error(f"show databases") From f3147f201e72ab30c5486337cb669cbe894d84e1 Mon Sep 17 00:00:00 2001 From: cpwu Date: Mon, 25 Jul 2022 16:47:45 +0800 Subject: [PATCH 06/20] fix case --- tests/system-test/1-insert/mutil_stage.py | 55 +++++++++-------------- 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/tests/system-test/1-insert/mutil_stage.py b/tests/system-test/1-insert/mutil_stage.py index db8c43b009..179abeff8a 100644 --- a/tests/system-test/1-insert/mutil_stage.py +++ b/tests/system-test/1-insert/mutil_stage.py @@ -1,11 +1,11 @@ import datetime -from dataclasses import dataclass, field from typing import List, Any, Tuple from util.log import * from util.sql import * from util.cases import * from util.dnodes import * +from util.common import * PRIMARY_COL = "ts" @@ -54,24 +54,6 @@ DATA_PRE0 = f"data0" DATA_PRE1 = f"data1" DATA_PRE2 = f"data2" -@dataclass -class DataSet: - ts_data : List[int] = field(default_factory=list) - int_data : List[int] = field(default_factory=list) - bint_data : List[int] = field(default_factory=list) - sint_data : List[int] = field(default_factory=list) - tint_data : List[int] = field(default_factory=list) - int_un_data : List[int] = field(default_factory=list) - bint_un_data: List[int] = field(default_factory=list) - sint_un_data: List[int] = field(default_factory=list) - tint_un_data: List[int] = field(default_factory=list) - float_data : List[float] = field(default_factory=list) - double_data : List[float] = field(default_factory=list) - bool_data : List[int] = field(default_factory=list) - binary_data : List[str] = field(default_factory=list) - nchar_data : List[str] = field(default_factory=list) - - class TDTestCase: def init(self, conn, logSql): @@ -126,9 +108,9 @@ class TDTestCase: f"dataDir {self.taos_data_dir}/{DATA_PRE2}2 {L2} {NON_PRIMARY_DIR}", f"dataDir {self.taos_data_dir}/{DATA_PRE2}2 {L1} {NON_PRIMARY_DIR}" ] - err_case5 = [] - for i in range(17): - err_case5.append(f"dataDir {self.taos_data_dir}/{DATA_PRE0}{i} {L0} {NON_PRIMARY_DIR}") + err_case5 = [f"dataDir {self.taos_data_dir}/{DATA_PRE0}0 {L0} {PRIMARY_DIR}"] + for i in range(16): + err_case5.append(f"dataDir {self.taos_data_dir}/{DATA_PRE0}{i+1} {L0} {NON_PRIMARY_DIR}") err_case6 = [ f"dataDir {self.taos_data_dir}/{DATA_PRE0}0 {L0} {PRIMARY_DIR}", @@ -161,19 +143,15 @@ class TDTestCase: def __current_cfg(self): cfg_list = [] current_case1 = [ - f"dataDir {self.taos_data_dir}/{DATA_PRE0}0 {L0} {PRIMARY_COL}", - f"dataDir {self.taos_data_dir}/{DATA_PRE0}1 {L0} 0", - f"dataDir {self.taos_data_dir}/{DATA_PRE1}1 {L1} 0", - f"dataDir {self.taos_data_dir}/{DATA_PRE2}2 {L2} 0" + f"dataDir {self.taos_data_dir}/{DATA_PRE0}0 {L0} {PRIMARY_DIR}", + f"dataDir {self.taos_data_dir}/{DATA_PRE0}1 {L0} {NON_PRIMARY_DIR}", + f"dataDir {self.taos_data_dir}/{DATA_PRE1}1 {L1} {NON_PRIMARY_DIR}", + f"dataDir {self.taos_data_dir}/{DATA_PRE2}2 {L2} {NON_PRIMARY_DIR}" ] - current_case2 = [ - f"dataDir {self.taos_data_dir}/{DATA_PRE0}0 0 1", - f"dataDir {self.taos_data_dir}/{DATA_PRE0}1 0 1", - f"dataDir {self.taos_data_dir}/{DATA_PRE0}0 0 1", - f"dataDir {self.taos_data_dir}/{DATA_PRE0}0 0 1", - - ] + current_case2 = [f"dataDir {self.taos_data_dir}/{DATA_PRE0}0 {L0} {PRIMARY_DIR}"] + for i in range(9): + current_case2.append(f"dataDir {self.taos_data_dir}/{DATA_PRE0}{i+1} {L0} {NON_PRIMARY_DIR}") cfg_list.append(current_case1) @@ -181,7 +159,7 @@ class TDTestCase: def cfg_check(self): for cfg_case in self.__err_cfg: - tdLog.info("---------", self.__err_cfg.index(cfg_case)) + tdLog.info(self.__err_cfg.index(cfg_case)) self.del_old_datadir(filename=self.taos_cfg_path) tdDnodes.stop(1) self.cfg_str_list(filename=self.taos_cfg_path, update_list=cfg_case) @@ -189,6 +167,15 @@ class TDTestCase: tdSql.error(f"show databases") + for cfg_case in self.__current_cfg: + self.del_old_datadir(filename=self.taos_cfg_path) + tdDnodes.stop(1) + self.cfg_str_list(filename=self.taos_cfg_path, update_list=cfg_case) + tdDnodes.starttaosd(1) + + tdSql.query(f"show databases") + + def run(self): self.cfg_check() From 3d92db9d5aa728f3dfab80613c767179927062c1 Mon Sep 17 00:00:00 2001 From: cpwu Date: Mon, 25 Jul 2022 16:48:45 +0800 Subject: [PATCH 07/20] fix case --- tests/system-test/1-insert/mutil_stage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system-test/1-insert/mutil_stage.py b/tests/system-test/1-insert/mutil_stage.py index 179abeff8a..842e5a5167 100644 --- a/tests/system-test/1-insert/mutil_stage.py +++ b/tests/system-test/1-insert/mutil_stage.py @@ -171,7 +171,7 @@ class TDTestCase: self.del_old_datadir(filename=self.taos_cfg_path) tdDnodes.stop(1) self.cfg_str_list(filename=self.taos_cfg_path, update_list=cfg_case) - tdDnodes.starttaosd(1) + tdDnodes.start(1) tdSql.query(f"show databases") From e6bf3ccb04aa3a507a8297a42d370deb9f727de2 Mon Sep 17 00:00:00 2001 From: cpwu Date: Mon, 25 Jul 2022 16:58:51 +0800 Subject: [PATCH 08/20] fix case --- tests/system-test/1-insert/mutil_stage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/system-test/1-insert/mutil_stage.py b/tests/system-test/1-insert/mutil_stage.py index 842e5a5167..d5c1c5d690 100644 --- a/tests/system-test/1-insert/mutil_stage.py +++ b/tests/system-test/1-insert/mutil_stage.py @@ -1,4 +1,4 @@ -import datetime +from datetime import datetime from typing import List, Any, Tuple from util.log import * @@ -35,7 +35,7 @@ ALL_COL = [PRIMARY_COL, INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE 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" From 5b06d8dff6a02461ff3daedd83a76c8fcae78bbb Mon Sep 17 00:00:00 2001 From: cpwu Date: Tue, 26 Jul 2022 14:31:36 +0800 Subject: [PATCH 09/20] fix case --- tests/pytest/util/sql.py | 21 +++--- tests/system-test/1-insert/mutil_stage.py | 81 +++++++++++++++++++++-- 2 files changed, 87 insertions(+), 15 deletions(-) diff --git a/tests/pytest/util/sql.py b/tests/pytest/util/sql.py index 01955ec93a..b9177d2269 100644 --- a/tests/pytest/util/sql.py +++ b/tests/pytest/util/sql.py @@ -49,18 +49,23 @@ class TDSql: def close(self): self.cursor.close() - def prepare(self): - tdLog.info("prepare database:db") + def prepare(self, dbname="db", drop=True, **kwargs): + tdLog.info(f"prepare database:{dbname}") s = 'reset query cache' try: self.cursor.execute(s) except: tdLog.notice("'reset query cache' is not supported") - s = 'drop database if exists db' + if drop: + s = f'drop database if exists {dbname}' + self.cursor.execute(s) + s = f'create database {dbname}' + for k, v in kwargs.items(): + s += f" {k} {v}" + if "duration" not in kwargs: + s += " duration 300" self.cursor.execute(s) - s = 'create database db duration 300' - self.cursor.execute(s) - s = 'use db' + s = f'use {dbname}' self.cursor.execute(s) time.sleep(2) @@ -106,7 +111,7 @@ class TDSql: if row_tag: return self.queryResult return self.queryRows - except Exception as e: + except Exception as e: caller = inspect.getframeinfo(inspect.stack()[1][0]) args = (caller.filename, caller.lineno, sql, repr(e)) tdLog.notice("%s(%d) failed: sql:%s, %s" % args) @@ -304,7 +309,7 @@ class TDSql: tdLog.notice("Try to execute sql again, query times: %d "%i) time.sleep(1) pass - else: + else: try: tdLog.notice("Try the last execute sql ") self.affectedRows = self.cursor.execute(sql) diff --git a/tests/system-test/1-insert/mutil_stage.py b/tests/system-test/1-insert/mutil_stage.py index d5c1c5d690..7fac180057 100644 --- a/tests/system-test/1-insert/mutil_stage.py +++ b/tests/system-test/1-insert/mutil_stage.py @@ -1,4 +1,5 @@ from datetime import datetime +import time from typing import List, Any, Tuple from util.log import * @@ -31,7 +32,6 @@ 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 @@ -39,9 +39,9 @@ NOW = int(datetime.timestamp(datetime.now()) * 1000) # init db/table DBNAME = "db" -STBNAME = f"{DBNAME}.stb1" -CTBNAME = f"{DBNAME}.ct1" -NTBNAME = f"{DBNAME}.nt1" +STBNAME = "stb1" +CTB_PRE = "ct" +NTB_PRE = "nt" L0 = 0 L1 = 1 @@ -153,32 +153,99 @@ class TDTestCase: for i in range(9): current_case2.append(f"dataDir {self.taos_data_dir}/{DATA_PRE0}{i+1} {L0} {NON_PRIMARY_DIR}") + # TD-17773bug + current_case3 = [ + f"dataDir {self.taos_data_dir}/{DATA_PRE0}0 ", + f"dataDir {self.taos_data_dir}/{DATA_PRE0}1 {L0} {NON_PRIMARY_DIR}", + f"dataDir {self.taos_data_dir}/{DATA_PRE1}0 {L1} {NON_PRIMARY_DIR}", + f"dataDir {self.taos_data_dir}/{DATA_PRE2}0 {L2} {NON_PRIMARY_DIR}", + ] cfg_list.append(current_case1) + cfg_list.append(current_case3) return cfg_list def cfg_check(self): for cfg_case in self.__err_cfg: - tdLog.info(self.__err_cfg.index(cfg_case)) self.del_old_datadir(filename=self.taos_cfg_path) tdDnodes.stop(1) + tdDnodes.deploy(1) self.cfg_str_list(filename=self.taos_cfg_path, update_list=cfg_case) tdDnodes.starttaosd(1) - + time.sleep(2) tdSql.error(f"show databases") for cfg_case in self.__current_cfg: self.del_old_datadir(filename=self.taos_cfg_path) tdDnodes.stop(1) + tdDnodes.deploy(1) self.cfg_str_list(filename=self.taos_cfg_path, update_list=cfg_case) tdDnodes.start(1) - tdSql.query(f"show databases") + def __create_tb(self, stb=STBNAME, ctb_pre = CTB_PRE, ctb_num=20, ntb_pre=NTB_PRE, ntbnum=1, dbname=DBNAME): + tdLog.printNoPrefix("==========step: create table") + create_stb_sql = f'''create table {dbname}.{stb}( + 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 + ) tags ({INT_TAG} int) + ''' + for i in range(ntbnum): + + create_ntb_sql = f'''create table {dbname}.{ntb_pre}{i+1}( + 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(ctb_num): + tdSql.execute(f'create table {dbname}.{ctb_pre}{i+1} using {dbname}.{stb} tags ( {i+1} )') + + def __insert_data(self, rows,dbname=DBNAME): + data = DataSet().get_order_set(rows) + + tdLog.printNoPrefix("==========step: start inser data into tables now.....") + + # now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) + + 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]} + ''' + + tdSql.execute( + f"insert into {dbname}.{CTB_PRE}1 values ( {NOW - i * TIME_STEP}, {row_data} )") + tdSql.execute( + f"insert into {dbname}.{CTB_PRE}2 values ( {NOW - i * int(TIME_STEP * 0.6)}, {neg_row_data} )") + tdSql.execute( + f"insert into {dbname}.{CTB_PRE}4 values ( {NOW - i * int(TIME_STEP * 0.8) }, {row_data} )") + tdSql.execute( + f"insert into {dbname}.{NTB_PRE}1 values ( {NOW - i * int(TIME_STEP * 1.2)}, {row_data} )") + def run(self): + self.rows = 10 self.cfg_check() + tdSql.prepare(dbname=DBNAME, **{"keep": "5m, 10m, 15m", "duration":"5m"}) + self.__create_tb(dbname=DBNAME) + self.__insert_data(rows=self.rows, dbname=DBNAME) + tdSql.query(f"select count(*) from {DBNAME}.{NTB_PRE}1") def stop(self): tdSql.close() From 2cb144664e927fbb8444a4feb97fb534956f2abb Mon Sep 17 00:00:00 2001 From: cpwu Date: Tue, 26 Jul 2022 15:15:54 +0800 Subject: [PATCH 10/20] fix case --- tests/pytest/util/common.py | 27 +++++++++-------------- tests/system-test/1-insert/mutil_stage.py | 13 ++++------- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/tests/pytest/util/common.py b/tests/pytest/util/common.py index 9b72312028..a290a92876 100644 --- a/tests/pytest/util/common.py +++ b/tests/pytest/util/common.py @@ -80,23 +80,18 @@ class DataSet: self.bool_data.append( bool((i + bool_start) % 2 )) self.vchar_data.append( f"{vchar_prefix}_{i * vchar_step}" ) self.nchar_data.append( f"{nchar_prefix}_{i * nchar_step}") - self.ts_data.append( int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000 - i * ts_step)) + self.ts_data.append( int(datetime.timestamp(datetime.now()) * 1000 - i * ts_step)) - def get_disorder_set(self, - rows, - int_low :int = INT_MIN, - int_up :int = INT_MAX, - bint_low :int = BIGINT_MIN, - bint_up :int = BIGINT_MAX, - sint_low :int = SMALLINT_MIN, - sint_up :int = SMALLINT_MAX, - tint_low :int = TINYINT_MIN, - tint_up :int = TINYINT_MAX, - ubint_low :int = BIGINT_UN_MIN, - ubint_up :int = BIGINT_UN_MAX, - - - ): + def get_disorder_set(self, rows, **kwargs): + for k, v in kwargs.items(): + int_low = v if k == "int_low" else INT_MIN + int_up = v if k == "int_up" else INT_MAX + bint_low = v if k == "bint_low" else BIGINT_MIN + bint_up = v if k == "bint_up" else BIGINT_MAX + sint_low = v if k == "sint_low" else SMALLINT_MIN + sint_up = v if k == "sint_up" else SMALLINT_MAX + tint_low = v if k == "tint_low" else TINYINT_MIN + tint_up = v if k == "tint_up" else TINYINT_MAX pass diff --git a/tests/system-test/1-insert/mutil_stage.py b/tests/system-test/1-insert/mutil_stage.py index 7fac180057..6584c4081b 100644 --- a/tests/system-test/1-insert/mutil_stage.py +++ b/tests/system-test/1-insert/mutil_stage.py @@ -193,8 +193,9 @@ class TDTestCase: {INT_UN_COL} int unsigned, {BINT_UN_COL} bigint unsigned ) tags ({INT_TAG} int) ''' - for i in range(ntbnum): + tdSql.execute(create_stb_sql) + for i in range(ntbnum): create_ntb_sql = f'''create table {dbname}.{ntb_pre}{i+1}( ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, @@ -203,8 +204,7 @@ class TDTestCase: {INT_UN_COL} int unsigned, {BINT_UN_COL} bigint unsigned ) ''' - tdSql.execute(create_stb_sql) - tdSql.execute(create_ntb_sql) + tdSql.execute(create_ntb_sql) for i in range(ctb_num): tdSql.execute(f'create table {dbname}.{ctb_pre}{i+1} using {dbname}.{stb} tags ( {i+1} )') @@ -213,9 +213,6 @@ class TDTestCase: data = DataSet().get_order_set(rows) tdLog.printNoPrefix("==========step: start inser data into tables now.....") - - # now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) - 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]}, @@ -237,12 +234,10 @@ class TDTestCase: tdSql.execute( f"insert into {dbname}.{NTB_PRE}1 values ( {NOW - i * int(TIME_STEP * 1.2)}, {row_data} )") - - def run(self): self.rows = 10 self.cfg_check() - tdSql.prepare(dbname=DBNAME, **{"keep": "5m, 10m, 15m", "duration":"5m"}) + tdSql.prepare(dbname=DBNAME, **{"keep": "1d, 1500m, 26h", "duration":"1h"}) self.__create_tb(dbname=DBNAME) self.__insert_data(rows=self.rows, dbname=DBNAME) tdSql.query(f"select count(*) from {DBNAME}.{NTB_PRE}1") From c71b1440cf1501218dfa6c7ca3896ad52fd65f6c Mon Sep 17 00:00:00 2001 From: cpwu Date: Tue, 26 Jul 2022 15:38:54 +0800 Subject: [PATCH 11/20] fix case --- tests/pytest/util/common.py | 2 +- tests/system-test/1-insert/mutil_stage.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/pytest/util/common.py b/tests/pytest/util/common.py index a290a92876..6384195a1b 100644 --- a/tests/pytest/util/common.py +++ b/tests/pytest/util/common.py @@ -18,7 +18,7 @@ import time import socket import json import toml -from .boundary import DataBoundary +from util.boundary import DataBoundary import taos from util.log import * from util.sql import * diff --git a/tests/system-test/1-insert/mutil_stage.py b/tests/system-test/1-insert/mutil_stage.py index 6584c4081b..e4342eca24 100644 --- a/tests/system-test/1-insert/mutil_stage.py +++ b/tests/system-test/1-insert/mutil_stage.py @@ -210,7 +210,8 @@ class TDTestCase: tdSql.execute(f'create table {dbname}.{ctb_pre}{i+1} using {dbname}.{stb} tags ( {i+1} )') def __insert_data(self, rows,dbname=DBNAME): - data = DataSet().get_order_set(rows) + data = DataSet() + data.get_order_set(rows) tdLog.printNoPrefix("==========step: start inser data into tables now.....") for i in range(self.rows): From 4d765cd64f694b0c56c0d500bb93fdce99c1aaa5 Mon Sep 17 00:00:00 2001 From: cpwu Date: Tue, 26 Jul 2022 17:43:53 +0800 Subject: [PATCH 12/20] fix case --- tests/system-test/1-insert/mutil_stage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/system-test/1-insert/mutil_stage.py b/tests/system-test/1-insert/mutil_stage.py index e4342eca24..f18098267b 100644 --- a/tests/system-test/1-insert/mutil_stage.py +++ b/tests/system-test/1-insert/mutil_stage.py @@ -217,12 +217,12 @@ class TDTestCase: 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.bool_data[i]}, '{data.vchar_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]}, + {data.bool_data[i]}, '{data.vchar_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]} ''' From 9101b2aeba08fde6eebc57f02d9bf774fadf9e4a Mon Sep 17 00:00:00 2001 From: cpwu Date: Tue, 26 Jul 2022 17:47:07 +0800 Subject: [PATCH 13/20] fix case --- tests/system-test/1-insert/mutil_stage.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/system-test/1-insert/mutil_stage.py b/tests/system-test/1-insert/mutil_stage.py index f18098267b..880e638798 100644 --- a/tests/system-test/1-insert/mutil_stage.py +++ b/tests/system-test/1-insert/mutil_stage.py @@ -217,13 +217,13 @@ class TDTestCase: 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.vchar_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]} + {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]} ''' 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.vchar_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]}, {1 * data.utint_data[i]}, + {1 * data.usint_data[i]}, {1 * data.uint_data[i]}, {1 * data.ubint_data[i]} ''' tdSql.execute( From 4bec9b1cdc6bcf09bd35b318722addffbdc77966 Mon Sep 17 00:00:00 2001 From: cpwu Date: Tue, 26 Jul 2022 17:56:29 +0800 Subject: [PATCH 14/20] fix case --- tests/system-test/1-insert/mutil_stage.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/system-test/1-insert/mutil_stage.py b/tests/system-test/1-insert/mutil_stage.py index 880e638798..f537c0042a 100644 --- a/tests/system-test/1-insert/mutil_stage.py +++ b/tests/system-test/1-insert/mutil_stage.py @@ -163,6 +163,9 @@ class TDTestCase: cfg_list.append(current_case1) cfg_list.append(current_case3) + # case2 must in last of least, because use this cfg as data uniformity test + cfg_list.append(current_case2) + return cfg_list def cfg_check(self): From 424d4094007b0675373c2a928b6c708d3600d889 Mon Sep 17 00:00:00 2001 From: cpwu Date: Tue, 26 Jul 2022 18:02:22 +0800 Subject: [PATCH 15/20] fix case --- tests/system-test/1-insert/mutil_stage.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/system-test/1-insert/mutil_stage.py b/tests/system-test/1-insert/mutil_stage.py index f537c0042a..711f3321ff 100644 --- a/tests/system-test/1-insert/mutil_stage.py +++ b/tests/system-test/1-insert/mutil_stage.py @@ -241,10 +241,11 @@ class TDTestCase: def run(self): self.rows = 10 self.cfg_check() - tdSql.prepare(dbname=DBNAME, **{"keep": "1d, 1500m, 26h", "duration":"1h"}) + tdSql.prepare(dbname=DBNAME, **{"keep": "1d, 1500m, 26h", "duration":"1h", "vgroups": 10}) self.__create_tb(dbname=DBNAME) self.__insert_data(rows=self.rows, dbname=DBNAME) tdSql.query(f"select count(*) from {DBNAME}.{NTB_PRE}1") + tdSql.execute(f"flush database {DBNAME}") def stop(self): tdSql.close() From b9a23993be48897e20d5a889cbfd4ae869062b51 Mon Sep 17 00:00:00 2001 From: cpwu Date: Tue, 26 Jul 2022 18:23:02 +0800 Subject: [PATCH 16/20] fix case --- tests/system-test/1-insert/mutil_stage.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/system-test/1-insert/mutil_stage.py b/tests/system-test/1-insert/mutil_stage.py index 711f3321ff..97a4afdc60 100644 --- a/tests/system-test/1-insert/mutil_stage.py +++ b/tests/system-test/1-insert/mutil_stage.py @@ -212,7 +212,7 @@ class TDTestCase: for i in range(ctb_num): tdSql.execute(f'create table {dbname}.{ctb_pre}{i+1} using {dbname}.{stb} tags ( {i+1} )') - def __insert_data(self, rows,dbname=DBNAME): + def __insert_data(self, rows, dbname=DBNAME, ctb_num=20): data = DataSet() data.get_order_set(rows) @@ -229,12 +229,14 @@ class TDTestCase: {1 * data.usint_data[i]}, {1 * data.uint_data[i]}, {1 * data.ubint_data[i]} ''' - tdSql.execute( - f"insert into {dbname}.{CTB_PRE}1 values ( {NOW - i * TIME_STEP}, {row_data} )") - tdSql.execute( - f"insert into {dbname}.{CTB_PRE}2 values ( {NOW - i * int(TIME_STEP * 0.6)}, {neg_row_data} )") - tdSql.execute( - f"insert into {dbname}.{CTB_PRE}4 values ( {NOW - i * int(TIME_STEP * 0.8) }, {row_data} )") + for i in range(ctb_num): + tdSql.execute( + f"insert into {dbname}.{CTB_PRE}{i + 1} values ( {NOW - i * TIME_STEP}, {row_data} )") + + # tdSql.execute( + # f"insert into {dbname}.{CTB_PRE}2 values ( {NOW - i * int(TIME_STEP * 0.6)}, {neg_row_data} )") + # tdSql.execute( + # f"insert into {dbname}.{CTB_PRE}4 values ( {NOW - i * int(TIME_STEP * 0.8) }, {row_data} )") tdSql.execute( f"insert into {dbname}.{NTB_PRE}1 values ( {NOW - i * int(TIME_STEP * 1.2)}, {row_data} )") From 1c45770c6240bbc6f04a5f76cfbbc2d7c5f884ab Mon Sep 17 00:00:00 2001 From: cpwu Date: Wed, 27 Jul 2022 10:10:05 +0800 Subject: [PATCH 17/20] fix case of tSma --- tests/system-test/1-insert/time_range_wise.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/system-test/1-insert/time_range_wise.py b/tests/system-test/1-insert/time_range_wise.py index f945bafe3b..e65dded601 100644 --- a/tests/system-test/1-insert/time_range_wise.py +++ b/tests/system-test/1-insert/time_range_wise.py @@ -1,4 +1,5 @@ import datetime +import time from dataclasses import dataclass from typing import List, Any, Tuple @@ -328,11 +329,15 @@ class TDTestCase: tdSql.query("select database()") dbname = tdSql.getData(0,0) tdSql.query("show databases") + for index , value in enumerate(tdSql.cursor.description): + if value[0] == "retention": + r_index = index + break for row in tdSql.queryResult: if row[0] == dbname: - if row[-1] is None: + if row[r_index] is None: continue - if ":" in row[-1]: + if ":" in row[r_index]: sma.rollup_db = True if sma.rollup_db : return False @@ -393,8 +398,6 @@ class TDTestCase: else: tdSql.error(self.__create_sma_index(sma)) - - def __drop_sma_index(self, sma:SMAschema): sql = f"{sma.drop} {sma.drop_flag} {sma.index_name}" return sql @@ -416,8 +419,7 @@ class TDTestCase: self.sma_created_index = list(filter(lambda x: x != sma.index_name, self.sma_created_index)) tdSql.query("show streams") tdSql.checkRows(self.sma_count) - - + time.sleep(1) else: tdSql.error(self.__drop_sma_index(sma)) From 3c8ac2192653cfe19b73e6fb6b91901e880543f7 Mon Sep 17 00:00:00 2001 From: cpwu Date: Wed, 27 Jul 2022 10:10:15 +0800 Subject: [PATCH 18/20] fix case --- tests/system-test/fulltest.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system-test/fulltest.sh b/tests/system-test/fulltest.sh index 7c42f51ee0..7ecc81415d 100755 --- a/tests/system-test/fulltest.sh +++ b/tests/system-test/fulltest.sh @@ -27,7 +27,7 @@ python3 ./test.py -f 1-insert/alter_stable.py python3 ./test.py -f 1-insert/alter_table.py python3 ./test.py -f 1-insert/insertWithMoreVgroup.py python3 ./test.py -f 1-insert/table_comment.py -#python3 ./test.py -f 1-insert/time_range_wise.py +python3 ./test.py -f 1-insert/time_range_wise.py python3 ./test.py -f 1-insert/block_wise.py python3 ./test.py -f 1-insert/create_retentions.py python3 ./test.py -f 1-insert/table_param_ttl.py From b14dee976fa483ec6e48086c1b259301b2eeff31 Mon Sep 17 00:00:00 2001 From: cpwu Date: Wed, 27 Jul 2022 10:43:50 +0800 Subject: [PATCH 19/20] fix case --- tests/system-test/1-insert/mutil_stage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/system-test/1-insert/mutil_stage.py b/tests/system-test/1-insert/mutil_stage.py index 97a4afdc60..fcad114edd 100644 --- a/tests/system-test/1-insert/mutil_stage.py +++ b/tests/system-test/1-insert/mutil_stage.py @@ -229,9 +229,9 @@ class TDTestCase: {1 * data.usint_data[i]}, {1 * data.uint_data[i]}, {1 * data.ubint_data[i]} ''' - for i in range(ctb_num): + for j in range(ctb_num): tdSql.execute( - f"insert into {dbname}.{CTB_PRE}{i + 1} values ( {NOW - i * TIME_STEP}, {row_data} )") + f"insert into {dbname}.{CTB_PRE}{j + 1} values ( {NOW - i * TIME_STEP}, {row_data} )") # tdSql.execute( # f"insert into {dbname}.{CTB_PRE}2 values ( {NOW - i * int(TIME_STEP * 0.6)}, {neg_row_data} )") From f15c6b0ef08a8607180c2c7e4722d11992ffee6c Mon Sep 17 00:00:00 2001 From: cpwu Date: Wed, 27 Jul 2022 14:38:34 +0800 Subject: [PATCH 20/20] fix case --- tests/system-test/2-query/diff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system-test/2-query/diff.py b/tests/system-test/2-query/diff.py index 9eac56b9e3..76d4891a1c 100644 --- a/tests/system-test/2-query/diff.py +++ b/tests/system-test/2-query/diff.py @@ -96,7 +96,7 @@ class TDTestCase: tdSql.error(f"select diff(col12) from {dbname}.stb_1") tdSql.error(f"select diff(col13) from {dbname}.stb_1") tdSql.error(f"select diff(col14) from {dbname}.stb_1") - tdSql.error(f"select ts,diff(col1),ts from {dbname}.stb_1") + tdSql.query(f"select ts,diff(col1),ts from {dbname}.stb_1") tdSql.query(f"select diff(col1) from {dbname}.stb_1") tdSql.checkRows(10)