Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
b762a699
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看板
提交
b762a699
编写于
9月 27, 2021
作者:
A
AlexDuan
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'tdigest' of
https://github.com/taosdata/TDengine
into tdigest
上级
6f9b51cd
d04e33b5
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
420 addition
and
17 deletion
+420
-17
tests/pytest/functions/queryTestCases.py
tests/pytest/functions/queryTestCases.py
+381
-15
tests/pytest/util/sql.py
tests/pytest/util/sql.py
+39
-2
未找到文件。
tests/pytest/functions/queryTestCases.py
浏览文件 @
b762a699
...
...
@@ -71,7 +71,6 @@ class TDTestCase:
def
td4082
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4082=========="
)
tdSql
.
prepare
()
cfgfile
=
self
.
getCfgFile
()
...
...
@@ -122,12 +121,8 @@ class TDTestCase:
def
td4097
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4097=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"drop database if exists db1"
)
tdDnodes
.
stop
(
1
)
tdDnodes
.
start
(
1
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"create database if not exists db1 keep 3650"
)
tdSql
.
execute
(
"create database if not exists new keep 3650"
)
...
...
@@ -143,7 +138,7 @@ class TDTestCase:
tdSql
.
execute
(
"create table db.t20 using db.stb2 tags(3)"
)
tdSql
.
execute
(
"create table db1.t30 using db1.stb3 tags(4)"
)
tdLog
.
printNoPrefix
(
"==========TD-4097=========="
)
#
tdLog.printNoPrefix("==========TD-4097==========")
# 插入数据,然后进行show create 操作
# p1 不进入指定数据库
...
...
@@ -329,7 +324,6 @@ class TDTestCase:
tdSql
.
checkData
(
0
,
7
,
36500
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db1"
)
tdSql
.
query
(
"show databases"
)
if
(
"community"
in
selfPath
):
...
...
@@ -398,28 +392,36 @@ class TDTestCase:
def
td4889
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4889=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"create database if not exists db keep 3650
blocks 3
"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t1 int)"
)
for
i
in
range
(
1000
):
tdSql
.
execute
(
f
"create table db.t1
{
i
}
using db.stb1 tags(
{
i
}
)"
)
for
j
in
range
(
10
0
):
for
j
in
range
(
6
0
):
tdSql
.
execute
(
f
"insert into db.t1
{
i
}
values (now-100d,
{
i
+
j
}
)"
)
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
tdDnodes
.
start
(
index
)
tdSql
.
query
(
"show vgroups"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdSql
.
checkData
(
0
,
6
,
0
)
tdSql
.
execute
(
f
"compact vnodes in(
{
index
}
)"
)
for
i
in
range
(
3
):
start_time
=
time
.
time
()
while
True
:
tdSql
.
query
(
"show vgroups"
)
if
tdSql
.
getData
(
0
,
6
)
==
1
:
if
tdSql
.
getData
(
0
,
6
)
!=
0
:
tdLog
.
printNoPrefix
(
"show vgroups row:0 col:6 data:1 == expect:1"
)
break
if
i
==
3
:
run_time
=
time
.
time
()
-
start_time
if
run_time
>
3
:
tdLog
.
exit
(
"compacting not occured"
)
time
.
sleep
(
0.5
)
time
.
sleep
(
0.1
)
pass
...
...
@@ -769,7 +771,7 @@ class TDTestCase:
tdSql
.
query
(
f
"select distinct c1,c2 from (select * from t1 where c1 <
{
tbnum
}
) "
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from (select * from stb1 where t2 !=0 and t2 != 1) "
)
tdSql
.
checkRows
(
0
)
tdSql
.
checkRows
(
4
)
tdSql
.
error
(
"select distinct c1, c2 from (select distinct c1, c2 from stb1 where t0 > 2 and t1 < 3) "
)
tdSql
.
error
(
"select c1, c2 from (select distinct c1, c2 from stb1 where t0 > 2 and t1 < 3) "
)
tdSql
.
query
(
"select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 ) where c1 < 4"
)
...
...
@@ -1118,9 +1120,372 @@ class TDTestCase:
tdSql
.
error
(
"select ts as t, top(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from t1 order by c3"
)
pass
def
apercentile_query_form
(
self
,
col
=
"c1"
,
p
=
0
,
com
=
','
,
algo
=
"'t-digest'"
,
alias
=
""
,
table_expr
=
"t1"
,
condition
=
""
):
'''
apercentile function:
:param col: string, column name, required parameters;
:param p: float, percentile interval, [0,100], required parameters;
:param algo: string, alforithm, real form like: ', algorithm' , algorithm: {type:int, data:[0, 1]};
:param alias: string, result column another name;
:param table_expr: string or expression, data source(eg,table/stable name, result set), required parameters;
:param condition: expression;
:param args: other funtions,like: ', last(col)'
:return: apercentile query statement,default: select apercentile(c1, 0, 1) from t1
'''
if
alias
:
return
f
"select apercentile(
{
col
}
,
{
p
}{
com
}
{
algo
}
)
{
alias
}
from
{
table_expr
}
{
condition
}
"
else
:
return
f
"select apercentile(
{
col
}
,
{
p
}{
com
}
{
algo
}
) from
{
table_expr
}
{
condition
}
"
def
checkapert
(
self
,
col
=
"c1"
,
p
=
0
,
com
=
','
,
algo
=
'"t-digest"'
,
alias
=
""
,
table_expr
=
"t1"
,
condition
=
""
):
tdSql
.
query
(
f
"select count(
{
col
}
) from
{
table_expr
}
{
condition
}
"
)
if
tdSql
.
queryRows
==
0
:
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
p
,
com
=
com
,
algo
=
algo
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
tdSql
.
checkRows
(
0
)
return
pset
=
[
0
,
40
,
50
,
60
,
100
]
for
pi
in
pset
:
if
"group"
in
condition
:
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
'"default"'
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
print
(
tdSql
.
sql
)
print
(
tdSql
.
queryResult
)
print
(
tdSql
.
queryRows
)
query_result
=
tdSql
.
queryResult
query_rows
=
tdSql
.
queryRows
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
'"t-digest"'
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
print
(
tdSql
.
sql
)
print
(
tdSql
.
queryResult
)
print
(
tdSql
.
queryRows
)
for
i
in
range
(
query_rows
):
tdSql
.
checkDeviaRation
(
i
,
0
,
query_result
[
i
][
0
],
0.001
)
else
:
tdSql
.
query
(
f
"select
{
col
}
from
{
table_expr
}
{
condition
}
"
)
query_result
=
np
.
array
(
tdSql
.
queryResult
)[
np
.
array
(
tdSql
.
queryResult
)
!=
None
]
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
algo
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
pi
),
0.001
)
if
algo
==
'"t-digest"'
:
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
'"default"'
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
pi
),
0.001
)
def
apercentile_query
(
self
):
# table schema :ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool
# c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
# case1: int col
self
.
checkapert
()
# case2: float col
case2
=
{
'col'
:
'c2'
}
self
.
checkapert
(
**
case2
)
# case3: double col
case3
=
{
'col'
:
'c5'
}
self
.
checkapert
(
**
case3
)
# case4: bigint col
case4
=
{
'col'
:
'c7'
}
self
.
checkapert
(
**
case4
)
# case5: smallint col
case5
=
{
'col'
:
'c8'
}
self
.
checkapert
(
**
case5
)
# case6: tinyint col
case6
=
{
'col'
:
'c9'
}
self
.
checkapert
(
**
case6
)
# case7: stable
case7
=
{
'table_expr'
:
'stb1'
}
self
.
checkapert
(
**
case7
)
# case8: nest query, outquery
case8
=
{
'table_expr'
:
'(select c1 from t1)'
}
self
.
checkapert
(
**
case8
)
# case9: nest query, inquery and out query
case9
=
{
'table_expr'
:
'(select apercentile(c1, 0) as c1 from t1)'
}
self
.
checkapert
(
**
case9
)
# case10: nest query, inquery
tdSql
.
query
(
"select * from (select c1 from stb1)"
)
if
tdSql
.
queryRows
==
0
:
tdSql
.
query
(
"select * from (select apercentile(c1,0) c1 from stb1)"
)
tdSql
.
checkRows
(
0
)
else
:
query_result
=
np
.
array
(
tdSql
.
queryResult
)[
np
.
array
(
tdSql
.
queryResult
)
!=
None
]
tdSql
.
query
(
"select * from (select apercentile(c1, 0) c1 from stb1)"
)
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
0
),
0.001
)
tdSql
.
query
(
"select * from (select apercentile(c1,100) c1 from stb1)"
)
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
100
),
0.001
)
tdSql
.
query
(
"select * from (select apercentile(c1,50) c1 from stb1)"
)
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
50
),
0.001
)
# case11: no algorithm = algo:0
case11
=
{
'com'
:
''
,
'algo'
:
''
}
self
.
checkapert
(
**
case11
)
# case12~14: p: bin/oct/hex
case12
=
{
'p'
:
0b1100100
}
self
.
checkapert
(
**
case12
)
case13
=
{
'algo'
:
'"T-DIGEST"'
}
self
.
checkapert
(
**
case13
)
case14
=
{
'p'
:
0x32
,
'algo'
:
'"DEFAULT"'
}
self
.
checkapert
(
**
case14
)
# case15~21: mix with aggregate function
case15
=
{
'alias'
:
', count(*)'
}
self
.
checkapert
(
**
case15
)
case16
=
{
'alias'
:
', avg(c1)'
}
self
.
checkapert
(
**
case16
)
case17
=
{
'alias'
:
', twa(c1)'
}
self
.
checkapert
(
**
case17
)
case18
=
{
'alias'
:
', irate(c1)'
}
self
.
checkapert
(
**
case18
)
case19
=
{
'alias'
:
', sum(c1)'
}
self
.
checkapert
(
**
case19
)
case20
=
{
'alias'
:
', stddev(c1)'
}
self
.
checkapert
(
**
case20
)
case21
=
{
'alias'
:
', leastsquares(c1, 1, 1)'
}
self
.
checkapert
(
**
case21
)
# case22~27:mix with selector function
case22
=
{
'alias'
:
', min(c1)'
}
self
.
checkapert
(
**
case22
)
case23
=
{
'alias'
:
', max(c1)'
}
self
.
checkapert
(
**
case23
)
case24
=
{
'alias'
:
', first(c1)'
}
self
.
checkapert
(
**
case24
)
case25
=
{
'alias'
:
', last(c1)'
}
self
.
checkapert
(
**
case25
)
case26
=
{
'alias'
:
', percentile(c1, 0)'
}
self
.
checkapert
(
**
case26
)
case27
=
{
'alias'
:
', apercentile(c1, 0, "t-digest")'
}
self
.
checkapert
(
**
case27
)
# case28~29: mix with computing function
case28
=
{
'alias'
:
', spread(c1)'
}
self
.
checkapert
(
**
case28
)
# case29: mix with four operation
case29
=
{
'alias'
:
'+ spread(c1)'
}
self
.
checkapert
(
**
case29
)
# case30~36: with condition
case30
=
{
'condition'
:
'where ts > now'
}
self
.
checkapert
(
**
case30
)
case31
=
{
'condition'
:
'where c1 between 1 and 200'
}
self
.
checkapert
(
**
case31
)
case32
=
{
'condition'
:
f
'where c1 in
{
tuple
(
i
for
i
in
range
(
200
))
}
'
}
self
.
checkapert
(
**
case32
)
case33
=
{
'condition'
:
'where c1>100 and c2<100'
}
self
.
checkapert
(
**
case33
)
case34
=
{
'condition'
:
'where c1 is not null'
}
self
.
checkapert
(
**
case34
)
case35
=
{
'condition'
:
'where c4 like "_inary%"'
}
self
.
checkapert
(
**
case35
)
case36
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'where tbname like "t_"'
}
self
.
checkapert
(
**
case36
)
# case37~38: with join
case37
=
{
'col'
:
't1.c1'
,
'table_expr'
:
't1, t2 '
,
'condition'
:
'where t1.ts=t2.ts'
}
self
.
checkapert
(
**
case37
)
case38
=
{
'col'
:
'stb1.c1'
,
'table_expr'
:
'stb1, stb2'
,
'condition'
:
'where stb1.ts=stb2.ts and stb1.st1=stb2.st2'
}
self
.
checkapert
(
**
case38
)
# case39: with group by
case39
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname'
}
self
.
checkapert
(
**
case39
)
# case40: with slimit
case40
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname slimit 1'
}
self
.
checkapert
(
**
case40
)
# case41: with soffset
case41
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname slimit 1 soffset 1'
}
self
.
checkapert
(
**
case41
)
# case42: with order by
case42
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'order by ts'
}
self
.
checkapert
(
**
case42
)
case43
=
{
'table_expr'
:
't1'
,
'condition'
:
'order by ts'
}
self
.
checkapert
(
**
case43
)
# case44: with limit offset
case44
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname limit 1'
}
self
.
checkapert
(
**
case44
)
case45
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname limit 1 offset 1'
}
self
.
checkapert
(
**
case45
)
pass
def
error_apercentile
(
self
):
# unusual test
#
# table schema :ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool
# c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
#
# form test
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
""
,
com
=
''
,
algo
=
''
))
# no col , no algorithm
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
""
))
# no col , algorithm
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
''
,
com
=
''
,
algo
=
''
))
# no p , no algorithm
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
''
))
# no p , algorithm
tdSql
.
error
(
"apercentile( c1, 100) from t1"
)
# no select
tdSql
.
error
(
"select apercentile from t1"
)
# no algorithm condition
tdSql
.
error
(
"select apercentile c1,0 from t1"
)
# no brackets
tdSql
.
error
(
"select apercentile (c1,0) t1"
)
# no from
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
'(c1,0)'
,
p
=
''
,
com
=
''
,
algo
=
''
))
# no p , no algorithm
tdSql
.
error
(
"select apercentile( (c1,0) ) from t1"
)
# no table_expr
tdSql
.
error
(
"select apercentile{ (c1,0) } from t1"
)
# sql form error 1
tdSql
.
error
(
"select apercentile[ (c1,0) ] from t1"
)
# sql form error 2
tdSql
.
error
(
"select [apercentile(c1,0) ] from t1"
)
# sql form error 3
tdSql
.
error
(
"select apercentile((c1, 0), 'default') from t1"
)
# sql form error 5
tdSql
.
error
(
"select apercentile(c1, (0, 'default')) from t1"
)
# sql form error 6
tdSql
.
error
(
"select apercentile(c1, (0), 1) from t1"
)
# sql form error 7
tdSql
.
error
(
"select apercentile([c1, 0], 'default') from t1"
)
# sql form error 8
tdSql
.
error
(
"select apercentile(c1, [0, 'default']) from t1"
)
# sql form error 9
tdSql
.
error
(
"select apercentile(c1, {0, 'default'}) from t1"
)
# sql form error 10
tdSql
.
error
(
"select apercentile([c1, 0]) from t1"
)
# sql form error 11
tdSql
.
error
(
"select apercentile({c1, 0}) from t1"
)
# sql form error 12
tdSql
.
error
(
"select apercentile(c1) from t1"
)
# agrs: 1
tdSql
.
error
(
"select apercentile(c1, 0, 'default', 0) from t1"
)
# agrs: 4
tdSql
.
error
(
"select apercentile(c1, 0, 0, 'default') from t1"
)
# agrs: 4
tdSql
.
error
(
"select apercentile() from t1"
)
# agrs: null 1
tdSql
.
error
(
"select apercentile from t1"
)
# agrs: null 2
tdSql
.
error
(
"select apercentile( , , ) from t1"
)
# agrs: null 3
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
''
,
p
=
''
,
algo
=
''
))
# agrs: null 4
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"st1"
))
# col:tag column
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
123
))
# col:numerical
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
True
))
# col:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
''
))
# col:''
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"last(c1)"
))
# col:expr
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"t%"
))
# col:non-numerical
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c3"
))
# col-type: timestamp
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c4"
))
# col-type: binary
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c6"
))
# col-type: bool
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c10"
))
# col-type: nchar
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
True
))
# p:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
'a'
))
# p:str
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
'last(*)'
))
# p:expr
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
"2021-08-01 00:00:00.000"
))
# p:timestamp
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
't-digest'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t_digest"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest0"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest."'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest%"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest*"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'tdigest'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
2.0
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
1.9999
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
0.9999
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
1.0
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
0b1
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
0x1
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
0o1
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
True
))
# algorithm:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
"True"
))
# algorithm:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'2021-08-01 00:00:00.000'
))
# algorithm:timestamp
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'last(c1)'
))
# algorithm:expr
# boundary test
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=-
1
))
# p left out of [0, 100]
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=-
9223372036854775809
))
# p left out of bigint
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
100.1
))
# p right out of [0, 100]
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
18446744073709551616
))
# p right out of unsigned-bigint
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
1
))
# algorithm left out of [0, 1]
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
9223372036854775809
))
# algorithm left out of unsigned-bigint
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
2
))
# algorithm right out of [0, 1]
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
18446744073709551616
))
# algorithm right out of unsigned-bigint
# mix function test
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', top(c1,1)'
))
# mix with top function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', top(c1,1)'
))
# mix with bottom function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', last_row(c1)'
))
# mix with last_row function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', distinct c1 '
))
# mix with distinct function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', *'
))
# mix with *
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', diff(c1)'
))
# mix with diff function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', interp(c1)'
,
condition
=
'ts="2021-10-10 00:00:00.000"'
))
# mix with interp function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', derivative(c1, 10m, 0)'
))
# mix with derivative function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', diff(c1)'
))
# mix with diff function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
'+ c1)'
))
# mix with four operation
def
apercentile_data
(
self
,
basetime
):
for
i
in
range
(
10
):
for
j
in
range
(
10
):
tdSql
.
execute
(
f
"insert into t
{
i
}
values ("
f
"
{
basetime
+
j
*
10
}
,
{
random
.
randint
(
-
200
,
-
1
)
}
,
{
random
.
uniform
(
200
,
-
1
)
}
,
{
basetime
+
random
.
randint
(
-
200
,
-
1
)
}
, "
f
"'binary_
{
j
}
',
{
random
.
uniform
(
-
200
,
-
1
)
}
,
{
random
.
choice
([
0
,
1
])
}
,
{
random
.
randint
(
-
200
,
-
1
)
}
, "
f
"
{
random
.
randint
(
-
200
,
-
1
)
}
,
{
random
.
randint
(
-
127
,
-
1
)
}
, 'nchar_
{
j
}
' )"
)
tdSql
.
execute
(
f
"insert into t
{
i
}
values ("
f
"
{
basetime
-
(
j
+
1
)
*
10
}
,
{
random
.
randint
(
1
,
200
)
}
,
{
random
.
uniform
(
1
,
200
)
}
,
{
basetime
-
random
.
randint
(
1
,
200
)
}
, "
f
"'binary_
{
j
}
_1',
{
random
.
uniform
(
1
,
200
)
}
,
{
random
.
choice
([
0
,
1
])
}
,
{
random
.
randint
(
1
,
200
)
}
, "
f
"
{
random
.
randint
(
1
,
200
)
}
,
{
random
.
randint
(
1
,
127
)
}
, 'nchar_
{
j
}
_1' )"
)
tdSql
.
execute
(
f
"insert into tt
{
i
}
values (
{
basetime
-
(
j
+
1
)
*
10
}
,
{
random
.
randint
(
1
,
200
)
}
)"
)
pass
def
td6108
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-6108=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (
\
ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool,
\
c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
\
)
\
tags(st1 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c1 int) tags(st2 int)"
)
for
i
in
range
(
100
):
tdSql
.
execute
(
f
"create table t
{
i
}
using stb1 tags(
{
i
}
)"
)
tdSql
.
execute
(
f
"create table tt
{
i
}
using stb2 tags(
{
i
}
)"
)
tdLog
.
printNoPrefix
(
"######## no data test:"
)
self
.
apercentile_query
()
self
.
error_apercentile
()
tdLog
.
printNoPrefix
(
"######## insert data test:"
)
nowtime
=
int
(
round
(
time
.
time
()
*
1000
))
self
.
apercentile_data
(
nowtime
)
self
.
apercentile_query
()
self
.
error_apercentile
()
tdLog
.
printNoPrefix
(
"######## insert data with NULL test:"
)
tdSql
.
execute
(
f
"insert into t1(ts) values (
{
nowtime
-
5
}
)"
)
tdSql
.
execute
(
f
"insert into t1(ts) values (
{
nowtime
+
5
}
)"
)
self
.
apercentile_query
()
self
.
error_apercentile
()
tdLog
.
printNoPrefix
(
"######## check after WAL test:"
)
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
tdDnodes
.
start
(
index
)
self
.
apercentile_query
()
self
.
error_apercentile
()
def
run
(
self
):
...
...
@@ -1135,9 +1500,10 @@ class TDTestCase:
# develop branch
self
.
td4097
()
self
.
td4889
()
self
.
td5798
()
# self.td5168()
self
.
td5798
()
self
.
td5433
()
self
.
td6108
()
def
stop
(
self
):
tdSql
.
close
()
...
...
tests/pytest/util/sql.py
浏览文件 @
b762a699
###################################################################
###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
...
...
@@ -184,7 +184,11 @@ class TDSql:
if
self
.
queryResult
[
row
][
col
]
!=
data
:
if
self
.
cursor
.
istype
(
col
,
"TIMESTAMP"
):
# suppose user want to check nanosecond timestamp if a longer data passed
if
(
len
(
data
)
>=
28
):
if
isinstance
(
data
,
int
)
or
isinstance
(
data
,
float
):
if
pd
.
to_datetime
(
self
.
queryResult
[
row
][
col
])
==
pd
.
to_datetime
(
data
):
tdLog
.
info
(
"sql:%s, row:%d col:%d data:%d == expect:%s"
%
(
self
.
sql
,
row
,
col
,
self
.
queryResult
[
row
][
col
],
data
))
elif
(
len
(
data
)
>=
28
):
if
pd
.
to_datetime
(
self
.
queryResult
[
row
][
col
])
==
pd
.
to_datetime
(
data
):
tdLog
.
info
(
"sql:%s, row:%d col:%d data:%d == expect:%s"
%
(
self
.
sql
,
row
,
col
,
self
.
queryResult
[
row
][
col
],
data
))
...
...
@@ -223,6 +227,39 @@ class TDSql:
tdLog
.
info
(
"sql:%s, row:%d col:%d data:%s == expect:%d"
%
(
self
.
sql
,
row
,
col
,
self
.
queryResult
[
row
][
col
],
data
))
def
checkDeviaRation
(
self
,
row
,
col
,
data
,
deviation
=
0.001
):
self
.
checkRowCol
(
row
,
col
)
if
data
is
None
:
self
.
checkData
(
row
,
col
,
None
)
return
caller
=
inspect
.
getframeinfo
(
inspect
.
stack
()[
1
][
0
])
if
data
is
not
None
and
len
(
self
.
queryResult
)
==
0
:
tdLog
.
exit
(
f
"
{
caller
.
filename
}
(
{
caller
.
lineno
}
) failed: sql:
{
self
.
sql
}
, data:
{
data
}
, "
f
"expect result is not None but it is"
)
args
=
(
caller
.
filename
,
caller
.
lineno
,
self
.
sql
,
data
,
type
(
data
),
deviation
,
type
(
deviation
),
self
.
queryResult
[
row
][
col
],
type
(
self
.
queryResult
[
row
][
col
])
)
if
not
(
isinstance
(
data
,
int
)
or
isinstance
(
data
,
float
)):
tdLog
.
exit
(
f
"
{
args
[
0
]
}
(
{
args
[
1
]
}
) failed: sql:
{
args
[
2
]
}
, data:
{
args
[
3
]
}
, "
f
"expect type: int or float, actual type:
{
args
[
4
]
}
"
)
if
not
(
isinstance
(
deviation
,
int
)
or
isinstance
(
deviation
,
float
))
or
type
(
data
)
==
type
(
True
):
tdLog
.
exit
(
f
"
{
args
[
0
]
}
(
{
args
[
1
]
}
) failed: sql:
{
args
[
2
]
}
, deviation:
{
args
[
5
]
}
, "
f
"expect type: int or float, actual type:
{
args
[
6
]
}
"
)
if
not
(
isinstance
(
self
.
queryResult
[
row
][
col
],
int
)
or
isinstance
(
self
.
queryResult
[
row
][
col
],
float
)):
tdLog
.
exit
(
f
"
{
args
[
0
]
}
(
{
args
[
1
]
}
) failed: sql:
{
args
[
2
]
}
, result:
{
args
[
7
]
}
, "
f
"expect type: int or float, actual type:
{
args
[
8
]
}
"
)
devia
=
abs
((
data
-
self
.
queryResult
[
row
][
col
])
/
data
)
if
devia
<=
deviation
:
tdLog
.
info
(
f
"sql:
{
args
[
2
]
}
, result data:
{
args
[
7
]
}
, expect data:
{
args
[
3
]
}
, "
f
"actual deviation:
{
devia
}
<= expect deviation:
{
args
[
5
]
}
"
)
else
:
tdLog
.
exit
(
f
"
{
args
[
0
]
}
(
{
args
[
1
]
}
) failed: sql:
{
args
[
2
]
}
, result data:
{
args
[
7
]
}
, expect data:
{
args
[
3
]
}
,"
f
"actual deviation:
{
devia
}
<= expect deviation:
{
args
[
5
]
}
"
)
pass
def
getData
(
self
,
row
,
col
):
self
.
checkRowCol
(
row
,
col
)
return
self
.
queryResult
[
row
][
col
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录