From 9172cfff82c83a8689b074c4e47c7bd8cbc685dd Mon Sep 17 00:00:00 2001 From: cpwu Date: Thu, 21 Apr 2022 18:54:32 +0800 Subject: [PATCH 01/20] fix case --- tests/system-test/2-query/cast.py | 45 ++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/tests/system-test/2-query/cast.py b/tests/system-test/2-query/cast.py index f09e7d1f63..a8fc16ae7a 100644 --- a/tests/system-test/2-query/cast.py +++ b/tests/system-test/2-query/cast.py @@ -15,7 +15,50 @@ class TDTestCase: tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) - def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring + def __cast_to_bigint(self, col_name, tbname): + __sql = f"select cast({col_name} as bigint), {col_name} from {tbname}" + tdSql.query(sql=__sql) + data_tb_col = [result[1] for result in tdSql.queryResult] + for i in range(len(tdSql.queryRows)): + tdSql.checkData( i, 0, None ) if data_tb_col[i] is None else tdSql.checkData( i, 0, int(data_tb_col[i]) ) + + def __range_to_bigint(self,cols,tables): + for col in cols: + for table in tables: + self.__cast_to_bigint(col_name=col, tbname=table) + + def __cast_to_timestamp(self, col_name, tbname): + __sql = f"select cast({col_name} as timestamp), {col_name} from {tbname}" + tdSql.query(sql=__sql) + data_tb_col = [result[1] for result in tdSql.queryResult] + for i in range(len(tdSql.queryRows)): + if data_tb_col[i] is None: + tdSql.checkData( i, 0 , None ) + if (col_name == "c2" or col_name == "double" ) and tbname == "t1" and i == 10: + continue + else: + utc_zone = datetime.timezone.utc + utc_8 = datetime.timezone(datetime.timedelta(hours=8)) + date_init_stamp = datetime.datetime.utcfromtimestamp(data_tb_col[i]/1000) + date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f") + tdSql.checkData( i, 0, date_data) + + def __range_to_timestamp(self, cols, tables): + for col in cols: + for table in tables: + self.__cast_to_timestamp(col_name=col, tbname=table) + + def __test_bigint(self): + __table_list = ["ct1", "ct4", "t1"] + __col_list = ["c1","c2","c3","c4","c5","c6","c7","c10","c1+c2"] + self.__range_to_bigint(cols=__col_list, tables=__table_list) + + def __test_timestamp(self): + __table_list = ["ct1", "ct4", "t1"] + __col_list = ["c1","c2","c3","c4","c5","c6","c7","c1+c2"] + self.__range_to_timestamp(cols=__col_list, tables=__table_list) + + def run(self): tdSql.prepare() tdLog.printNoPrefix("==========step1:create table") From bdd0412918afbd96975c862be1070b27bd833515 Mon Sep 17 00:00:00 2001 From: cpwu Date: Thu, 21 Apr 2022 18:54:43 +0800 Subject: [PATCH 02/20] fix case --- tests/system-test/2-query/cast.py | 110 ++++++++++++++++-------------- 1 file changed, 60 insertions(+), 50 deletions(-) diff --git a/tests/system-test/2-query/cast.py b/tests/system-test/2-query/cast.py index a8fc16ae7a..adcd52b598 100644 --- a/tests/system-test/2-query/cast.py +++ b/tests/system-test/2-query/cast.py @@ -6,6 +6,7 @@ import inspect from util.log import * from util.sql import * from util.cases import * +from util.dnodes import * @@ -58,56 +59,7 @@ class TDTestCase: __col_list = ["c1","c2","c3","c4","c5","c6","c7","c1+c2"] self.__range_to_timestamp(cols=__col_list, tables=__table_list) - def run(self): - tdSql.prepare() - - tdLog.printNoPrefix("==========step1:create table") - tdSql.execute( - '''create table 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 - (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} )') - - tdLog.printNoPrefix("==========step2:insert data") - 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 )" - ) - 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 )" - ) - 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 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 ) - ''' - ) + def all_test(self): tdSql.query("select c1 from ct4") data_ct4_c1 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] @@ -667,7 +619,65 @@ class TDTestCase: tdSql.error("select cast(c8 as timestamp ) as b from ct4") tdSql.error("select cast(c9 as timestamp ) as b from ct4") tdSql.error("select cast(c9 as binary(64) ) as b from ct4") + pass + def run(self): + tdSql.prepare() + + tdLog.printNoPrefix("==========step1:create table") + tdSql.execute( + '''create table 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 + (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} )') + + tdLog.printNoPrefix("==========step2:insert data") + 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 )" + ) + 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 )" + ) + 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 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 ) + ''' + ) + + self.all_test() + + tdDnodes.stop(1) + tdDnodes.start(1) + + self.all_test() def stop(self): tdSql.close() From f9dea8132c65e31c02fdd7032a10f9806cf46568 Mon Sep 17 00:00:00 2001 From: cpwu Date: Fri, 22 Apr 2022 11:16:16 +0800 Subject: [PATCH 03/20] fix cast add wal test --- tests/system-test/2-query/cast.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/system-test/2-query/cast.py b/tests/system-test/2-query/cast.py index adcd52b598..ea6d8c1a8a 100644 --- a/tests/system-test/2-query/cast.py +++ b/tests/system-test/2-query/cast.py @@ -677,6 +677,8 @@ class TDTestCase: tdDnodes.stop(1) tdDnodes.start(1) + tdSql.execute("use db") + self.all_test() def stop(self): From af970cccecfc0c369e5defc599ab3d2b0a9547c5 Mon Sep 17 00:00:00 2001 From: cpwu Date: Fri, 22 Apr 2022 16:13:41 +0800 Subject: [PATCH 04/20] add sum case --- tests/system-test/2-query/cast.py | 8 +- tests/system-test/2-query/sum.py | 120 ++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 4 deletions(-) create mode 100644 tests/system-test/2-query/sum.py diff --git a/tests/system-test/2-query/cast.py b/tests/system-test/2-query/cast.py index ea6d8c1a8a..78633e1a16 100644 --- a/tests/system-test/2-query/cast.py +++ b/tests/system-test/2-query/cast.py @@ -235,7 +235,7 @@ class TDTestCase: tdSql.checkData( i, 0, date_data) - tdLog.printNoPrefix("==========step16: cast smallint to bigint, expect no changes") + tdLog.printNoPrefix("==========step16: cast tinyint to bigint, expect no changes") tdSql.query("select c4 from ct4") data_ct4_c4 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] tdSql.query("select c4 from t1") @@ -249,7 +249,7 @@ class TDTestCase: tdSql.checkData( i, 0, data_t1_c4[i]) - tdLog.printNoPrefix("==========step17: cast smallint to binary, expect changes to str(int) ") + tdLog.printNoPrefix("==========step17: cast tinyint to binary, expect changes to str(int) ") tdSql.query("select cast(c4 as binary(32)) as b from ct4") for i in range(len(data_ct4_c4)): @@ -258,7 +258,7 @@ class TDTestCase: for i in range(len(data_t1_c4)): tdSql.checkData( i, 0, str(data_t1_c4[i]) ) - tdLog.printNoPrefix("==========step18: cast smallint to nchar, expect changes to str(int) ") + tdLog.printNoPrefix("==========step18: cast tinyint to nchar, expect changes to str(int) ") tdSql.query("select cast(c4 as nchar(32)) as b from ct4") for i in range(len(data_ct4_c4)): @@ -267,7 +267,7 @@ class TDTestCase: for i in range(len(data_t1_c4)): tdSql.checkData( i, 0, str(data_t1_c4[i]) ) - tdLog.printNoPrefix("==========step19: cast smallint to timestamp, expect changes to timestamp ") + tdLog.printNoPrefix("==========step19: cast tinyint to timestamp, expect changes to timestamp ") tdSql.query("select cast(c4 as timestamp) as b from ct4") for i in range(len(data_ct4_c4)): diff --git a/tests/system-test/2-query/sum.py b/tests/system-test/2-query/sum.py new file mode 100644 index 0000000000..1ec167ed09 --- /dev/null +++ b/tests/system-test/2-query/sum.py @@ -0,0 +1,120 @@ +import taos +import sys +import datetime +import inspect + +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * + + + +class TDTestCase: + + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor()) + + def __sum_checkdata(self, row, col,data): + pass + + + + def all_test(self): + + pass + + def __create_tb(self): + tdSql.prepare() + + tdLog.printNoPrefix("==========step1:create table") + tdSql.execute( + '''create table 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 + (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} )') + + def __insert_data(self, rows): + 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 )" + ) + 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 )" + ) + 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 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(f"insert into ct4 values (now()+{rows * 9}d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f'''insert into ct4 values + (now()+{rows * 9-10}d, {pow(2,31)-pow(2,15)}, {pow(2,63)-pow(2,30)}, 32767, 127, + { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nachar_limit-1", now()-1d ) + ''') + + tdSql.execute(f'''insert into ct4 values + (now()+{rows * 9-20}d, {pow(2,31)-pow(2,16)}, {pow(2,63)-pow(2,31)}, 32766, 126, + { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, + "binary_limit-2", "nachar_limit-2", now()-2d ) + ''') + + for i in range(rows): + tdSql.execute( + f'''insert into t1 values + ( now()-{i}h, {i}, {i}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}, + "binary_{i}", "nchar_{i}", now-{i}s ) + ''' + ) + tdSql.execute( + f'''insert into t1 values + ( now() + 3h, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( now()-{ ( rows // 2 ) * 60 + 30 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( now()-{rows}h, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( now() + 2h, {pow(2,31)-pow(2,15)}, {pow(2,63)-pow(2,30)}, 32767, 127, + { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, + "binary_limit-1", "nachar_limit-1", now()-1d + ) + (now() + 1h , {pow(2,31)-pow(2,16)}, {pow(2,63)-pow(2,31)}, 32766, 126, + { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, + "binary_limit-2", "nachar_limit-2", now()-2d + ) + ''' + ) + + + def run(self): + tdSql.prepare() + + tdLog.printNoPrefix("==========step1:create table") + self.__create_tb() + + tdLog.printNoPrefix("==========step2:insert data") + self.__insert_data() + + + self.all_test() + + tdDnodes.stop(1) + tdDnodes.start(1) + + tdSql.execute("use db") + + self.all_test() + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) From bb815260fc87d80a23239ed7af1ed7cc19538501 Mon Sep 17 00:00:00 2001 From: cpwu Date: Fri, 22 Apr 2022 19:03:29 +0800 Subject: [PATCH 05/20] fix case --- tests/system-test/2-query/sum.py | 109 ++++++++++++++++++++++++------- 1 file changed, 86 insertions(+), 23 deletions(-) diff --git a/tests/system-test/2-query/sum.py b/tests/system-test/2-query/sum.py index 1ec167ed09..b23c942e40 100644 --- a/tests/system-test/2-query/sum.py +++ b/tests/system-test/2-query/sum.py @@ -9,16 +9,48 @@ from util.cases import * from util.dnodes import * +INT_COL = "c1" +BINT_COL = "c2" +SINT_COL = "c3" +TINT_COL = "c4" +FLOAT_COL = "c5" +DOUBLE_COL = "c6" +BOOL_COL = "c7" + +BINARY_COL = "c8" +NCHAR_COL = "c9" +TS_COL = "c10" + +NUM_COL = [INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, BOOL_COL] +UN_NUM_COL = [BINARY_COL, NCHAR_COL, TS_COL] class TDTestCase: + + def init(self, conn, logSql): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) - def __sum_checkdata(self, row, col,data): + def __sum_current_check(self, row, col,data): pass + def __sum_err_check(self,tbanme): + sqls = [] + + for un_num_col in UN_NUM_COL: + sqls.append( f"select sum( {un_num_col} ) from {tbanme} " ) + sqls.extend( f"select sum( {un_num_col} + {num_col} ) from {tbanme} " for num_col in NUM_COL ) + sqls.extend( f"select sum( {un_num_col} + {un_num_col_2} ) from {tbanme} " for un_num_col_2 in UN_NUM_COL ) + + return sqls + + def __test_error(self): + tbname = ["ct1", "ct2", "ct4", "t1"] + + for tb in tbname: + for errsql in self.__sum_err_check(tb): + tdSql.error(sql=errsql) def all_test(self): @@ -30,15 +62,20 @@ class TDTestCase: tdLog.printNoPrefix("==========step1:create table") tdSql.execute( - '''create table 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) + f'''create table stb1( + ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, + {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, + {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp) tags (t1 int) ''' ) 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) + create table t1( + ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, + {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, + {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp + ) ''' ) for i in range(4): @@ -52,22 +89,47 @@ class TDTestCase: 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 )" ) - 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( + f"insert into ct2 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 ) + ( now()+10s, 9, -99999, -999, -99, -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(f"insert into ct4 values (now()+{rows * 9}d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute(f'''insert into ct4 values - (now()+{rows * 9-10}d, {pow(2,31)-pow(2,15)}, {pow(2,63)-pow(2,30)}, 32767, 127, - { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nachar_limit-1", now()-1d ) - ''') + tdSql.execute( + f'''insert into ct4 values + ( now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( now()+{rows * 9}d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( + now()+{rows * 9-10}d, {pow(2,31)-pow(2,15)}, {pow(2,63)-pow(2,30)}, 32767, 127, + { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nachar_limit-1", now()-1d + ) + ( + now()+{rows * 9-20}d, {pow(2,31)-pow(2,16)}, {pow(2,63)-pow(2,31)}, 32766, 126, + { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nachar_limit-2", now()-2d + ) + ''' + ) - tdSql.execute(f'''insert into ct4 values - (now()+{rows * 9-20}d, {pow(2,31)-pow(2,16)}, {pow(2,63)-pow(2,31)}, 32766, 126, - { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, - "binary_limit-2", "nachar_limit-2", now()-2d ) - ''') + tdSql.execute( + f'''insert into ct2 values + ( now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( now()+{rows * 9}d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( + now()+{rows * 9-10}d, { -1 * pow(2,31) + pow(2,15) }, { -1 * pow(2,63) + pow(2,30) }, -32766, -126, + { -1 * 3.2 * pow(10,38) }, { -1.2 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nachar_limit-1", now()-1d + ) + ( + now()+{rows * 9-20}d, { -1 * pow(2,31) + pow(2,16) }, { -1 * pow(2,63) + pow(2,31) }, -32767, -127, + { - 3.3 * pow(10,38) }, { -1.3 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nachar_limit-2", now()-2d + ) + ''' + ) for i in range(rows): tdSql.execute( @@ -79,13 +141,14 @@ class TDTestCase: tdSql.execute( f'''insert into t1 values ( now() + 3h, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( now()-{ ( rows // 2 ) * 60 + 30 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( now()-{ ( rows // 2 ) * 60 + 30 }m, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( now()-{rows}h, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( now() + 2h, {pow(2,31)-pow(2,15)}, {pow(2,63)-pow(2,30)}, 32767, 127, + ( now() + 2h, { pow(2,31) - pow(2,15) }, { pow(2,63) - pow(2,30) }, 32767, 127, { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nachar_limit-1", now()-1d ) - (now() + 1h , {pow(2,31)-pow(2,16)}, {pow(2,63)-pow(2,31)}, 32766, 126, + ( + now() + 1h , { pow(2,31) - pow(2,16) }, { pow(2,63) - pow(2,31) }, 32766, 126, { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nachar_limit-2", now()-2d ) @@ -100,7 +163,7 @@ class TDTestCase: self.__create_tb() tdLog.printNoPrefix("==========step2:insert data") - self.__insert_data() + self.__insert_data(1000) self.all_test() From bd932b3e773f86c23dfd6bd798ed5c227f7fac5f Mon Sep 17 00:00:00 2001 From: cpwu Date: Fri, 22 Apr 2022 19:27:17 +0800 Subject: [PATCH 06/20] fix case --- tests/system-test/2-query/sum.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/system-test/2-query/sum.py b/tests/system-test/2-query/sum.py index b23c942e40..85559ba5dd 100644 --- a/tests/system-test/2-query/sum.py +++ b/tests/system-test/2-query/sum.py @@ -61,23 +61,23 @@ class TDTestCase: tdSql.prepare() tdLog.printNoPrefix("==========step1:create table") - tdSql.execute( - f'''create table stb1( + create_stb_sql = f'''create table stb1( ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, - {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, - {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp) - tags (t1 int) + {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, + {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp + ) tags (t1 int) ''' - ) - tdSql.execute( - ''' - create table t1( + create_ntb_sql = f'''create table stb1( ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, - {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, - {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp + {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, + {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp ) ''' - ) + print(create_stb_sql) + print(create_ntb_sql) + tdSql.execute(create_stb_sql) + tdSql.execute(create_ntb_sql) + for i in range(4): tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') From db97f5606a2315035f7845ab7d7292dda98a5703 Mon Sep 17 00:00:00 2001 From: cpwu Date: Fri, 22 Apr 2022 19:32:48 +0800 Subject: [PATCH 07/20] fix case --- tests/system-test/2-query/sum.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/system-test/2-query/sum.py b/tests/system-test/2-query/sum.py index 85559ba5dd..91f3295e9f 100644 --- a/tests/system-test/2-query/sum.py +++ b/tests/system-test/2-query/sum.py @@ -73,8 +73,6 @@ class TDTestCase: {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp ) ''' - print(create_stb_sql) - print(create_ntb_sql) tdSql.execute(create_stb_sql) tdSql.execute(create_ntb_sql) @@ -132,12 +130,11 @@ class TDTestCase: ) for i in range(rows): - tdSql.execute( - f'''insert into t1 values + insert_data = f'''insert into t1 values ( now()-{i}h, {i}, {i}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}, "binary_{i}", "nchar_{i}", now-{i}s ) ''' - ) + tdSql.execute(insert_data) tdSql.execute( f'''insert into t1 values ( now() + 3h, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) From 98809c098625f077009701569ba5d27209663843 Mon Sep 17 00:00:00 2001 From: cpwu Date: Fri, 22 Apr 2022 19:34:49 +0800 Subject: [PATCH 08/20] fix case --- tests/script/tsim/query/crash_sql.sim | 103 ++++++++++++++++++++++++++ tests/system-test/2-query/sum.py | 2 +- 2 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 tests/script/tsim/query/crash_sql.sim diff --git a/tests/script/tsim/query/crash_sql.sim b/tests/script/tsim/query/crash_sql.sim new file mode 100644 index 0000000000..44671fbb0d --- /dev/null +++ b/tests/script/tsim/query/crash_sql.sim @@ -0,0 +1,103 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +print =============== create database +sql create database db +sql show databases +if $rows != 2 then + return -1 +endi + +sql use db + +print =============== create super table and child table +sql create table 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) +sql show stables +print $rows $data00 $data01 $data02 +if $rows != 1 then + return -1 +endi + +sql create table ct1 using stb1 tags ( 1 ) +sql create table ct2 using stb1 tags ( 2 ) +sql create table ct3 using stb1 tags ( 3 ) +sql create table ct4 using stb1 tags ( 4 ) +sql show tables +print $rows $data00 $data10 $data20 +if $rows != 4 then + return -1 +endi + +print =============== insert data into child table ct1 (s) +sql insert into ct1 values ( '2022-01-01 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct1 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct1 values ( '2022-01-01 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct1 values ( '2022-01-01 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct1 values ( '2022-01-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct1 values ( '2022-01-01 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct1 values ( '2022-01-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+7a ) +sql insert into ct1 values ( '2022-01-01 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+8a ) + +print =============== insert data into child table ct2 (d) +sql insert into ct2 values ( '2022-01-01 01:00:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct2 values ( '2022-01-01 10:00:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct2 values ( '2022-01-01 20:00:01.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct2 values ( '2022-01-02 10:00:01.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct2 values ( '2022-01-02 20:00:01.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct2 values ( '2022-01-03 10:00:01.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+6a ) +sql insert into ct2 values ( '2022-01-03 20:00:01.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+7a ) + +print =============== insert data into child table ct3 (n) +sql insert into ct3 values ( '2021-12-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) +sql insert into ct3 values ( '2021-12-31 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct3 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct3 values ( '2022-01-07 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct3 values ( '2022-01-31 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct3 values ( '2022-02-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct3 values ( '2022-02-28 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct3 values ( '2022-03-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct3 values ( '2022-03-08 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) + +print =============== insert data into child table ct4 (y) +sql insert into ct4 values ( '2019-01-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) +sql insert into ct4 values ( '2019-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct4 values ( '2019-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct4 values ( '2020-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct4 values ( '2020-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct4 values ( '2020-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct4 values ( '2020-12-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) +sql insert into ct4 values ( '2021-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct4 values ( '2021-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct4 values ( '2021-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) +sql insert into ct4 values ( '2022-02-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) +sql insert into ct4 values ( '2022-05-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + + +print ================ start query ====================== +print ================ SQL used to cause taosd or taos shell crash +sql select sum(c1) ,count(c1) from ct4 group by c1 having sum(c10) between 0 and 1 ; + + + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/system-test/2-query/sum.py b/tests/system-test/2-query/sum.py index 91f3295e9f..19caf3815b 100644 --- a/tests/system-test/2-query/sum.py +++ b/tests/system-test/2-query/sum.py @@ -132,7 +132,7 @@ class TDTestCase: for i in range(rows): insert_data = f'''insert into t1 values ( now()-{i}h, {i}, {i}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}, - "binary_{i}", "nchar_{i}", now-{i}s ) + "binary_{i}", "nchar_{i}", now()-{i}s ) ''' tdSql.execute(insert_data) tdSql.execute( From a7661c467ee43b94412e4eafdd808a83b75713e1 Mon Sep 17 00:00:00 2001 From: cpwu Date: Fri, 22 Apr 2022 19:38:27 +0800 Subject: [PATCH 09/20] fix case --- tests/system-test/2-query/sum.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system-test/2-query/sum.py b/tests/system-test/2-query/sum.py index 19caf3815b..f835e5e435 100644 --- a/tests/system-test/2-query/sum.py +++ b/tests/system-test/2-query/sum.py @@ -67,7 +67,7 @@ class TDTestCase: {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp ) tags (t1 int) ''' - create_ntb_sql = f'''create table stb1( + create_ntb_sql = f'''create table t1( ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp From d362881572c0a275c926701b7620dd34ce637aba Mon Sep 17 00:00:00 2001 From: cpwu Date: Sun, 24 Apr 2022 14:50:57 +0800 Subject: [PATCH 10/20] add sum case --- tests/system-test/2-query/sum.py | 64 ++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 12 deletions(-) diff --git a/tests/system-test/2-query/sum.py b/tests/system-test/2-query/sum.py index f835e5e435..90435f8b86 100644 --- a/tests/system-test/2-query/sum.py +++ b/tests/system-test/2-query/sum.py @@ -26,26 +26,64 @@ UN_NUM_COL = [BINARY_COL, NCHAR_COL, TS_COL] class TDTestCase: - - def init(self, conn, logSql): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) - def __sum_current_check(self, row, col,data): - pass + def __sum_condition(self): + sum_condition = [] + for num_col in NUM_COL: + sum_condition.extend( + ( + num_col, + f"ceil( {num_col} )", + ) + ) + sum_condition.extend( f"{num_col} + {num_col_2}" for num_col_2 in NUM_COL ) + sum_condition.extend( f"{num_col} + {un_num_col} " for un_num_col in UN_NUM_COL ) + + return sum_condition + + def __where_condition(self, col): + return f" where {col} < 1000000 " + + def __group_condition(self, col, having = ""): + return f" group by {col} having {having}" if having else f" group by {col} " + + def __sum_current_check(self, tbname): + sum_condition = self.__sum_condition() + for condition in sum_condition: + where_condition = self.__where_condition(condition) + group_condition = self.__group_condition(condition, having=f"{condition} is not null " ) + + tdSql.query(f"select {condition} from {tbname} {where_condition} {group_condition} ") + datas = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] + sum_data = sum(datas) + tdSql.query(f"select sum( {condition} ) from {tbname} {where_condition} {group_condition}") + tdSql.checkData(0, 0, sum_data) def __sum_err_check(self,tbanme): sqls = [] for un_num_col in UN_NUM_COL: - sqls.append( f"select sum( {un_num_col} ) from {tbanme} " ) - sqls.extend( f"select sum( {un_num_col} + {num_col} ) from {tbanme} " for num_col in NUM_COL ) + sqls.extend( + ( + f"select sum( {un_num_col} ) from {tbanme} ", + f"select sum(ceil( {un_num_col} )) from {tbanme} ", + ) + ) sqls.extend( f"select sum( {un_num_col} + {un_num_col_2} ) from {tbanme} " for un_num_col_2 in UN_NUM_COL ) return sqls + def __test_current(self): + tdLog.printNoPrefix("==========current sql condition check , must return query ok==========") + tbname = ["ct1", "ct2", "ct4", "t1"] + for tb in tbname: + self.__sum_current_check(tb) + def __test_error(self): + tdLog.printNoPrefix("==========err sql condition check , must return error==========") tbname = ["ct1", "ct2", "ct4", "t1"] for tb in tbname: @@ -54,8 +92,9 @@ class TDTestCase: def all_test(self): + self.__test_current() + self.__test_error() - pass def __create_tb(self): tdSql.prepare() @@ -162,15 +201,16 @@ class TDTestCase: tdLog.printNoPrefix("==========step2:insert data") self.__insert_data(1000) - + tdLog.printNoPrefix("==========step3:all check") self.all_test() - tdDnodes.stop(1) - tdDnodes.start(1) + # tdDnodes.stop(1) + # tdDnodes.start(1) - tdSql.execute("use db") + # tdSql.execute("use db") - self.all_test() + # tdLog.printNoPrefix("==========step4:after wal, all check again ") + # self.all_test() def stop(self): tdSql.close() From 5fe7882abec69ed5ed3eaa0d78e5f59ba4aabf55 Mon Sep 17 00:00:00 2001 From: cpwu Date: Sun, 24 Apr 2022 15:04:12 +0800 Subject: [PATCH 11/20] fix case --- tests/system-test/2-query/sum.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/system-test/2-query/sum.py b/tests/system-test/2-query/sum.py index 90435f8b86..eaa94af3e6 100644 --- a/tests/system-test/2-query/sum.py +++ b/tests/system-test/2-query/sum.py @@ -59,9 +59,11 @@ class TDTestCase: tdSql.query(f"select {condition} from {tbname} {where_condition} {group_condition} ") datas = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] sum_data = sum(datas) - tdSql.query(f"select sum( {condition} ) from {tbname} {where_condition} {group_condition}") + tdSql.query(f"select sum( {condition} ) from {tbname} {where_condition} ") tdSql.checkData(0, 0, sum_data) + tdSql.query(f"select {condition} from {tbname} {where_condition} {group_condition} ") + def __sum_err_check(self,tbanme): sqls = [] @@ -199,7 +201,7 @@ class TDTestCase: self.__create_tb() tdLog.printNoPrefix("==========step2:insert data") - self.__insert_data(1000) + self.__insert_data(100) tdLog.printNoPrefix("==========step3:all check") self.all_test() From f6d3f059493d5855cb04d5328ed8c84a72fb2a9e Mon Sep 17 00:00:00 2001 From: cpwu Date: Sun, 24 Apr 2022 15:07:44 +0800 Subject: [PATCH 12/20] fix case --- tests/system-test/2-query/sum.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system-test/2-query/sum.py b/tests/system-test/2-query/sum.py index eaa94af3e6..f816aac0a2 100644 --- a/tests/system-test/2-query/sum.py +++ b/tests/system-test/2-query/sum.py @@ -56,7 +56,7 @@ class TDTestCase: where_condition = self.__where_condition(condition) group_condition = self.__group_condition(condition, having=f"{condition} is not null " ) - tdSql.query(f"select {condition} from {tbname} {where_condition} {group_condition} ") + tdSql.query(f"select {condition} from {tbname} {where_condition} ") datas = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] sum_data = sum(datas) tdSql.query(f"select sum( {condition} ) from {tbname} {where_condition} ") From 85bca551b243e08e481e9eb07d8635091fd40076 Mon Sep 17 00:00:00 2001 From: cpwu Date: Sun, 24 Apr 2022 15:15:05 +0800 Subject: [PATCH 13/20] fix case --- tests/system-test/2-query/sum.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/system-test/2-query/sum.py b/tests/system-test/2-query/sum.py index f816aac0a2..b85a91fbc6 100644 --- a/tests/system-test/2-query/sum.py +++ b/tests/system-test/2-query/sum.py @@ -75,6 +75,7 @@ class TDTestCase: ) ) sqls.extend( f"select sum( {un_num_col} + {un_num_col_2} ) from {tbanme} " for un_num_col_2 in UN_NUM_COL ) + sqls.extend( f"select sum( {num_col} + c10 ) from {tbanme} " for num_col in NUM_COL ) return sqls From 59cbfcc27e16441165cac15d7d3f14e14d149c01 Mon Sep 17 00:00:00 2001 From: cpwu Date: Sun, 24 Apr 2022 15:18:20 +0800 Subject: [PATCH 14/20] fix case --- tests/system-test/2-query/sum.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system-test/2-query/sum.py b/tests/system-test/2-query/sum.py index b85a91fbc6..d50a840457 100644 --- a/tests/system-test/2-query/sum.py +++ b/tests/system-test/2-query/sum.py @@ -40,7 +40,7 @@ class TDTestCase: ) ) sum_condition.extend( f"{num_col} + {num_col_2}" for num_col_2 in NUM_COL ) - sum_condition.extend( f"{num_col} + {un_num_col} " for un_num_col in UN_NUM_COL ) + sum_condition.extend( f"{num_col} + {un_num_col} " for un_num_col in [BINARY_COL, NCHAR_COL] ) return sum_condition From 9890fa1fc07ea87879a0c4d506ade5b1f9cc689e Mon Sep 17 00:00:00 2001 From: cpwu Date: Sun, 24 Apr 2022 15:55:21 +0800 Subject: [PATCH 15/20] fix case --- tests/system-test/2-query/sum.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/system-test/2-query/sum.py b/tests/system-test/2-query/sum.py index d50a840457..8a4130c466 100644 --- a/tests/system-test/2-query/sum.py +++ b/tests/system-test/2-query/sum.py @@ -21,8 +21,9 @@ BINARY_COL = "c8" NCHAR_COL = "c9" TS_COL = "c10" -NUM_COL = [INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, BOOL_COL] -UN_NUM_COL = [BINARY_COL, NCHAR_COL, TS_COL] +NUM_COL = [INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, ] +UN_NUM_COL = [BINARY_COL, NCHAR_COL, BOOL_COL] +TS_TYPE_COL = [TS_COL] class TDTestCase: @@ -40,7 +41,8 @@ class TDTestCase: ) ) sum_condition.extend( f"{num_col} + {num_col_2}" for num_col_2 in NUM_COL ) - sum_condition.extend( f"{num_col} + {un_num_col} " for un_num_col in [BINARY_COL, NCHAR_COL] ) + sum_condition.extend( f"{num_col} + {un_num_col} " for un_num_col in UN_NUM_COL ) + sum_condition.extend(f"{un_num_col} + {ts_col} " for un_num_col in UN_NUM_COL for ts_col in TS_TYPE_COL) return sum_condition @@ -75,7 +77,7 @@ class TDTestCase: ) ) sqls.extend( f"select sum( {un_num_col} + {un_num_col_2} ) from {tbanme} " for un_num_col_2 in UN_NUM_COL ) - sqls.extend( f"select sum( {num_col} + c10 ) from {tbanme} " for num_col in NUM_COL ) + sqls.extend( f"select sum( {num_col} + {ts_col} ) from {tbanme} " for num_col in NUM_COL for ts_col in TS_TYPE_COL) return sqls From b4628209b7e53ff8c92da00c68c4543cd4ae084c Mon Sep 17 00:00:00 2001 From: cpwu Date: Sun, 24 Apr 2022 16:18:26 +0800 Subject: [PATCH 16/20] fix case --- tests/system-test/2-query/sum.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/system-test/2-query/sum.py b/tests/system-test/2-query/sum.py index 8a4130c466..3af3fdcf00 100644 --- a/tests/system-test/2-query/sum.py +++ b/tests/system-test/2-query/sum.py @@ -22,7 +22,7 @@ NCHAR_COL = "c9" TS_COL = "c10" NUM_COL = [INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, ] -UN_NUM_COL = [BINARY_COL, NCHAR_COL, BOOL_COL] +UN_NUM_COL = [BOOL_COL, BINARY_COL, NCHAR_COL, ] TS_TYPE_COL = [TS_COL] class TDTestCase: @@ -42,7 +42,6 @@ class TDTestCase: ) sum_condition.extend( f"{num_col} + {num_col_2}" for num_col_2 in NUM_COL ) sum_condition.extend( f"{num_col} + {un_num_col} " for un_num_col in UN_NUM_COL ) - sum_condition.extend(f"{un_num_col} + {ts_col} " for un_num_col in UN_NUM_COL for ts_col in TS_TYPE_COL) return sum_condition @@ -77,7 +76,8 @@ class TDTestCase: ) ) sqls.extend( f"select sum( {un_num_col} + {un_num_col_2} ) from {tbanme} " for un_num_col_2 in UN_NUM_COL ) - sqls.extend( f"select sum( {num_col} + {ts_col} ) from {tbanme} " for num_col in NUM_COL for ts_col in TS_TYPE_COL) + sqls.extend( f"select sum( {un_num_col} + {ts_col} ) from {tbanme} " for ts_col in TS_TYPE_COL ) + sqls.extend( f"select sum( {num_col} + {ts_col} ) from {tbanme} " for num_col in NUM_COL for ts_col in TS_TYPE_COL) return sqls From 0bf3204dee6578a68a1a94764391406753bc016f Mon Sep 17 00:00:00 2001 From: cpwu Date: Sun, 24 Apr 2022 16:21:32 +0800 Subject: [PATCH 17/20] fix case --- tests/system-test/2-query/sum.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/system-test/2-query/sum.py b/tests/system-test/2-query/sum.py index 3af3fdcf00..99ea0dbba4 100644 --- a/tests/system-test/2-query/sum.py +++ b/tests/system-test/2-query/sum.py @@ -86,6 +86,7 @@ class TDTestCase: tbname = ["ct1", "ct2", "ct4", "t1"] for tb in tbname: self.__sum_current_check(tb) + tdLog.printNoPrefix(f"==========current sql condition check in {tb} over==========") def __test_error(self): tdLog.printNoPrefix("==========err sql condition check , must return error==========") @@ -94,6 +95,7 @@ class TDTestCase: for tb in tbname: for errsql in self.__sum_err_check(tb): tdSql.error(sql=errsql) + tdLog.printNoPrefix(f"==========err sql condition check in {tb} over==========") def all_test(self): From 7f59a2d93708cd6e6d4240658514d239165e2ef3 Mon Sep 17 00:00:00 2001 From: cpwu Date: Sun, 24 Apr 2022 16:32:10 +0800 Subject: [PATCH 18/20] fix case --- tests/system-test/2-query/sum.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system-test/2-query/sum.py b/tests/system-test/2-query/sum.py index 99ea0dbba4..3b86e44788 100644 --- a/tests/system-test/2-query/sum.py +++ b/tests/system-test/2-query/sum.py @@ -59,7 +59,7 @@ class TDTestCase: tdSql.query(f"select {condition} from {tbname} {where_condition} ") datas = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] - sum_data = sum(datas) + sum_data = sum(filter(None, datas)) tdSql.query(f"select sum( {condition} ) from {tbname} {where_condition} ") tdSql.checkData(0, 0, sum_data) From 70607c03a60e3b31a36b070a9b60037af98c4e80 Mon Sep 17 00:00:00 2001 From: cpwu Date: Sun, 24 Apr 2022 17:52:35 +0800 Subject: [PATCH 19/20] fix case --- tests/system-test/2-query/sum.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system-test/2-query/sum.py b/tests/system-test/2-query/sum.py index 3b86e44788..a8fe8d4b7a 100644 --- a/tests/system-test/2-query/sum.py +++ b/tests/system-test/2-query/sum.py @@ -46,7 +46,7 @@ class TDTestCase: return sum_condition def __where_condition(self, col): - return f" where {col} < 1000000 " + return f" where abs( {col} ) < 1000000 " def __group_condition(self, col, having = ""): return f" group by {col} having {having}" if having else f" group by {col} " From 645d4829cfd758a9a3b8db313420e50cf97030f7 Mon Sep 17 00:00:00 2001 From: cpwu Date: Sun, 24 Apr 2022 18:03:41 +0800 Subject: [PATCH 20/20] fix case --- tests/system-test/2-query/sum.py | 232 +++++++++++++++++++++++++++++++ 1 file changed, 232 insertions(+) create mode 100644 tests/system-test/2-query/sum.py diff --git a/tests/system-test/2-query/sum.py b/tests/system-test/2-query/sum.py new file mode 100644 index 0000000000..65f5dfd653 --- /dev/null +++ b/tests/system-test/2-query/sum.py @@ -0,0 +1,232 @@ +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * + + +INT_COL = "c1" +BINT_COL = "c2" +SINT_COL = "c3" +TINT_COL = "c4" +FLOAT_COL = "c5" +DOUBLE_COL = "c6" +BOOL_COL = "c7" + +BINARY_COL = "c8" +NCHAR_COL = "c9" +TS_COL = "c10" + +NUM_COL = [INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, ] +UN_NUM_COL = [BOOL_COL, BINARY_COL, NCHAR_COL, ] +TS_TYPE_COL = [TS_COL] + +class TDTestCase: + + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor()) + + def __sum_condition(self): + sum_condition = [] + for num_col in NUM_COL: + sum_condition.extend( + ( + num_col, + f"ceil( {num_col} )", + ) + ) + sum_condition.extend( f"{num_col} + {num_col_2}" for num_col_2 in NUM_COL ) + sum_condition.extend( f"{num_col} + {un_num_col} " for un_num_col in UN_NUM_COL ) + sum_condition.append(1) + + return sum_condition + + def __where_condition(self, col): + return f" where abs( {col} ) < 1000000 " + + def __group_condition(self, col, having = ""): + return f" group by {col} having {having}" if having else f" group by {col} " + + def __sum_current_check(self, tbname): + sum_condition = self.__sum_condition() + for condition in sum_condition: + where_condition = self.__where_condition(condition) + group_condition = self.__group_condition(condition, having=f"{condition} is not null " ) + + tdSql.query(f"select {condition} from {tbname} {where_condition} ") + datas = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] + sum_data = sum(filter(None, datas)) + tdSql.query(f"select sum( {condition} ) from {tbname} {where_condition} ") + tdSql.checkData(0, 0, sum_data) + + tdSql.query(f"select {condition} from {tbname} {where_condition} {group_condition} ") + + def __sum_err_check(self,tbanme): + sqls = [] + + for un_num_col in UN_NUM_COL: + sqls.extend( + ( + f"select sum( {un_num_col} ) from {tbanme} ", + f"select sum(ceil( {un_num_col} )) from {tbanme} ", + ) + ) + sqls.extend( f"select sum( {un_num_col} + {un_num_col_2} ) from {tbanme} " for un_num_col_2 in UN_NUM_COL ) + sqls.extend( f"select sum( {un_num_col} + {ts_col} ) from {tbanme} " for ts_col in TS_TYPE_COL ) + + sqls.extend( f"select sum( {num_col} + {ts_col} ) from {tbanme} " for num_col in NUM_COL for ts_col in TS_TYPE_COL) + sqls.extend( + ( + f"select sum() from {tbanme} ", + f"select sum(*) from {tbanme} ", + f"select sum(ccccccc) from {tbanme} ", + f"select sum('test') from {tbanme} ", + ) + ) + + return sqls + + def __test_current(self): + tdLog.printNoPrefix("==========current sql condition check , must return query ok==========") + tbname = ["ct1", "ct2", "ct4", "t1"] + for tb in tbname: + self.__sum_current_check(tb) + tdLog.printNoPrefix(f"==========current sql condition check in {tb} over==========") + + def __test_error(self): + tdLog.printNoPrefix("==========err sql condition check , must return error==========") + tbname = ["ct1", "ct2", "ct4", "t1"] + + for tb in tbname: + for errsql in self.__sum_err_check(tb): + tdSql.error(sql=errsql) + tdLog.printNoPrefix(f"==========err sql condition check in {tb} over==========") + + + def all_test(self): + self.__test_current() + self.__test_error() + + + def __create_tb(self): + tdSql.prepare() + + tdLog.printNoPrefix("==========step1:create table") + create_stb_sql = f'''create table stb1( + ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, + {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, + {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp + ) tags (t1 int) + ''' + create_ntb_sql = f'''create table t1( + ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, + {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, + {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp + ) + ''' + tdSql.execute(create_stb_sql) + tdSql.execute(create_ntb_sql) + + for i in range(4): + tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + + def __insert_data(self, rows): + 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 )" + ) + 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 )" + ) + tdSql.execute( + f"insert into ct2 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 ) + ( now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a ) + ''' + ) + + tdSql.execute( + f'''insert into ct4 values + ( now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( now()+{rows * 9}d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( + now()+{rows * 9-10}d, {pow(2,31)-pow(2,15)}, {pow(2,63)-pow(2,30)}, 32767, 127, + { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nachar_limit-1", now()-1d + ) + ( + now()+{rows * 9-20}d, {pow(2,31)-pow(2,16)}, {pow(2,63)-pow(2,31)}, 32766, 126, + { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nachar_limit-2", now()-2d + ) + ''' + ) + + tdSql.execute( + f'''insert into ct2 values + ( now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( now()+{rows * 9}d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( + now()+{rows * 9-10}d, { -1 * pow(2,31) + pow(2,15) }, { -1 * pow(2,63) + pow(2,30) }, -32766, -126, + { -1 * 3.2 * pow(10,38) }, { -1.2 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nachar_limit-1", now()-1d + ) + ( + now()+{rows * 9-20}d, { -1 * pow(2,31) + pow(2,16) }, { -1 * pow(2,63) + pow(2,31) }, -32767, -127, + { - 3.3 * pow(10,38) }, { -1.3 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nachar_limit-2", now()-2d + ) + ''' + ) + + for i in range(rows): + insert_data = f'''insert into t1 values + ( now()-{i}h, {i}, {i}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}, + "binary_{i}", "nchar_{i}", now()-{i}s ) + ''' + tdSql.execute(insert_data) + tdSql.execute( + f'''insert into t1 values + ( now() + 3h, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( now()-{ ( rows // 2 ) * 60 + 30 }m, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( now()-{rows}h, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( now() + 2h, { pow(2,31) - pow(2,15) }, { pow(2,63) - pow(2,30) }, 32767, 127, + { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, + "binary_limit-1", "nachar_limit-1", now()-1d + ) + ( + now() + 1h , { pow(2,31) - pow(2,16) }, { pow(2,63) - pow(2,31) }, 32766, 126, + { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, + "binary_limit-2", "nachar_limit-2", now()-2d + ) + ''' + ) + + + def run(self): + tdSql.prepare() + + tdLog.printNoPrefix("==========step1:create table") + self.__create_tb() + + tdLog.printNoPrefix("==========step2:insert data") + self.__insert_data(100) + + tdLog.printNoPrefix("==========step3:all check") + self.all_test() + + # tdDnodes.stop(1) + # tdDnodes.start(1) + + # tdSql.execute("use db") + + # tdLog.printNoPrefix("==========step4:after wal, all check again ") + # self.all_test() + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase())