From 817e73bb125fe35192d6cf82374c7690086c4fcc Mon Sep 17 00:00:00 2001 From: cpwu Date: Sat, 14 May 2022 21:58:08 +0800 Subject: [PATCH 01/20] fix case --- tests/system-test/2-query/union.py | 378 +++++++++++++++++++++++++++++ 1 file changed, 378 insertions(+) create mode 100644 tests/system-test/2-query/union.py diff --git a/tests/system-test/2-query/union.py b/tests/system-test/2-query/union.py new file mode 100644 index 0000000000..e45265d129 --- /dev/null +++ b/tests/system-test/2-query/union.py @@ -0,0 +1,378 @@ +import datetime + +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * + +PRIMARY_COL = "ts" + +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, ] +CHAR_COL = [ BINARY_COL, NCHAR_COL, ] +BOOLEAN_COL = [ BOOL_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 __query_condition(self,tbname): + query_condition = [] + for char_col in CHAR_COL: + query_condition.extend( + ( + f"{tbname}.{char_col}", + f"upper( {tbname}.{char_col} )", + ) + ) + query_condition.extend( f"cast( {tbname}.{un_char_col} as binary(16) ) " for un_char_col in NUM_COL) + query_condition.extend( f"cast( {tbname}.{char_col} + {tbname}.{char_col_2} as binary(32) ) " for char_col_2 in CHAR_COL ) + query_condition.extend( f"cast( {tbname}.{char_col} + {tbname}.{un_char_col} as binary(32) ) " for un_char_col in NUM_COL ) + + for num_col in NUM_COL: + query_condition.extend( + ( + f"{tbname}.{num_col}", + f"ceil( {tbname}.{num_col} )", + f"sum( {tbname}.{num_col} )", + f"count( {tbname}.{num_col} )", + f"sin( {tbname}.{num_col} )", + ) + ) + query_condition.extend( f"{tbname}.{num_col} + {tbname}.{num_col_2}" for num_col_2 in NUM_COL ) + query_condition.extend( f"{tbname}.{num_col} + {tbname}.{char_col} " for char_col in CHAR_COL ) + + query_condition.append(''' "test1234!@#$%^&*():'>= 0" + if col in CHAR_COL: + return f" where lower( {tbname}.{col} ) like 'bina%' or lower( {tbname}.{col} ) like '_cha%' " + if col in BOOLEAN_COL: + return f" where {tbname}.{col} in (false, true) " + if col in TS_TYPE_COL or col in PRIMARY_COL: + return f" where cast( {tbname}.{col} as binary(16) ) is not null " + + return "" + + + def __group_condition(self, tbname, col, having = None): + return f" group by {tbname}.{col} having {having}" if having else f" group by {tbname}.{col} " + + def __single_sql(self, select_clause, from_clause, where_condition=None, group_condition=None): + return f"select {select_clause} from {from_clause} {where_condition} {group_condition}" + + + @property + def __join_tblist(self): + return [ + ["ct1", "ct2"], + ["ct1", "ct4"], + ["ct1", "t1"], + ["ct2", "ct4"], + ["ct2", "t1"], + ["ct4", "t1"], + ["ct1", "ct2", "ct4"], + ["ct1", "ct2", "t1"], + ["ct1", "ct4", "t1"], + ["ct2", "ct4", "t1"], + ["ct1", "ct2", "ct4", "t1"], + ] + + @property + def __tb_liast(self): + return [ + "ct1", + "ct2", + "ct4", + "t1", + ] + + def sql_list(self): + sqls = [] + __join_tblist = self.__join_tblist + for join_tblist in __join_tblist: + for join_tb in join_tblist: + select_claus = self.__query_condition(join_tb) + group_claus = self.__group_condition(tbname=join_tb, col=select_claus) + where_claus = self.__where_condition(query_conditon=select_claus) + having_claus = self.__group_condition(tbname=join_tb, col=select_claus, having=f"{select_claus} is not null") + sqls.extend( + ( + self.__single_sql(select_claus, join_tb, where_claus, group_claus), + self.__single_sql(select_claus, join_tb, where_claus, having_claus), + self.__single_sql(select_claus, self.__join_condition(join_tblist), where_claus, having_claus), + self.__single_sql(select_claus, self.__join_condition(join_tblist, INNER=True), where_claus, having_claus), + ) + ) + __no_join_tblist = self.__tb_liast + for tb in __no_join_tblist: + select_claus = self.__query_condition(tb) + group_claus = self.__group_condition(tbname=tb, col=select_claus) + where_claus = self.__where_condition(query_conditon=select_claus) + having_claus = self.__group_condition(tbname=tb, col=select_claus, having=f"{select_claus} is not null") + sqls.extend( + ( + self.__single_sql(select_claus, join_tb, where_claus, group_claus), + self.__single_sql(select_claus, join_tb, where_claus, having_claus), + ) + ) + + return sqls + + + + def union_check(self): + sqls = self.sql_list() + for sql1 in sqls: + for sql2 in sqls: + select_claus1 = sql1.split("from")[0].split("select")[1] + select_claus2 = sql2.split("from")[0].split("select")[1] + + pass + + def __join_check(self, tblist, checkrows, join_flag=True): + query_conditions = self.__query_condition(tblist[0]) + join_condition = self.__join_condition(tb_list=tblist) if join_flag else " " + for condition in query_conditions: + where_condition = self.__where_condition(col=condition, tbname=tblist[0]) + group_having = self.__group_condition(tbname=tblist[0], col=condition, having=f"{condition} is not null " ) + group_no_having= self.__group_condition(tbname=tblist[0], col=condition ) + groups = ["", group_having, group_no_having] + for group_condition in groups: + if where_condition: + sql = f" select {condition} from {tblist[0]},{tblist[1]} where {join_condition} and {where_condition} {group_condition} " + else: + sql = f" select {condition} from {tblist[0]},{tblist[1]} where {join_condition} {group_condition} " + + if not join_flag : + tdSql.error(sql=sql) + break + if len(tblist) == 2: + if "ct1" in tblist or "t1" in tblist: + self.__join_current(sql, checkrows) + elif where_condition or "not null" in group_condition: + self.__join_current(sql, checkrows + 2 ) + elif group_condition: + self.__join_current(sql, checkrows + 3 ) + else: + self.__join_current(sql, checkrows + 5 ) + if len(tblist) > 2 or len(tblist) < 1: + tdSql.error(sql=sql) + + def __join_current(self, sql, checkrows): + tdSql.query(sql=sql) + # tdSql.checkRows(checkrows) + + + def __test_current(self): + # sourcery skip: extract-duplicate-method, inline-immediately-returned-variable + tdLog.printNoPrefix("==========current sql condition check , must return query ok==========") + tblist_1 = ["ct1", "ct2"] + self.__join_check(tblist_1, 1) + tdLog.printNoPrefix(f"==========current sql condition check in {tblist_1} over==========") + tblist_2 = ["ct2", "ct4"] + self.__join_check(tblist_2, self.rows) + tdLog.printNoPrefix(f"==========current sql condition check in {tblist_2} over==========") + tblist_3 = ["t1", "ct4"] + self.__join_check(tblist_3, 1) + tdLog.printNoPrefix(f"==========current sql condition check in {tblist_3} over==========") + tblist_4 = ["t1", "ct1"] + self.__join_check(tblist_4, 1) + tdLog.printNoPrefix(f"==========current sql condition check in {tblist_4} over==========") + + def __test_error(self): + # sourcery skip: extract-duplicate-method, move-assign-in-block + tdLog.printNoPrefix("==========err sql condition check , must return error==========") + err_list_1 = ["ct1","ct2", "ct4"] + err_list_2 = ["ct1","ct2", "t1"] + err_list_3 = ["ct1","ct4", "t1"] + err_list_4 = ["ct2","ct4", "t1"] + err_list_5 = ["ct1", "ct2","ct4", "t1"] + self.__join_check(err_list_1, -1) + tdLog.printNoPrefix(f"==========err sql condition check in {err_list_1} over==========") + self.__join_check(err_list_2, -1) + tdLog.printNoPrefix(f"==========err sql condition check in {err_list_2} over==========") + self.__join_check(err_list_3, -1) + tdLog.printNoPrefix(f"==========err sql condition check in {err_list_3} over==========") + self.__join_check(err_list_4, -1) + tdLog.printNoPrefix(f"==========err sql condition check in {err_list_4} over==========") + self.__join_check(err_list_5, -1) + tdLog.printNoPrefix(f"==========err sql condition check in {err_list_5} over==========") + self.__join_check(["ct2", "ct4"], -1, join_flag=False) + tdLog.printNoPrefix("==========err sql condition check in has no join condition over==========") + + tdSql.error( f"select c1, c2 from ct2, ct4 where ct2.{PRIMARY_COL}=ct4.{PRIMARY_COL}" ) + tdSql.error( f"select ct2.c1, ct2.c2 from ct2, ct4 where ct2.{INT_COL}=ct4.{INT_COL}" ) + tdSql.error( f"select ct2.c1, ct2.c2 from ct2, ct4 where ct2.{TS_COL}=ct4.{TS_COL}" ) + tdSql.error( f"select ct2.c1, ct2.c2 from ct2, ct4 where ct2.{PRIMARY_COL}=ct4.{TS_COL}" ) + tdSql.error( f"select ct2.c1, ct1.c2 from ct2, ct4 where ct2.{PRIMARY_COL}=ct4.{PRIMARY_COL}" ) + tdSql.error( f"select ct2.c1, ct4.c2 from ct2, ct4 where ct2.{PRIMARY_COL}=ct4.{PRIMARY_COL} and c1 is not null " ) + tdSql.error( f"select ct2.c1, ct4.c2 from ct2, ct4 where ct2.{PRIMARY_COL}=ct4.{PRIMARY_COL} and ct1.c1 is not null " ) + + + tbname = ["ct1", "ct2", "ct4", "t1"] + + # for tb in tbname: + # for errsql in self.__join_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): + + 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} )') + { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2} + + def __insert_data(self, rows): + now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) + for i in range(rows): + tdSql.execute( + f"insert into ct1 values ( { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" + ) + tdSql.execute( + f"insert into ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" + ) + tdSql.execute( + f"insert into ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" + ) + tdSql.execute( + f'''insert into ct1 values + ( { now_time - rows * 5 }, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar_测试_0', { now_time + 8 } ) + ( { now_time + 10000 }, { rows }, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar_测试_9', { now_time + 9 } ) + ''' + ) + + tdSql.execute( + f'''insert into ct4 values + ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - rows * 3888000000 + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( + { now_time + 5184000000}, {pow(2,31)-pow(2,15)}, {pow(2,63)-pow(2,30)}, 32767, 127, + { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_测试_limit-1", { now_time - 86400000} + ) + ( + { now_time + 2592000000 }, {pow(2,31)-pow(2,16)}, {pow(2,63)-pow(2,31)}, 32766, 126, + { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_测试_limit-2", { now_time - 172800000} + ) + ''' + ) + + tdSql.execute( + f'''insert into ct2 values + ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - rows * 3888000000 + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( + { now_time + 5184000000 }, { -1 * pow(2,31) + pow(2,15) }, { -1 * pow(2,63) + pow(2,30) }, -32766, -126, + { -1 * 3.2 * pow(10,38) }, { -1.2 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_测试_limit-1", { now_time - 86400000 } + ) + ( + { now_time + 2592000000 }, { -1 * pow(2,31) + pow(2,16) }, { -1 * pow(2,63) + pow(2,31) }, -32767, -127, + { - 3.3 * pow(10,38) }, { -1.3 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_测试_limit-2", { now_time - 172800000 } + ) + ''' + ) + + for i in range(rows): + insert_data = f'''insert into t1 values + ( { now_time - i * 3600000 }, {i}, {i * 11111}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}, + "binary_{i}", "nchar_测试_{i}", { now_time - 1000 * i } ) + ''' + tdSql.execute(insert_data) + tdSql.execute( + f'''insert into t1 values + ( { now_time + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - (( rows // 2 ) * 60 + 30) * 60000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - rows * 3600000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time + 7200000 }, { pow(2,31) - pow(2,15) }, { pow(2,63) - pow(2,30) }, 32767, 127, + { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, + "binary_limit-1", "nchar_测试_limit-1", { now_time - 86400000 } + ) + ( + { now_time + 3600000 } , { pow(2,31) - pow(2,16) }, { pow(2,63) - pow(2,31) }, 32766, 126, + { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, + "binary_limit-2", "nchar_测试_limit-2", { now_time - 172800000 } + ) + ''' + ) + + + def run(self): + tdSql.prepare() + + tdLog.printNoPrefix("==========step1:create table") + self.__create_tb() + + tdLog.printNoPrefix("==========step2:insert data") + self.rows = 10 + self.__insert_data(self.rows) + + 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()) From 8c6da59e09e5ea150c04c2dd7c8051f913f5cd05 Mon Sep 17 00:00:00 2001 From: cpwu Date: Mon, 16 May 2022 14:17:19 +0800 Subject: [PATCH 02/20] fix case --- tests/system-test/2-query/union.py | 159 ++++++++++++++--------------- 1 file changed, 77 insertions(+), 82 deletions(-) diff --git a/tests/system-test/2-query/union.py b/tests/system-test/2-query/union.py index e45265d129..8754fb1eb5 100644 --- a/tests/system-test/2-query/union.py +++ b/tests/system-test/2-query/union.py @@ -37,6 +37,15 @@ class TDTestCase: ( f"{tbname}.{char_col}", f"upper( {tbname}.{char_col} )", + f"char_length( {tbname}.{char_col} )", + f"concat( {tbname}.{char_col}, {tbname}.{char_col} )", + f"concat_ws( '_', {tbname}.{char_col}, {tbname}.{char_col} )", + f"length( {tbname}.{char_col} )", + f"lower( {tbname}.{char_col} )", + f"ltrim( {tbname}.{char_col} )", + f"rtrim( {tbname}.{char_col} )", + f"substr( {tbname}.{char_col}, 1 )", + f"count( {tbname}.{char_col} )", ) ) query_condition.extend( f"cast( {tbname}.{un_char_col} as binary(16) ) " for un_char_col in NUM_COL) @@ -48,9 +57,21 @@ class TDTestCase: ( f"{tbname}.{num_col}", f"ceil( {tbname}.{num_col} )", + f"abs( {tbname}.{num_col} )", + f"acos( {tbname}.{num_col} )", + f"asin( {tbname}.{num_col} )", + f"atan( {tbname}.{num_col} )", + f"cos( {tbname}.{num_col} )", + f"floor( {tbname}.{num_col} )", + f"log( {tbname}.{num_col}, {tbname}.{num_col})", + f"sin( {tbname}.{num_col} )", + f"sqrt( {tbname}.{num_col} )", + f"tan( {tbname}.{num_col} )", + f"round( {tbname}.{num_col} )", + f"max( {tbname}.{num_col} )", f"sum( {tbname}.{num_col} )", f"count( {tbname}.{num_col} )", - f"sin( {tbname}.{num_col} )", + f"min( {tbname}.{num_col} )", ) ) query_condition.extend( f"{tbname}.{num_col} + {tbname}.{num_col_2}" for num_col_2 in NUM_COL ) @@ -148,90 +169,69 @@ class TDTestCase: return sqls - + def __get_type(self, col): + if tdSql.cursor.istype(col, "BOOL"): + return "BOOL" + if tdSql.cursor.istype(col, "INT"): + return "INT" + if tdSql.cursor.istype(col, "BIGINT"): + return "BIGINT" + if tdSql.cursor.istype(col, "TINYINT"): + return "TINYINT" + if tdSql.cursor.istype(col, "SMALLINT"): + return "SMALLINT" + if tdSql.cursor.istype(col, "FLOAT"): + return "FLOAT" + if tdSql.cursor.istype(col, "DOUBLE"): + return "DOUBLE" + if tdSql.cursor.istype(col, "BINARY"): + return "BINARY" + if tdSql.cursor.istype(col, "NCHAR"): + return "NCHAR" + if tdSql.cursor.istype(col, "TIMESTAMP"): + return "TIMESTAMP" + if tdSql.cursor.istype(col, "JSON"): + return "JSON" + if tdSql.cursor.istype(col, "TINYINT UNSIGNED"): + return "TINYINT UNSIGNED" + if tdSql.cursor.istype(col, "SMALLINT UNSIGNED"): + return "SMALLINT UNSIGNED" + if tdSql.cursor.istype(col, "INT UNSIGNED"): + return "INT UNSIGNED" + if tdSql.cursor.istype(col, "BIGINT UNSIGNED"): + return "BIGINT UNSIGNED" def union_check(self): sqls = self.sql_list() for sql1 in sqls: + tdSql.query(sql1) + res1_type = self.__get_type(0) for sql2 in sqls: - select_claus1 = sql1.split("from")[0].split("select")[1] - select_claus2 = sql2.split("from")[0].split("select")[1] + tdSql.query(sql2) + union_type = False + res2_type = self.__get_type(0) - pass + if res1_type in ( "BIGINT" , "NCHAR" ): + union_type = True + elif res2_type == res1_type: + union_type = True + elif res1_type == "TIMESAMP" and res2_type not in ("BINARY", "NCHAR"): + union_type = True + elif res1_type == "BINARY" and res2_type != "NCHAR": + union_type = True - def __join_check(self, tblist, checkrows, join_flag=True): - query_conditions = self.__query_condition(tblist[0]) - join_condition = self.__join_condition(tb_list=tblist) if join_flag else " " - for condition in query_conditions: - where_condition = self.__where_condition(col=condition, tbname=tblist[0]) - group_having = self.__group_condition(tbname=tblist[0], col=condition, having=f"{condition} is not null " ) - group_no_having= self.__group_condition(tbname=tblist[0], col=condition ) - groups = ["", group_having, group_no_having] - for group_condition in groups: - if where_condition: - sql = f" select {condition} from {tblist[0]},{tblist[1]} where {join_condition} and {where_condition} {group_condition} " + if union_type: + tdSql.query(f"{sql1} union {sql2}") + tdSql.query(f"{sql1} union all {sql2}") else: - sql = f" select {condition} from {tblist[0]},{tblist[1]} where {join_condition} {group_condition} " - - if not join_flag : - tdSql.error(sql=sql) - break - if len(tblist) == 2: - if "ct1" in tblist or "t1" in tblist: - self.__join_current(sql, checkrows) - elif where_condition or "not null" in group_condition: - self.__join_current(sql, checkrows + 2 ) - elif group_condition: - self.__join_current(sql, checkrows + 3 ) - else: - self.__join_current(sql, checkrows + 5 ) - if len(tblist) > 2 or len(tblist) < 1: - tdSql.error(sql=sql) - - def __join_current(self, sql, checkrows): - tdSql.query(sql=sql) - # tdSql.checkRows(checkrows) - - - def __test_current(self): - # sourcery skip: extract-duplicate-method, inline-immediately-returned-variable - tdLog.printNoPrefix("==========current sql condition check , must return query ok==========") - tblist_1 = ["ct1", "ct2"] - self.__join_check(tblist_1, 1) - tdLog.printNoPrefix(f"==========current sql condition check in {tblist_1} over==========") - tblist_2 = ["ct2", "ct4"] - self.__join_check(tblist_2, self.rows) - tdLog.printNoPrefix(f"==========current sql condition check in {tblist_2} over==========") - tblist_3 = ["t1", "ct4"] - self.__join_check(tblist_3, 1) - tdLog.printNoPrefix(f"==========current sql condition check in {tblist_3} over==========") - tblist_4 = ["t1", "ct1"] - self.__join_check(tblist_4, 1) - tdLog.printNoPrefix(f"==========current sql condition check in {tblist_4} over==========") + tdSql.error(f"{sql1} union {sql2}") def __test_error(self): - # sourcery skip: extract-duplicate-method, move-assign-in-block - tdLog.printNoPrefix("==========err sql condition check , must return error==========") - err_list_1 = ["ct1","ct2", "ct4"] - err_list_2 = ["ct1","ct2", "t1"] - err_list_3 = ["ct1","ct4", "t1"] - err_list_4 = ["ct2","ct4", "t1"] - err_list_5 = ["ct1", "ct2","ct4", "t1"] - self.__join_check(err_list_1, -1) - tdLog.printNoPrefix(f"==========err sql condition check in {err_list_1} over==========") - self.__join_check(err_list_2, -1) - tdLog.printNoPrefix(f"==========err sql condition check in {err_list_2} over==========") - self.__join_check(err_list_3, -1) - tdLog.printNoPrefix(f"==========err sql condition check in {err_list_3} over==========") - self.__join_check(err_list_4, -1) - tdLog.printNoPrefix(f"==========err sql condition check in {err_list_4} over==========") - self.__join_check(err_list_5, -1) - tdLog.printNoPrefix(f"==========err sql condition check in {err_list_5} over==========") - self.__join_check(["ct2", "ct4"], -1, join_flag=False) - tdLog.printNoPrefix("==========err sql condition check in has no join condition over==========") - tdSql.error( f"select c1, c2 from ct2, ct4 where ct2.{PRIMARY_COL}=ct4.{PRIMARY_COL}" ) - tdSql.error( f"select ct2.c1, ct2.c2 from ct2, ct4 where ct2.{INT_COL}=ct4.{INT_COL}" ) + + tdSql.error( "show tables union show tables" ) + tdSql.error( "create table errtb1 union all create table errtb2" ) + tdSql.error( "drop table ct1 union all drop table ct3" ) tdSql.error( f"select ct2.c1, ct2.c2 from ct2, ct4 where ct2.{TS_COL}=ct4.{TS_COL}" ) tdSql.error( f"select ct2.c1, ct2.c2 from ct2, ct4 where ct2.{PRIMARY_COL}=ct4.{TS_COL}" ) tdSql.error( f"select ct2.c1, ct1.c2 from ct2, ct4 where ct2.{PRIMARY_COL}=ct4.{PRIMARY_COL}" ) @@ -241,15 +241,10 @@ class TDTestCase: tbname = ["ct1", "ct2", "ct4", "t1"] - # for tb in tbname: - # for errsql in self.__join_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() + # self.__test_current() + # self.__test_error() + self.union_check() def __create_tb(self): From c58fd6ec63ee8c4f65cae9ac1d011d2b62ca3925 Mon Sep 17 00:00:00 2001 From: cpwu Date: Mon, 16 May 2022 14:25:47 +0800 Subject: [PATCH 03/20] fix case --- tests/system-test/2-query/union.py | 42 ++++++++++++++++-------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/tests/system-test/2-query/union.py b/tests/system-test/2-query/union.py index 8754fb1eb5..f252f2764e 100644 --- a/tests/system-test/2-query/union.py +++ b/tests/system-test/2-query/union.py @@ -142,30 +142,32 @@ class TDTestCase: __join_tblist = self.__join_tblist for join_tblist in __join_tblist: for join_tb in join_tblist: - select_claus = self.__query_condition(join_tb) - group_claus = self.__group_condition(tbname=join_tb, col=select_claus) - where_claus = self.__where_condition(query_conditon=select_claus) - having_claus = self.__group_condition(tbname=join_tb, col=select_claus, having=f"{select_claus} is not null") - sqls.extend( - ( - self.__single_sql(select_claus, join_tb, where_claus, group_claus), - self.__single_sql(select_claus, join_tb, where_claus, having_claus), - self.__single_sql(select_claus, self.__join_condition(join_tblist), where_claus, having_claus), - self.__single_sql(select_claus, self.__join_condition(join_tblist, INNER=True), where_claus, having_claus), + select_claus_list = self.__query_condition(join_tb) + for select_claus in select_claus_list: + group_claus = self.__group_condition(tbname=join_tb, col=select_claus) + where_claus = self.__where_condition(query_conditon=select_claus) + having_claus = self.__group_condition(tbname=join_tb, col=select_claus, having=f"{select_claus} is not null") + sqls.extend( + ( + self.__single_sql(select_claus, join_tb, where_claus, group_claus), + self.__single_sql(select_claus, join_tb, where_claus, having_claus), + self.__single_sql(select_claus, self.__join_condition(join_tblist), where_claus, having_claus), + self.__single_sql(select_claus, self.__join_condition(join_tblist, INNER=True), where_claus, having_claus), + ) ) - ) __no_join_tblist = self.__tb_liast for tb in __no_join_tblist: - select_claus = self.__query_condition(tb) - group_claus = self.__group_condition(tbname=tb, col=select_claus) - where_claus = self.__where_condition(query_conditon=select_claus) - having_claus = self.__group_condition(tbname=tb, col=select_claus, having=f"{select_claus} is not null") - sqls.extend( - ( - self.__single_sql(select_claus, join_tb, where_claus, group_claus), - self.__single_sql(select_claus, join_tb, where_claus, having_claus), + select_claus_list = self.__query_condition(tb) + for select_claus in select_claus_list: + group_claus = self.__group_condition(tbname=tb, col=select_claus) + where_claus = self.__where_condition(query_conditon=select_claus) + having_claus = self.__group_condition(tbname=tb, col=select_claus, having=f"{select_claus} is not null") + sqls.extend( + ( + self.__single_sql(select_claus, join_tb, where_claus, group_claus), + self.__single_sql(select_claus, join_tb, where_claus, having_claus), + ) ) - ) return sqls From eb72eadb7d654b5ac19df9082a7b3e96941f3dd2 Mon Sep 17 00:00:00 2001 From: cpwu Date: Mon, 16 May 2022 14:27:56 +0800 Subject: [PATCH 04/20] fix case --- tests/system-test/2-query/union.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/system-test/2-query/union.py b/tests/system-test/2-query/union.py index f252f2764e..2b3b710817 100644 --- a/tests/system-test/2-query/union.py +++ b/tests/system-test/2-query/union.py @@ -105,8 +105,8 @@ class TDTestCase: return "" - def __group_condition(self, tbname, col, having = None): - return f" group by {tbname}.{col} having {having}" if having else f" group by {tbname}.{col} " + def __group_condition(self, col, having = None): + return f" group by {col} having {having}" if having else f" group by {col} " def __single_sql(self, select_clause, from_clause, where_condition=None, group_condition=None): return f"select {select_clause} from {from_clause} {where_condition} {group_condition}" From 882b07f38d27a5cb46d749cac25e6366e9c67ffc Mon Sep 17 00:00:00 2001 From: cpwu Date: Mon, 16 May 2022 14:29:37 +0800 Subject: [PATCH 05/20] fix case --- tests/system-test/2-query/union.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/system-test/2-query/union.py b/tests/system-test/2-query/union.py index 2b3b710817..f48c200405 100644 --- a/tests/system-test/2-query/union.py +++ b/tests/system-test/2-query/union.py @@ -144,9 +144,9 @@ class TDTestCase: for join_tb in join_tblist: select_claus_list = self.__query_condition(join_tb) for select_claus in select_claus_list: - group_claus = self.__group_condition(tbname=join_tb, col=select_claus) + group_claus = self.__group_condition( col=select_claus) where_claus = self.__where_condition(query_conditon=select_claus) - having_claus = self.__group_condition(tbname=join_tb, col=select_claus, having=f"{select_claus} is not null") + having_claus = self.__group_condition( col=select_claus, having=f"{select_claus} is not null") sqls.extend( ( self.__single_sql(select_claus, join_tb, where_claus, group_claus), @@ -159,9 +159,9 @@ class TDTestCase: for tb in __no_join_tblist: select_claus_list = self.__query_condition(tb) for select_claus in select_claus_list: - group_claus = self.__group_condition(tbname=tb, col=select_claus) + group_claus = self.__group_condition(col=select_claus) where_claus = self.__where_condition(query_conditon=select_claus) - having_claus = self.__group_condition(tbname=tb, col=select_claus, having=f"{select_claus} is not null") + having_claus = self.__group_condition(col=select_claus, having=f"{select_claus} is not null") sqls.extend( ( self.__single_sql(select_claus, join_tb, where_claus, group_claus), From 0da873380a9e5bdb3f0aa3b7a5de448d6d327bbb Mon Sep 17 00:00:00 2001 From: cpwu Date: Mon, 16 May 2022 14:31:13 +0800 Subject: [PATCH 06/20] fix case --- tests/system-test/2-query/union.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system-test/2-query/union.py b/tests/system-test/2-query/union.py index f48c200405..fa63eda1c6 100644 --- a/tests/system-test/2-query/union.py +++ b/tests/system-test/2-query/union.py @@ -86,7 +86,7 @@ class TDTestCase: join_condition = table_reference join = "inner join" if INNER else "join" for i in range(len(tb_list[1:])): - join_condition += f"{join} {tb_list[i+1]} on {table_reference}.{filter}={tb_list[i+1]}.{filter}" + join_condition += f" {join} {tb_list[i+1]} on {table_reference}.{filter}={tb_list[i+1]}.{filter}" return join_condition From bef4a5371185d7f9b94f373a30414e8989548703 Mon Sep 17 00:00:00 2001 From: cpwu Date: Mon, 16 May 2022 16:29:25 +0800 Subject: [PATCH 07/20] fix case --- tests/system-test/2-query/union.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/system-test/2-query/union.py b/tests/system-test/2-query/union.py index fa63eda1c6..d5ab5ce315 100644 --- a/tests/system-test/2-query/union.py +++ b/tests/system-test/2-query/union.py @@ -106,6 +106,14 @@ class TDTestCase: def __group_condition(self, col, having = None): + if col.startswith("count"): + col = col.split("count(")[1].split(")") + if col.startswith("max"): + col = col.split("max(")[1].split(")") + if col.startswith("sum"): + col = col.split("sum(")[1].split(")") + if col.startswith("min"): + col = col.split("min(")[1].split(")") return f" group by {col} having {having}" if having else f" group by {col} " def __single_sql(self, select_clause, from_clause, where_condition=None, group_condition=None): From 0ba5d02b48187dee7d7f7d51c1137a944ad975d9 Mon Sep 17 00:00:00 2001 From: cpwu Date: Mon, 16 May 2022 16:36:28 +0800 Subject: [PATCH 08/20] fix case --- tests/system-test/2-query/union.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/system-test/2-query/union.py b/tests/system-test/2-query/union.py index d5ab5ce315..5ed7386360 100644 --- a/tests/system-test/2-query/union.py +++ b/tests/system-test/2-query/union.py @@ -108,11 +108,11 @@ class TDTestCase: def __group_condition(self, col, having = None): if col.startswith("count"): col = col.split("count(")[1].split(")") - if col.startswith("max"): + elif col.startswith("max"): col = col.split("max(")[1].split(")") - if col.startswith("sum"): + elif col.startswith("sum"): col = col.split("sum(")[1].split(")") - if col.startswith("min"): + elif col.startswith("min"): col = col.split("min(")[1].split(")") return f" group by {col} having {having}" if having else f" group by {col} " @@ -161,6 +161,11 @@ class TDTestCase: self.__single_sql(select_claus, join_tb, where_claus, having_claus), self.__single_sql(select_claus, self.__join_condition(join_tblist), where_claus, having_claus), self.__single_sql(select_claus, self.__join_condition(join_tblist, INNER=True), where_claus, having_claus), + self.__single_sql(select_claus, join_tb, where_claus), + self.__single_sql(select_claus, join_tb, having_claus), + self.__single_sql(select_claus, join_tb, group_claus), + self.__single_sql(select_claus, join_tb), + ) ) __no_join_tblist = self.__tb_liast @@ -174,6 +179,10 @@ class TDTestCase: ( self.__single_sql(select_claus, join_tb, where_claus, group_claus), self.__single_sql(select_claus, join_tb, where_claus, having_claus), + self.__single_sql(select_claus, join_tb, where_claus), + self.__single_sql(select_claus, join_tb, group_claus), + self.__single_sql(select_claus, join_tb, having_claus), + self.__single_sql(select_claus, join_tb), ) ) From 467038762df555f372695e5703a4e63631865945 Mon Sep 17 00:00:00 2001 From: cpwu Date: Mon, 16 May 2022 16:39:06 +0800 Subject: [PATCH 09/20] fix case --- tests/system-test/2-query/union.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/system-test/2-query/union.py b/tests/system-test/2-query/union.py index 5ed7386360..36ad5489dc 100644 --- a/tests/system-test/2-query/union.py +++ b/tests/system-test/2-query/union.py @@ -116,7 +116,7 @@ class TDTestCase: col = col.split("min(")[1].split(")") return f" group by {col} having {having}" if having else f" group by {col} " - def __single_sql(self, select_clause, from_clause, where_condition=None, group_condition=None): + def __single_sql(self, select_clause, from_clause, where_condition="", group_condition=""): return f"select {select_clause} from {from_clause} {where_condition} {group_condition}" @@ -241,7 +241,9 @@ class TDTestCase: if union_type: tdSql.query(f"{sql1} union {sql2}") + tdSql.checkCols(1) tdSql.query(f"{sql1} union all {sql2}") + tdSql.checkCols(1) else: tdSql.error(f"{sql1} union {sql2}") From 42c7f2a29c087245b9c8846ecca4a6b32f2ad46c Mon Sep 17 00:00:00 2001 From: cpwu Date: Mon, 16 May 2022 16:45:07 +0800 Subject: [PATCH 10/20] fix case --- tests/system-test/2-query/union.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/system-test/2-query/union.py b/tests/system-test/2-query/union.py index 36ad5489dc..e54aac0f64 100644 --- a/tests/system-test/2-query/union.py +++ b/tests/system-test/2-query/union.py @@ -107,13 +107,13 @@ class TDTestCase: def __group_condition(self, col, having = None): if col.startswith("count"): - col = col.split("count(")[1].split(")") + col = col[6:-1] elif col.startswith("max"): - col = col.split("max(")[1].split(")") + col = col[4:-1] elif col.startswith("sum"): - col = col.split("sum(")[1].split(")") + col = col[4:-1] elif col.startswith("min"): - col = col.split("min(")[1].split(")") + col = col[4:-1] return f" group by {col} having {having}" if having else f" group by {col} " def __single_sql(self, select_clause, from_clause, where_condition="", group_condition=""): From 3cbe435e92e91feeae7bbd6835e68be0566942a9 Mon Sep 17 00:00:00 2001 From: cpwu Date: Mon, 16 May 2022 16:47:30 +0800 Subject: [PATCH 11/20] fix case --- tests/system-test/2-query/union.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/system-test/2-query/union.py b/tests/system-test/2-query/union.py index e54aac0f64..5b2994948f 100644 --- a/tests/system-test/2-query/union.py +++ b/tests/system-test/2-query/union.py @@ -91,6 +91,15 @@ class TDTestCase: return join_condition def __where_condition(self, col=None, tbname=None, query_conditon=None): + if col.startswith("count"): + col = col[6:-1] + elif col.startswith("max"): + col = col[4:-1] + elif col.startswith("sum"): + col = col[4:-1] + elif col.startswith("min"): + col = col[4:-1] + if query_conditon: return f" where {query_conditon} is not null" if col in NUM_COL: From 5e199efc05e1312b5532ee029db2b07eba1636d2 Mon Sep 17 00:00:00 2001 From: cpwu Date: Mon, 16 May 2022 16:50:59 +0800 Subject: [PATCH 12/20] fix case --- tests/system-test/2-query/union.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/system-test/2-query/union.py b/tests/system-test/2-query/union.py index 5b2994948f..a03a114ced 100644 --- a/tests/system-test/2-query/union.py +++ b/tests/system-test/2-query/union.py @@ -91,14 +91,16 @@ class TDTestCase: return join_condition def __where_condition(self, col=None, tbname=None, query_conditon=None): - if col.startswith("count"): - col = col[6:-1] - elif col.startswith("max"): - col = col[4:-1] - elif col.startswith("sum"): - col = col[4:-1] - elif col.startswith("min"): - col = col[4:-1] + if query_conditon: + if query_conditon.startswith("count"): + query_conditon = query_conditon[6:-1] + elif query_conditon.startswith("max"): + query_conditon = query_conditon[4:-1] + elif query_conditon.startswith("sum"): + query_conditon = query_conditon[4:-1] + elif query_conditon.startswith("min"): + query_conditon = query_conditon[4:-1] + if query_conditon: return f" where {query_conditon} is not null" From 6609a4afa19f57c6c2190e195f579e98eca7f9f3 Mon Sep 17 00:00:00 2001 From: cpwu Date: Mon, 16 May 2022 18:15:33 +0800 Subject: [PATCH 13/20] fix case --- tests/system-test/2-query/union.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/system-test/2-query/union.py b/tests/system-test/2-query/union.py index a03a114ced..5b3e27affa 100644 --- a/tests/system-test/2-query/union.py +++ b/tests/system-test/2-query/union.py @@ -46,6 +46,8 @@ class TDTestCase: f"rtrim( {tbname}.{char_col} )", f"substr( {tbname}.{char_col}, 1 )", f"count( {tbname}.{char_col} )", + f"cast( {tbname}.{char_col} as nchar(3) )", + f"cast( {tbname}.{char_col} as nchar(8) )", ) ) query_condition.extend( f"cast( {tbname}.{un_char_col} as binary(16) ) " for un_char_col in NUM_COL) @@ -128,6 +130,8 @@ class TDTestCase: return f" group by {col} having {having}" if having else f" group by {col} " def __single_sql(self, select_clause, from_clause, where_condition="", group_condition=""): + if "on" not in from_clause and select_clause.split(".")[0] != from_clause.split(".")[0]: + return return f"select {select_clause} from {from_clause} {where_condition} {group_condition}" From 507318f4238732505ab6000a0d9c9d4b6dd64719 Mon Sep 17 00:00:00 2001 From: cpwu Date: Mon, 16 May 2022 18:23:50 +0800 Subject: [PATCH 14/20] fix case --- tests/system-test/2-query/union.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system-test/2-query/union.py b/tests/system-test/2-query/union.py index 5b3e27affa..97647b8549 100644 --- a/tests/system-test/2-query/union.py +++ b/tests/system-test/2-query/union.py @@ -201,7 +201,7 @@ class TDTestCase: ) ) - return sqls + return filter(None, sqls) def __get_type(self, col): if tdSql.cursor.istype(col, "BOOL"): From ed76cad0789249cf5deee1e13deed823f9f0d567 Mon Sep 17 00:00:00 2001 From: cpwu Date: Mon, 16 May 2022 18:40:32 +0800 Subject: [PATCH 15/20] add union case --- tests/system-test/2-query/union.py | 71 ++++++++++++++++-------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/tests/system-test/2-query/union.py b/tests/system-test/2-query/union.py index 97647b8549..59434e3f2d 100644 --- a/tests/system-test/2-query/union.py +++ b/tests/system-test/2-query/union.py @@ -36,40 +36,40 @@ class TDTestCase: query_condition.extend( ( f"{tbname}.{char_col}", - f"upper( {tbname}.{char_col} )", - f"char_length( {tbname}.{char_col} )", - f"concat( {tbname}.{char_col}, {tbname}.{char_col} )", - f"concat_ws( '_', {tbname}.{char_col}, {tbname}.{char_col} )", - f"length( {tbname}.{char_col} )", - f"lower( {tbname}.{char_col} )", - f"ltrim( {tbname}.{char_col} )", - f"rtrim( {tbname}.{char_col} )", - f"substr( {tbname}.{char_col}, 1 )", - f"count( {tbname}.{char_col} )", + # f"upper( {tbname}.{char_col} )", + # f"char_length( {tbname}.{char_col} )", + # f"concat( {tbname}.{char_col}, {tbname}.{char_col} )", + # f"concat_ws( '_', {tbname}.{char_col}, {tbname}.{char_col} )", + # f"length( {tbname}.{char_col} )", + # f"lower( {tbname}.{char_col} )", + # f"ltrim( {tbname}.{char_col} )", + # f"rtrim( {tbname}.{char_col} )", + # f"substr( {tbname}.{char_col}, 1 )", + # f"count( {tbname}.{char_col} )", f"cast( {tbname}.{char_col} as nchar(3) )", f"cast( {tbname}.{char_col} as nchar(8) )", ) ) - query_condition.extend( f"cast( {tbname}.{un_char_col} as binary(16) ) " for un_char_col in NUM_COL) - query_condition.extend( f"cast( {tbname}.{char_col} + {tbname}.{char_col_2} as binary(32) ) " for char_col_2 in CHAR_COL ) - query_condition.extend( f"cast( {tbname}.{char_col} + {tbname}.{un_char_col} as binary(32) ) " for un_char_col in NUM_COL ) + # query_condition.extend( f"cast( {tbname}.{un_char_col} as binary(16) ) " for un_char_col in NUM_COL) + # query_condition.extend( f"cast( {tbname}.{char_col} + {tbname}.{char_col_2} as binary(32) ) " for char_col_2 in CHAR_COL ) + # query_condition.extend( f"cast( {tbname}.{char_col} + {tbname}.{un_char_col} as binary(32) ) " for un_char_col in NUM_COL ) for num_col in NUM_COL: query_condition.extend( ( f"{tbname}.{num_col}", - f"ceil( {tbname}.{num_col} )", - f"abs( {tbname}.{num_col} )", - f"acos( {tbname}.{num_col} )", - f"asin( {tbname}.{num_col} )", - f"atan( {tbname}.{num_col} )", - f"cos( {tbname}.{num_col} )", - f"floor( {tbname}.{num_col} )", - f"log( {tbname}.{num_col}, {tbname}.{num_col})", - f"sin( {tbname}.{num_col} )", - f"sqrt( {tbname}.{num_col} )", - f"tan( {tbname}.{num_col} )", - f"round( {tbname}.{num_col} )", + # f"ceil( {tbname}.{num_col} )", + # f"abs( {tbname}.{num_col} )", + # f"acos( {tbname}.{num_col} )", + # f"asin( {tbname}.{num_col} )", + # f"atan( {tbname}.{num_col} )", + # f"cos( {tbname}.{num_col} )", + # f"floor( {tbname}.{num_col} )", + # f"log( {tbname}.{num_col}, {tbname}.{num_col})", + # f"sin( {tbname}.{num_col} )", + # f"sqrt( {tbname}.{num_col} )", + # f"tan( {tbname}.{num_col} )", + # f"round( {tbname}.{num_col} )", f"max( {tbname}.{num_col} )", f"sum( {tbname}.{num_col} )", f"count( {tbname}.{num_col} )", @@ -79,7 +79,13 @@ class TDTestCase: query_condition.extend( f"{tbname}.{num_col} + {tbname}.{num_col_2}" for num_col_2 in NUM_COL ) query_condition.extend( f"{tbname}.{num_col} + {tbname}.{char_col} " for char_col in CHAR_COL ) - query_condition.append(''' "test1234!@#$%^&*():'> Date: Mon, 16 May 2022 18:44:40 +0800 Subject: [PATCH 16/20] fix case --- tests/system-test/2-query/union.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/system-test/2-query/union.py b/tests/system-test/2-query/union.py index 59434e3f2d..a379584a8c 100644 --- a/tests/system-test/2-query/union.py +++ b/tests/system-test/2-query/union.py @@ -99,7 +99,7 @@ class TDTestCase: return join_condition def __where_condition(self, col=None, tbname=None, query_conditon=None): - if query_conditon: + if query_conditon and isinstance(query_conditon, str): if query_conditon.startswith("count"): query_conditon = query_conditon[6:-1] elif query_conditon.startswith("max"): @@ -125,14 +125,15 @@ class TDTestCase: def __group_condition(self, col, having = None): - if col.startswith("count"): - col = col[6:-1] - elif col.startswith("max"): - col = col[4:-1] - elif col.startswith("sum"): - col = col[4:-1] - elif col.startswith("min"): - col = col[4:-1] + if isinstance(col, str): + if col.startswith("count"): + col = col[6:-1] + elif col.startswith("max"): + col = col[4:-1] + elif col.startswith("sum"): + col = col[4:-1] + elif col.startswith("min"): + col = col[4:-1] return f" group by {col} having {having}" if having else f" group by {col} " def __single_sql(self, select_clause, from_clause, where_condition="", group_condition=""): From 43a8a55a5bf3dfac00ed3adf1c7ca1d36df2e154 Mon Sep 17 00:00:00 2001 From: cpwu Date: Mon, 16 May 2022 18:46:48 +0800 Subject: [PATCH 17/20] fix case --- tests/system-test/2-query/union.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system-test/2-query/union.py b/tests/system-test/2-query/union.py index a379584a8c..408815c9b6 100644 --- a/tests/system-test/2-query/union.py +++ b/tests/system-test/2-query/union.py @@ -137,7 +137,7 @@ class TDTestCase: return f" group by {col} having {having}" if having else f" group by {col} " def __single_sql(self, select_clause, from_clause, where_condition="", group_condition=""): - if "on" not in from_clause and select_clause.split(".")[0] != from_clause.split(".")[0]: + if isinstance(select_clause, str) and "on" not in from_clause and select_clause.split(".")[0] != from_clause.split(".")[0]: return return f"select {select_clause} from {from_clause} {where_condition} {group_condition}" From 7e87795daded6ad974b4689e28f95c690b0647dd Mon Sep 17 00:00:00 2001 From: cpwu Date: Mon, 16 May 2022 19:14:23 +0800 Subject: [PATCH 18/20] add case --- tests/system-test/2-query/union.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/tests/system-test/2-query/union.py b/tests/system-test/2-query/union.py index 408815c9b6..67b3479f5e 100644 --- a/tests/system-test/2-query/union.py +++ b/tests/system-test/2-query/union.py @@ -76,14 +76,14 @@ class TDTestCase: f"min( {tbname}.{num_col} )", ) ) - query_condition.extend( f"{tbname}.{num_col} + {tbname}.{num_col_2}" for num_col_2 in NUM_COL ) - query_condition.extend( f"{tbname}.{num_col} + {tbname}.{char_col} " for char_col in CHAR_COL ) + # query_condition.extend( f"{tbname}.{num_col} + {tbname}.{num_col_2}" for num_col_2 in NUM_COL ) + # query_condition.extend( f"{tbname}.{num_col} + {tbname}.{char_col} " for char_col in CHAR_COL ) query_condition.extend( ( # ''' "test1234!@#$%^&*():'> Date: Mon, 16 May 2022 19:27:10 +0800 Subject: [PATCH 19/20] fix case --- tests/system-test/2-query/union.py | 62 +++++++++++++++--------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/tests/system-test/2-query/union.py b/tests/system-test/2-query/union.py index 67b3479f5e..af1779e1e3 100644 --- a/tests/system-test/2-query/union.py +++ b/tests/system-test/2-query/union.py @@ -36,54 +36,54 @@ class TDTestCase: query_condition.extend( ( f"{tbname}.{char_col}", - # f"upper( {tbname}.{char_col} )", - # f"char_length( {tbname}.{char_col} )", - # f"concat( {tbname}.{char_col}, {tbname}.{char_col} )", - # f"concat_ws( '_', {tbname}.{char_col}, {tbname}.{char_col} )", - # f"length( {tbname}.{char_col} )", - # f"lower( {tbname}.{char_col} )", - # f"ltrim( {tbname}.{char_col} )", - # f"rtrim( {tbname}.{char_col} )", - # f"substr( {tbname}.{char_col}, 1 )", - # f"count( {tbname}.{char_col} )", + f"upper( {tbname}.{char_col} )", + f"char_length( {tbname}.{char_col} )", + f"concat( {tbname}.{char_col}, {tbname}.{char_col} )", + f"concat_ws( '_', {tbname}.{char_col}, {tbname}.{char_col} )", + f"length( {tbname}.{char_col} )", + f"lower( {tbname}.{char_col} )", + f"ltrim( {tbname}.{char_col} )", + f"rtrim( {tbname}.{char_col} )", + f"substr( {tbname}.{char_col}, 1 )", + f"count( {tbname}.{char_col} )", f"cast( {tbname}.{char_col} as nchar(3) )", f"cast( {tbname}.{char_col} as nchar(8) )", ) ) - # query_condition.extend( f"cast( {tbname}.{un_char_col} as binary(16) ) " for un_char_col in NUM_COL) - # query_condition.extend( f"cast( {tbname}.{char_col} + {tbname}.{char_col_2} as binary(32) ) " for char_col_2 in CHAR_COL ) - # query_condition.extend( f"cast( {tbname}.{char_col} + {tbname}.{un_char_col} as binary(32) ) " for un_char_col in NUM_COL ) + query_condition.extend( f"cast( {tbname}.{un_char_col} as binary(16) ) " for un_char_col in NUM_COL) + query_condition.extend( f"cast( {tbname}.{char_col} + {tbname}.{char_col_2} as binary(32) ) " for char_col_2 in CHAR_COL ) + query_condition.extend( f"cast( {tbname}.{char_col} + {tbname}.{un_char_col} as binary(32) ) " for un_char_col in NUM_COL ) for num_col in NUM_COL: query_condition.extend( ( f"{tbname}.{num_col}", - # f"ceil( {tbname}.{num_col} )", - # f"abs( {tbname}.{num_col} )", - # f"acos( {tbname}.{num_col} )", - # f"asin( {tbname}.{num_col} )", - # f"atan( {tbname}.{num_col} )", - # f"cos( {tbname}.{num_col} )", - # f"floor( {tbname}.{num_col} )", - # f"log( {tbname}.{num_col}, {tbname}.{num_col})", - # f"sin( {tbname}.{num_col} )", - # f"sqrt( {tbname}.{num_col} )", - # f"tan( {tbname}.{num_col} )", - # f"round( {tbname}.{num_col} )", + f"ceil( {tbname}.{num_col} )", + f"abs( {tbname}.{num_col} )", + f"acos( {tbname}.{num_col} )", + f"asin( {tbname}.{num_col} )", + f"atan( {tbname}.{num_col} )", + f"cos( {tbname}.{num_col} )", + f"floor( {tbname}.{num_col} )", + f"log( {tbname}.{num_col}, {tbname}.{num_col})", + f"sin( {tbname}.{num_col} )", + f"sqrt( {tbname}.{num_col} )", + f"tan( {tbname}.{num_col} )", + f"round( {tbname}.{num_col} )", f"max( {tbname}.{num_col} )", f"sum( {tbname}.{num_col} )", f"count( {tbname}.{num_col} )", f"min( {tbname}.{num_col} )", ) ) - # query_condition.extend( f"{tbname}.{num_col} + {tbname}.{num_col_2}" for num_col_2 in NUM_COL ) - # query_condition.extend( f"{tbname}.{num_col} + {tbname}.{char_col} " for char_col in CHAR_COL ) + query_condition.extend( f"{tbname}.{num_col} + {tbname}.{num_col_2}" for num_col_2 in NUM_COL ) + query_condition.extend( f"{tbname}.{num_col} + {tbname}.{char_col} " for char_col in CHAR_COL ) query_condition.extend( ( - # ''' "test1234!@#$%^&*():'> Date: Mon, 16 May 2022 19:41:44 +0800 Subject: [PATCH 20/20] fix case --- tests/system-test/2-query/union.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system-test/2-query/union.py b/tests/system-test/2-query/union.py index af1779e1e3..5b0099c6eb 100644 --- a/tests/system-test/2-query/union.py +++ b/tests/system-test/2-query/union.py @@ -83,7 +83,7 @@ class TDTestCase: ( ''' "test1234!@#$%^&*():'>