fix case
This commit is contained in:
parent
a7844ce6ec
commit
eec9f5889b
|
@ -55,35 +55,118 @@ class TDTestCase:
|
||||||
|
|
||||||
return query_condition
|
return query_condition
|
||||||
|
|
||||||
def __join_condition(self, tb_list, filter=PRIMARY_COL):
|
def __join_condition(self, tb_list, filter=PRIMARY_COL, INNER=False):
|
||||||
# sourcery skip: flip-comparison
|
table_reference = tb_list[0]
|
||||||
if 1 == len(tb_list):
|
join_condition = table_reference
|
||||||
join_filter = f"{tb_list[0]}.{filter} = {tb_list[0]}.{filter} "
|
join = "inner join" if INNER else "join"
|
||||||
elif 2 == len(tb_list):
|
for i in range(len(tb_list[1:])):
|
||||||
join_filter = f"{tb_list[0]}.{filter} = {tb_list[1]}.{filter} "
|
join_condition += f" {join} {tb_list[i+1]} on {table_reference}.{filter}={tb_list[i+1]}.{filter}"
|
||||||
else:
|
|
||||||
join_filter = f"{tb_list[0]}.{filter} = {tb_list[1]}.{filter} "
|
|
||||||
for i in range(1, len(tb_list)-1 ):
|
|
||||||
join_filter += f"and {tb_list[i]}.{filter} = {tb_list[i+1]}.{filter}"
|
|
||||||
|
|
||||||
return join_filter
|
return join_condition
|
||||||
|
|
||||||
def __where_condition(self, col, tbname):
|
# def __join_condition(self, tb_list, filter=PRIMARY_COL):
|
||||||
|
# # sourcery skip: flip-comparison
|
||||||
|
# if 1 == len(tb_list):
|
||||||
|
# join_filter = f"{tb_list[0]}.{filter} = {tb_list[0]}.{filter} "
|
||||||
|
# elif 2 == len(tb_list):
|
||||||
|
# join_filter = f"{tb_list[0]}.{filter} = {tb_list[1]}.{filter} "
|
||||||
|
# else:
|
||||||
|
# join_filter = f"{tb_list[0]}.{filter} = {tb_list[1]}.{filter} "
|
||||||
|
# for i in range(1, len(tb_list)-1 ):
|
||||||
|
# join_filter += f"and {tb_list[i]}.{filter} = {tb_list[i+1]}.{filter}"
|
||||||
|
|
||||||
|
# return join_filter
|
||||||
|
|
||||||
|
def __where_condition(self, col=None, tbname=None, query_conditon=None):
|
||||||
|
if query_conditon and isinstance(query_conditon, str):
|
||||||
|
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"
|
||||||
if col in NUM_COL:
|
if col in NUM_COL:
|
||||||
return f" abs( {tbname}.{col} ) >= 0"
|
return f" where abs( {tbname}.{col} ) >= 0"
|
||||||
elif col in CHAR_COL:
|
if col in CHAR_COL:
|
||||||
return f" lower( {tbname}.{col} ) like 'bina%' or lower( {tbname}.{col} ) like '_cha%' "
|
return f" where lower( {tbname}.{col} ) like 'bina%' or lower( {tbname}.{col} ) like '_cha%' "
|
||||||
elif col in BOOLEAN_COL:
|
if col in BOOLEAN_COL:
|
||||||
return f" {tbname}.{col} in (false, true) "
|
return f" where {tbname}.{col} in (false, true) "
|
||||||
elif col in TS_TYPE_COL or col in PRIMARY_COL:
|
if col in TS_TYPE_COL or col in PRIMARY_COL:
|
||||||
return f" cast( {tbname}.{col} as binary(16) ) is not null "
|
return f" where cast( {tbname}.{col} as binary(16) ) is not null "
|
||||||
else:
|
|
||||||
return ""
|
|
||||||
|
|
||||||
def __group_condition(self, tbname, col, having = ""):
|
return ""
|
||||||
|
|
||||||
|
def __group_condition(self, col, having = None):
|
||||||
|
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} "
|
return f" group by {col} having {having}" if having else f" group by {col} "
|
||||||
|
|
||||||
def __join_check(self, tblist, checkrows, join_flag=True):
|
def __gen_sql(self, select_clause, from_clause, where_condition="", group_condition=""):
|
||||||
|
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}"
|
||||||
|
|
||||||
|
@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 __sqls_list(self):
|
||||||
|
sqls = []
|
||||||
|
__join_tblist = self.__join_tblist
|
||||||
|
for join_tblist in __join_tblist:
|
||||||
|
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( col=select_claus)
|
||||||
|
where_claus = self.__where_condition( query_conditon=select_claus )
|
||||||
|
having_claus = self.__group_condition( col=select_claus, having=f"{select_claus} is not null" )
|
||||||
|
sqls.extend(
|
||||||
|
(
|
||||||
|
self.__gen_sql(select_claus, self.__join_condition(join_tblist), where_claus, group_claus),
|
||||||
|
self.__gen_sql(select_claus, self.__join_condition(join_tblist), where_claus, having_claus),
|
||||||
|
self.__gen_sql(select_claus, self.__join_condition(join_tblist), where_claus),
|
||||||
|
self.__gen_sql(select_claus, self.__join_condition(join_tblist), group_claus),
|
||||||
|
self.__gen_sql(select_claus, self.__join_condition(join_tblist), having_claus),
|
||||||
|
self.__gen_sql(select_claus, self.__join_condition(join_tblist)),
|
||||||
|
self.__gen_sql(select_claus, self.__join_condition(join_tblist, INNER=True), where_claus, group_claus),
|
||||||
|
self.__gen_sql(select_claus, self.__join_condition(join_tblist, INNER=True), where_claus, having_claus),
|
||||||
|
self.__gen_sql(select_claus, self.__join_condition(join_tblist, INNER=True), where_claus, ),
|
||||||
|
self.__gen_sql(select_claus, self.__join_condition(join_tblist, INNER=True), having_claus ),
|
||||||
|
self.__gen_sql(select_claus, self.__join_condition(join_tblist, INNER=True), group_claus ),
|
||||||
|
self.__gen_sql(select_claus, self.__join_condition(join_tblist, INNER=True), ),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def __join_check(self,):
|
||||||
|
for sql in self.__sqls_list:
|
||||||
|
tdSql.query(sql)
|
||||||
|
|
||||||
|
def __join_check_old(self, tblist, checkrows, join_flag=True):
|
||||||
query_conditions = self.__query_condition(tblist[0])
|
query_conditions = self.__query_condition(tblist[0])
|
||||||
join_condition = self.__join_condition(tb_list=tblist) if join_flag else " "
|
join_condition = self.__join_condition(tb_list=tblist) if join_flag else " "
|
||||||
for condition in query_conditions:
|
for condition in query_conditions:
|
||||||
|
@ -141,17 +224,17 @@ class TDTestCase:
|
||||||
err_list_3 = ["ct1","ct4", "t1"]
|
err_list_3 = ["ct1","ct4", "t1"]
|
||||||
err_list_4 = ["ct2","ct4", "t1"]
|
err_list_4 = ["ct2","ct4", "t1"]
|
||||||
err_list_5 = ["ct1", "ct2","ct4", "t1"]
|
err_list_5 = ["ct1", "ct2","ct4", "t1"]
|
||||||
self.__join_check(err_list_1, -1)
|
self.__join_check_old(err_list_1, -1)
|
||||||
tdLog.printNoPrefix(f"==========err sql condition check in {err_list_1} over==========")
|
tdLog.printNoPrefix(f"==========err sql condition check in {err_list_1} over==========")
|
||||||
self.__join_check(err_list_2, -1)
|
self.__join_check_old(err_list_2, -1)
|
||||||
tdLog.printNoPrefix(f"==========err sql condition check in {err_list_2} over==========")
|
tdLog.printNoPrefix(f"==========err sql condition check in {err_list_2} over==========")
|
||||||
self.__join_check(err_list_3, -1)
|
self.__join_check_old(err_list_3, -1)
|
||||||
tdLog.printNoPrefix(f"==========err sql condition check in {err_list_3} over==========")
|
tdLog.printNoPrefix(f"==========err sql condition check in {err_list_3} over==========")
|
||||||
self.__join_check(err_list_4, -1)
|
self.__join_check_old(err_list_4, -1)
|
||||||
tdLog.printNoPrefix(f"==========err sql condition check in {err_list_4} over==========")
|
tdLog.printNoPrefix(f"==========err sql condition check in {err_list_4} over==========")
|
||||||
self.__join_check(err_list_5, -1)
|
self.__join_check_old(err_list_5, -1)
|
||||||
tdLog.printNoPrefix(f"==========err sql condition check in {err_list_5} over==========")
|
tdLog.printNoPrefix(f"==========err sql condition check in {err_list_5} over==========")
|
||||||
self.__join_check(["ct2", "ct4"], -1, join_flag=False)
|
self.__join_check_old(["ct2", "ct4"], -1, join_flag=False)
|
||||||
tdLog.printNoPrefix("==========err sql condition check in has no join condition over==========")
|
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 c1, c2 from ct2, ct4 where ct2.{PRIMARY_COL}=ct4.{PRIMARY_COL}" )
|
||||||
|
@ -172,7 +255,7 @@ class TDTestCase:
|
||||||
|
|
||||||
|
|
||||||
def all_test(self):
|
def all_test(self):
|
||||||
self.__test_current()
|
self.__join_check()
|
||||||
self.__test_error()
|
self.__test_error()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,6 @@ class TDTestCase:
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def __group_condition(self, col, having = None):
|
def __group_condition(self, col, having = None):
|
||||||
if isinstance(col, str):
|
if isinstance(col, str):
|
||||||
if col.startswith("count"):
|
if col.startswith("count"):
|
||||||
|
@ -114,7 +113,6 @@ class TDTestCase:
|
||||||
return
|
return
|
||||||
return f"select {select_clause} from {from_clause} {where_condition} {group_condition}"
|
return f"select {select_clause} from {from_clause} {where_condition} {group_condition}"
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def __join_tblist(self):
|
def __join_tblist(self):
|
||||||
return [
|
return [
|
||||||
|
@ -222,6 +220,8 @@ class TDTestCase:
|
||||||
tdSql.query(sqls[i])
|
tdSql.query(sqls[i])
|
||||||
res1_type = self.__get_type(0)
|
res1_type = self.__get_type(0)
|
||||||
for j in range(len(sqls[i:])):
|
for j in range(len(sqls[i:])):
|
||||||
|
if j % 100 == 0:
|
||||||
|
tdLog.success(f"{i} : {j} sql is already executed!")
|
||||||
tdSql.query(sqls[j+i])
|
tdSql.query(sqls[j+i])
|
||||||
order_union_type = False
|
order_union_type = False
|
||||||
rev_order_type = False
|
rev_order_type = False
|
||||||
|
@ -246,22 +246,12 @@ class TDTestCase:
|
||||||
rev_order_type = True
|
rev_order_type = True
|
||||||
|
|
||||||
if all_union_type:
|
if all_union_type:
|
||||||
tdSql.query(f"{sqls[i]} union {sqls[j+i]}")
|
tdSql.execute(f"{sqls[i]} union {sqls[j+i]}")
|
||||||
tdSql.query(f"{sqls[j+i]} union {sqls[i]}")
|
tdSql.execute(f"{sqls[j+i]} union all {sqls[i]}")
|
||||||
tdSql.checkCols(1)
|
|
||||||
tdSql.query(f"{sqls[i]} union all {sqls[j+i]}")
|
|
||||||
tdSql.query(f"{sqls[j+i]} union all {sqls[i]}")
|
|
||||||
tdSql.checkCols(1)
|
|
||||||
elif order_union_type:
|
elif order_union_type:
|
||||||
tdSql.query(f"{sqls[i]} union {sqls[j+i]}")
|
tdSql.execute(f"{sqls[i]} union all {sqls[j+i]}")
|
||||||
tdSql.checkCols(1)
|
|
||||||
tdSql.query(f"{sqls[i]} union all {sqls[j+i]}")
|
|
||||||
tdSql.checkCols(1)
|
|
||||||
elif rev_order_type:
|
elif rev_order_type:
|
||||||
tdSql.query(f"{sqls[j+i]} union {sqls[i]}")
|
tdSql.execute(f"{sqls[j+i]} union {sqls[i]}")
|
||||||
tdSql.checkCols(1)
|
|
||||||
tdSql.query(f"{sqls[j+i]} union all {sqls[i]}")
|
|
||||||
tdSql.checkCols(1)
|
|
||||||
else:
|
else:
|
||||||
tdSql.error(f"{sqls[i]} union {sqls[j+i]}")
|
tdSql.error(f"{sqls[i]} union {sqls[j+i]}")
|
||||||
|
|
||||||
|
@ -273,7 +263,7 @@ class TDTestCase:
|
||||||
tdSql.error( "select c1 from ct1 union all drop table ct3" )
|
tdSql.error( "select c1 from ct1 union all drop table ct3" )
|
||||||
tdSql.error( "select c1 from ct1 union all '' " )
|
tdSql.error( "select c1 from ct1 union all '' " )
|
||||||
tdSql.error( " '' union all select c1 from ct1 " )
|
tdSql.error( " '' union all select c1 from ct1 " )
|
||||||
tdSql.error( "select c1 from ct1 union select c1 from ct2 union select c1 from ct4 ")
|
# tdSql.error( "select c1 from ct1 union select c1 from ct2 union select c1 from ct4 ")
|
||||||
|
|
||||||
def all_test(self):
|
def all_test(self):
|
||||||
self.__test_error()
|
self.__test_error()
|
||||||
|
|
Loading…
Reference in New Issue