Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8c6da59e
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
8c6da59e
编写于
5月 16, 2022
作者:
C
cpwu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix case
上级
817e73bb
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
80 addition
and
85 deletion
+80
-85
tests/system-test/2-query/union.py
tests/system-test/2-query/union.py
+80
-85
未找到文件。
tests/system-test/2-query/union.py
浏览文件 @
8c6da59e
...
...
@@ -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
"
s
in(
{
tbname
}
.
{
num_col
}
)"
,
f
"
m
in(
{
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
]
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
}
"
tdSql
.
query
(
sql2
)
union_type
=
False
res2_type
=
self
.
__get_type
(
0
)
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
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
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录