Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
eec9f588
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
eec9f588
编写于
5月 24, 2022
作者:
C
cpwu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix case
上级
a7844ce6
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
123 addition
and
50 deletion
+123
-50
tests/system-test/2-query/join.py
tests/system-test/2-query/join.py
+116
-33
tests/system-test/2-query/union.py
tests/system-test/2-query/union.py
+7
-17
未找到文件。
tests/system-test/2-query/join.py
浏览文件 @
eec9f588
...
...
@@ -55,35 +55,118 @@ class TDTestCase:
return
query_condition
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
,
tbname
):
def
__join_condition
(
self
,
tb_list
,
filter
=
PRIMARY_COL
,
INNER
=
False
):
table_reference
=
tb_list
[
0
]
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
}
"
return
join_condition
# 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
:
return
f
" abs(
{
tbname
}
.
{
col
}
) >= 0"
elif
col
in
CHAR_COL
:
return
f
" lower(
{
tbname
}
.
{
col
}
) like 'bina%' or lower(
{
tbname
}
.
{
col
}
) like '_cha%' "
elif
col
in
BOOLEAN_COL
:
return
f
"
{
tbname
}
.
{
col
}
in (false, true) "
elif
col
in
TS_TYPE_COL
or
col
in
PRIMARY_COL
:
return
f
" cast(
{
tbname
}
.
{
col
}
as binary(16) ) is not null "
else
:
return
""
def
__group_condition
(
self
,
tbname
,
col
,
having
=
""
):
return
f
" where abs(
{
tbname
}
.
{
col
}
) >= 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
,
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
}
"
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
])
join_condition
=
self
.
__join_condition
(
tb_list
=
tblist
)
if
join_flag
else
" "
for
condition
in
query_conditions
:
...
...
@@ -141,17 +224,17 @@ class TDTestCase:
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
)
self
.
__join_check
_old
(
err_list_1
,
-
1
)
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=========="
)
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=========="
)
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=========="
)
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=========="
)
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=========="
)
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
):
self
.
__
test_current
()
self
.
__
join_check
()
self
.
__test_error
()
...
...
tests/system-test/2-query/union.py
浏览文件 @
eec9f588
...
...
@@ -96,7 +96,6 @@ class TDTestCase:
return
""
def
__group_condition
(
self
,
col
,
having
=
None
):
if
isinstance
(
col
,
str
):
if
col
.
startswith
(
"count"
):
...
...
@@ -114,7 +113,6 @@ class TDTestCase:
return
return
f
"select
{
select_clause
}
from
{
from_clause
}
{
where_condition
}
{
group_condition
}
"
@
property
def
__join_tblist
(
self
):
return
[
...
...
@@ -222,6 +220,8 @@ class TDTestCase:
tdSql
.
query
(
sqls
[
i
])
res1_type
=
self
.
__get_type
(
0
)
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
])
order_union_type
=
False
rev_order_type
=
False
...
...
@@ -246,22 +246,12 @@ class TDTestCase:
rev_order_type
=
True
if
all_union_type
:
tdSql
.
query
(
f
"
{
sqls
[
i
]
}
union
{
sqls
[
j
+
i
]
}
"
)
tdSql
.
query
(
f
"
{
sqls
[
j
+
i
]
}
union
{
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
)
tdSql
.
execute
(
f
"
{
sqls
[
i
]
}
union
{
sqls
[
j
+
i
]
}
"
)
tdSql
.
execute
(
f
"
{
sqls
[
j
+
i
]
}
union all
{
sqls
[
i
]
}
"
)
elif
order_union_type
:
tdSql
.
query
(
f
"
{
sqls
[
i
]
}
union
{
sqls
[
j
+
i
]
}
"
)
tdSql
.
checkCols
(
1
)
tdSql
.
query
(
f
"
{
sqls
[
i
]
}
union all
{
sqls
[
j
+
i
]
}
"
)
tdSql
.
checkCols
(
1
)
tdSql
.
execute
(
f
"
{
sqls
[
i
]
}
union all
{
sqls
[
j
+
i
]
}
"
)
elif
rev_order_type
:
tdSql
.
query
(
f
"
{
sqls
[
j
+
i
]
}
union
{
sqls
[
i
]
}
"
)
tdSql
.
checkCols
(
1
)
tdSql
.
query
(
f
"
{
sqls
[
j
+
i
]
}
union all
{
sqls
[
i
]
}
"
)
tdSql
.
checkCols
(
1
)
tdSql
.
execute
(
f
"
{
sqls
[
j
+
i
]
}
union
{
sqls
[
i
]
}
"
)
else
:
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 '' "
)
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
):
self
.
__test_error
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录