Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
6b3fa3f5
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看板
提交
6b3fa3f5
编写于
3月 16, 2023
作者:
G
gccgdb1234
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test:fix that timestamps can be validated correctly in testcase
上级
48bbd0ee
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
151 addition
and
9 deletion
+151
-9
tests/pytest/util/sql.py
tests/pytest/util/sql.py
+65
-9
tests/system-test/2-query/timeerror.py
tests/system-test/2-query/timeerror.py
+86
-0
未找到文件。
tests/pytest/util/sql.py
浏览文件 @
6b3fa3f5
...
@@ -23,13 +23,36 @@ import pandas as pd
...
@@ -23,13 +23,36 @@ import pandas as pd
from
util.log
import
*
from
util.log
import
*
from
util.constant
import
*
from
util.constant
import
*
from
datetime
import
datetime
,
timedelta
,
timezone
from
tzlocal
import
get_localzone
import
pytz
import
time
def
_locaTzTimeStamp
(
utctimestamp
):
tz
=
get_localzone
()
temptz
=
str
(
tz
)
localtz
=
pytz
.
timezone
(
temptz
)
defUtctimestamp
=
1035640800
local_dt
=
datetime
(
2002
,
10
,
27
,
6
,
0
,
0
,
tzinfo
=
localtz
)
defLocaltimestamp
=
time
.
mktime
(
local_dt
.
timetuple
())
deltaTzTime
=
int
(
defLocaltimestamp
)
-
int
(
defUtctimestamp
)
temp
=
int
(
str
(
utctimestamp
)[
0
:
10
])
tempOther
=
str
(
utctimestamp
)[
10
-
len
(
str
(
utctimestamp
)):]
localtemp
=
deltaTzTime
+
temp
localAll
=
str
(
localtemp
)
+
str
(
tempOther
)
localtimestamp
=
int
(
localAll
)
print
(
f
"local timezone is
{
localtimestamp
}
, Deltel time is
{
deltaTzTime
}
s"
)
return
localtimestamp
def
_parse_datetime
(
timestr
):
def
_parse_datetime
(
timestr
):
try
:
try
:
return
datetime
.
datetime
.
strptime
(
timestr
,
'%Y-%m-%d %H:%M:%S.%f'
)
return
datetime
.
strptime
(
timestr
,
'%Y-%m-%d %H:%M:%S.%f'
)
except
ValueError
:
except
ValueError
:
pass
pass
try
:
try
:
return
datetime
.
datetime
.
strptime
(
timestr
,
'%Y-%m-%d %H:%M:%S'
)
return
datetime
.
strptime
(
timestr
,
'%Y-%m-%d %H:%M:%S'
)
except
ValueError
:
except
ValueError
:
pass
pass
...
@@ -227,18 +250,51 @@ class TDSql:
...
@@ -227,18 +250,51 @@ class TDSql:
self
.
checkRowCol
(
row
,
col
)
self
.
checkRowCol
(
row
,
col
)
return
self
.
cursor
.
istype
(
col
,
dataType
)
return
self
.
cursor
.
istype
(
col
,
dataType
)
def
checkData
(
self
,
row
,
col
,
data
):
def
checkData
(
self
,
row
,
col
,
data
):
self
.
checkRowCol
(
row
,
col
)
self
.
checkRowCol
(
row
,
col
)
if
self
.
queryResult
[
row
][
col
]
!=
data
:
if
self
.
queryResult
[
row
][
col
]
!=
data
:
if
self
.
cursor
.
istype
(
col
,
"TIMESTAMP"
):
if
self
.
cursor
.
istype
(
col
,
"TIMESTAMP"
):
# suppose user want to check nanosecond timestamp if a longer data passed
# suppose user want to check nanosecond timestamp if a longer data passed``
if
isinstance
(
data
,
str
)
:
if
(
len
(
data
)
>=
28
):
if
(
len
(
data
)
>=
28
):
if
pd
.
to_datetime
(
self
.
queryResult
[
row
][
col
])
==
pd
.
to_datetime
(
data
):
resultData
=
_locaTzTimeStamp
(
self
.
queryResult
[
row
][
col
])
tdLog
.
info
(
f
"sql:
{
self
.
sql
}
, row:
{
row
}
col:
{
col
}
data:
{
self
.
queryResult
[
row
][
col
]
}
== expect:
{
data
}
"
)
if
pd
.
to_datetime
(
resultData
)
==
pd
.
to_datetime
(
data
):
tdLog
.
info
(
f
"sql:
{
self
.
sql
}
, row:
{
row
}
col:
{
col
}
data:
{
pd
.
to_datetime
(
resultData
)
}
== expect:
{
data
}
"
)
else
:
caller
=
inspect
.
getframeinfo
(
inspect
.
stack
()[
1
][
0
])
args
=
(
caller
.
filename
,
caller
.
lineno
,
self
.
sql
,
row
,
col
,
self
.
queryResult
[
row
][
col
],
data
)
tdLog
.
exit
(
"%s(%d) failed: sql:%s row:%d col:%d data:%s != expect:%s"
%
args
)
else
:
else
:
if
self
.
queryResult
[
row
][
col
]
==
_parse_datetime
(
data
):
if
self
.
queryResult
[
row
][
col
]
==
_parse_datetime
(
data
):
tdLog
.
info
(
f
"sql:
{
self
.
sql
}
, row:
{
row
}
col:
{
col
}
data:
{
self
.
queryResult
[
row
][
col
]
}
== expect:
{
data
}
"
)
tdLog
.
info
(
f
"sql:
{
self
.
sql
}
, row:
{
row
}
col:
{
col
}
data:
{
self
.
queryResult
[
row
][
col
]
}
== expect:
{
data
}
"
)
else
:
caller
=
inspect
.
getframeinfo
(
inspect
.
stack
()[
1
][
0
])
args
=
(
caller
.
filename
,
caller
.
lineno
,
self
.
sql
,
row
,
col
,
self
.
queryResult
[
row
][
col
],
data
)
tdLog
.
exit
(
"%s(%d) failed: sql:%s row:%d col:%d data:%s != expect:%s"
%
args
)
return
elif
isinstance
(
data
,
int
)
:
if
len
(
str
(
data
))
==
16
:
unitTime
=
'us'
elif
len
(
str
(
data
))
==
13
:
unitTime
=
'ms'
elif
len
(
str
(
data
))
==
19
:
unitTime
=
'ns'
else
:
tdLog
.
exit
(
"expect timeStamp type is wrong"
)
resultData
=
pd
.
to_datetime
(
_locaTzTimeStamp
(
data
),
unit
=
unitTime
)
if
resultData
==
self
.
queryResult
[
row
][
col
]
:
tdLog
.
info
(
f
"sql:
{
self
.
sql
}
, row:
{
row
}
col:
{
col
}
data:
{
self
.
queryResult
[
row
][
col
]
}
== expect:
{
resultData
}
"
)
else
:
caller
=
inspect
.
getframeinfo
(
inspect
.
stack
()[
1
][
0
])
args
=
(
caller
.
filename
,
caller
.
lineno
,
self
.
sql
,
row
,
col
,
self
.
queryResult
[
row
][
col
],
data
)
tdLog
.
exit
(
"%s(%d) failed: sql:%s row:%d col:%d data:%s != expect:%s"
%
args
)
return
return
else
:
caller
=
inspect
.
getframeinfo
(
inspect
.
stack
()[
1
][
0
])
args
=
(
caller
.
filename
,
caller
.
lineno
,
self
.
sql
,
row
,
col
,
self
.
queryResult
[
row
][
col
],
data
)
tdLog
.
exit
(
"%s(%d) failed: sql:%s row:%d col:%d data:%s != expect:%s"
%
args
)
if
str
(
self
.
queryResult
[
row
][
col
])
==
str
(
data
):
if
str
(
self
.
queryResult
[
row
][
col
])
==
str
(
data
):
tdLog
.
info
(
f
"sql:
{
self
.
sql
}
, row:
{
row
}
col:
{
col
}
data:
{
self
.
queryResult
[
row
][
col
]
}
== expect:
{
data
}
"
)
tdLog
.
info
(
f
"sql:
{
self
.
sql
}
, row:
{
row
}
col:
{
col
}
data:
{
self
.
queryResult
[
row
][
col
]
}
== expect:
{
data
}
"
)
...
...
tests/system-test/2-query/timeerror.py
0 → 100644
浏览文件 @
6b3fa3f5
import
taos
import
sys
from
time
import
sleep
from
util.log
import
*
from
util.sql
import
*
from
util.cases
import
*
class
TDTestCase
:
def
init
(
self
,
conn
,
logSql
,
replicaVar
=
1
):
self
.
replicaVar
=
int
(
replicaVar
)
tdLog
.
debug
(
f
"start to excute
{
__file__
}
"
)
tdSql
.
init
(
conn
.
cursor
())
def
run
(
self
):
rows
=
10
tdSql
.
execute
(
"create database dbus PRECISION 'us' "
)
tdSql
.
execute
(
"create database dbns PRECISION 'ns' "
)
tdSql
.
execute
(
"create database dbms PRECISION 'ms' "
)
dball
=
[
"dbns"
,
"dbus"
,
"dbms"
]
for
i
in
range
(
len
(
dball
)):
dbname
=
dball
[
i
]
stb
=
f
"
{
dbname
}
.stb1"
if
i
==
0
:
qts
=
1678883666951061471
qts1
=
1678883666951061471
qtime
=
"2023-03-15 20:34:26.951061471"
elif
i
==
1
:
qts
=
1678883666951061
qts1
=
1678883666951061
qtime
=
"2023-03-15 20:34:26.951061"
else
:
qts
=
1678883666951
qts1
=
1678883666953
qtime
=
"2023-03-15 20:34:26.951"
tdSql
.
execute
(
f
"use
{
dbname
}
"
)
tdLog
.
printNoPrefix
(
"==========step1:create table"
)
tdSql
.
execute
(
f
'''create table if not exists
{
stb
}
(ts timestamp, c1 int, c2 float, c3 bigint, c4 double, c5 smallint, c6 tinyint)
tags(location binary(64), type int, isused bool , family nchar(64))'''
)
tdSql
.
execute
(
f
"create table
{
dbname
}
.t1 using
{
stb
}
tags('beijing', 1, 1, 'nchar1')"
)
tdSql
.
execute
(
f
"create table
{
dbname
}
.t2 using
{
stb
}
tags('shanghai', 2, 0, 'nchar2')"
)
tdSql
.
execute
(
f
"create table
{
dbname
}
.t3 using
{
stb
}
tags('shanghai', 3, 0, 'nchar3')"
)
tdLog
.
printNoPrefix
(
"==========step2:insert data"
)
for
i
in
range
(
rows
):
tdSql
.
execute
(
f
"insert into
{
dbname
}
.t1 values (now()+
{
i
}
m,
{
32767
+
i
}
,
{
20.0
+
i
/
10
}
,
{
2
**
31
+
i
}
,
{
3.4
*
10
**
38
+
i
/
10
}
,
{
127
+
i
}
,
{
i
}
)"
)
tdSql
.
execute
(
f
"insert into
{
dbname
}
.t2 values (now()-
{
i
}
m,
{
-
32767
-
i
}
,
{
20.0
-
i
/
10
}
,
{
-
i
-
2
**
31
}
,
{
-
i
/
10
-
3.4
*
10
**
38
}
,
{
-
127
-
i
}
,
{
-
i
}
)"
)
tdSql
.
execute
(
f
"insert into
{
dbname
}
.t1 values (now()+11m,
{
2
**
31
-
1
}
,
{
pow
(
10
,
37
)
*
34
}
,
{
pow
(
2
,
63
)
-
1
}
,
{
1.7
*
10
**
308
}
, 32767, 127)"
)
tdSql
.
execute
(
f
"insert into
{
dbname
}
.t2 values (now()-11m,
{
1
-
2
**
31
}
,
{
-
3.4
*
10
**
38
}
,
{
1
-
2
**
63
}
,
{
-
1.7
*
10
**
308
}
, -32767, -127)"
)
tdSql
.
execute
(
f
"insert into
{
dbname
}
.t2 values (now()-12m, null ,
{
-
3.4
*
10
**
38
}
, null ,
{
-
1.7
*
10
**
308
}
, null , null)"
)
tdSql
.
execute
(
f
"insert into
{
dbname
}
.t3 values (
{
qts
}
, null ,
{
-
3.4
*
10
**
38
}
, null ,
{
-
1.7
*
10
**
308
}
, null , null)"
)
tdLog
.
printNoPrefix
(
"==========step3:query timestamp type"
)
tdSql
.
query
(
f
"select ts from
{
dbname
}
.t3 limit 1"
)
tdSql
.
checkData
(
0
,
0
,
qtime
)
tdSql
.
checkData
(
0
,
0
,
qts
)
def
stop
(
self
):
tdSql
.
close
()
tdLog
.
success
(
f
"
{
__file__
}
successfully executed"
)
tdCases
.
addLinux
(
__file__
,
TDTestCase
())
tdCases
.
addWindows
(
__file__
,
TDTestCase
())
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录