Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c9a7613d
T
TDengine
项目概览
taosdata
/
TDengine
12 个月 前同步成功
通知
1180
Star
22014
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
c9a7613d
编写于
7月 05, 2022
作者:
G
Ganlin Zhao
提交者:
GitHub
7月 05, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #14552 from taosdata/fix/TD-17012
fix(query): add "1b" timeunit in function param to represent nanosecond
上级
149587c9
479776b7
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
43 addition
and
35 deletion
+43
-35
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+18
-16
source/libs/scalar/src/sclfunc.c
source/libs/scalar/src/sclfunc.c
+16
-11
tests/system-test/2-query/timetruncate.py
tests/system-test/2-query/timetruncate.py
+9
-8
未找到文件。
source/libs/function/src/builtins.c
浏览文件 @
c9a7613d
...
...
@@ -48,13 +48,19 @@ static int32_t validateTimeUnitParam(uint8_t dbPrec, const SValueNode* pVal) {
return
TIME_UNIT_INVALID
;
}
if
(
TSDB_TIME_PRECISION_MILLI
==
dbPrec
&&
0
==
strcasecmp
(
pVal
->
literal
,
"1u"
))
{
if
(
TSDB_TIME_PRECISION_MILLI
==
dbPrec
&&
(
0
==
strcasecmp
(
pVal
->
literal
,
"1u"
)
||
0
==
strcasecmp
(
pVal
->
literal
,
"1b"
)))
{
return
TIME_UNIT_TOO_SMALL
;
}
if
(
pVal
->
literal
[
0
]
!=
'1'
||
(
pVal
->
literal
[
1
]
!=
'u'
&&
pVal
->
literal
[
1
]
!=
'a'
&&
pVal
->
literal
[
1
]
!=
's'
&&
pVal
->
literal
[
1
]
!=
'm'
&&
pVal
->
literal
[
1
]
!=
'h'
&&
pVal
->
literal
[
1
]
!=
'd'
&&
pVal
->
literal
[
1
]
!=
'w'
))
{
if
(
TSDB_TIME_PRECISION_MICRO
==
dbPrec
&&
0
==
strcasecmp
(
pVal
->
literal
,
"1b"
))
{
return
TIME_UNIT_TOO_SMALL
;
}
if
(
pVal
->
literal
[
0
]
!=
'1'
||
(
pVal
->
literal
[
1
]
!=
'u'
&&
pVal
->
literal
[
1
]
!=
'a'
&&
pVal
->
literal
[
1
]
!=
's'
&&
pVal
->
literal
[
1
]
!=
'm'
&&
pVal
->
literal
[
1
]
!=
'h'
&&
pVal
->
literal
[
1
]
!=
'd'
&&
pVal
->
literal
[
1
]
!=
'w'
&&
pVal
->
literal
[
1
]
!=
'b'
))
{
return
TIME_UNIT_INVALID
;
}
...
...
@@ -700,9 +706,8 @@ static int32_t translateElapsed(SFunctionNode* pFunc, char* pErrBuf, int32_t len
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"ELAPSED function time unit parameter should be greater than db precision"
);
}
else
if
(
ret
==
TIME_UNIT_INVALID
)
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"ELAPSED function time unit parameter should be one of the following: [1u, 1a, 1s, 1m, 1h, 1d, 1w]"
);
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"ELAPSED function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]"
);
}
}
...
...
@@ -1223,9 +1228,8 @@ static int32_t translateStateDuration(SFunctionNode* pFunc, char* pErrBuf, int32
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"STATEDURATION function time unit parameter should be greater than db precision"
);
}
else
if
(
ret
==
TIME_UNIT_INVALID
)
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"STATEDURATION function time unit parameter should be one of the following: [1u, 1a, 1s, 1m, 1h, 1d, 1w]"
);
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"STATEDURATION function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]"
);
}
}
...
...
@@ -1735,9 +1739,8 @@ static int32_t translateTimeTruncate(SFunctionNode* pFunc, char* pErrBuf, int32_
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"TIMETRUNCATE function time unit parameter should be greater than db precision"
);
}
else
if
(
ret
==
TIME_UNIT_INVALID
)
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"TIMETRUNCATE function time unit parameter should be one of the following: [1u, 1a, 1s, 1m, 1h, 1d, 1w]"
);
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"TIMETRUNCATE function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]"
);
}
addDbPrecisonParam
(
&
pFunc
->
pParameterList
,
dbPrec
);
...
...
@@ -1775,9 +1778,8 @@ static int32_t translateTimeDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t le
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"TIMEDIFF function time unit parameter should be greater than db precision"
);
}
else
if
(
ret
==
TIME_UNIT_INVALID
)
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"TIMEDIFF function time unit parameter should be one of the following: [1u, 1a, 1s, 1m, 1h, 1d, 1w]"
);
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"TIMEDIFF function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]"
);
}
}
...
...
source/libs/scalar/src/sclfunc.c
浏览文件 @
c9a7613d
...
...
@@ -1174,7 +1174,7 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
int64_t
factor
=
(
timePrec
==
TSDB_TIME_PRECISION_MILLI
)
?
1000
:
(
timePrec
==
TSDB_TIME_PRECISION_MICRO
?
1000000
:
1000000000
);
timeU
nit
=
timeUnit
*
1000
/
factor
;
int64_t
u
nit
=
timeUnit
*
1000
/
factor
;
for
(
int32_t
i
=
0
;
i
<
pInput
[
0
].
numOfRows
;
++
i
)
{
if
(
colDataIsNull_s
(
pInput
[
0
].
columnData
,
i
))
{
...
...
@@ -1209,12 +1209,14 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
NUM_TO_STRING
(
TSDB_DATA_TYPE_BIGINT
,
&
timeVal
,
sizeof
(
buf
),
buf
);
int32_t
tsDigits
=
(
int32_t
)
strlen
(
buf
);
switch
(
timeU
nit
)
{
case
0
:
{
/* 1u */
switch
(
u
nit
)
{
case
0
:
{
/* 1u
or 1b
*/
if
(
tsDigits
==
TSDB_TIME_PRECISION_NANO_DIGITS
)
{
timeVal
=
timeVal
/
1000
*
1000
;
//} else if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) {
// //timeVal = timeVal / 1000;
if
(
timePrec
==
TSDB_TIME_PRECISION_NANO
&&
timeUnit
==
1
)
{
timeVal
=
timeVal
*
1
;
}
else
{
timeVal
=
timeVal
/
1000
*
1000
;
}
}
else
if
(
tsDigits
<=
TSDB_TIME_PRECISION_SEC_DIGITS
)
{
timeVal
=
timeVal
*
factor
;
}
else
{
...
...
@@ -1366,8 +1368,6 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
int64_t
factor
=
(
timePrec
==
TSDB_TIME_PRECISION_MILLI
)
?
1000
:
(
timePrec
==
TSDB_TIME_PRECISION_MICRO
?
1000000
:
1000000000
);
timeUnit
=
timeUnit
*
1000
/
factor
;
int32_t
numOfRows
=
0
;
for
(
int32_t
i
=
0
;
i
<
inputNum
;
++
i
)
{
if
(
pInput
[
i
].
numOfRows
>
numOfRows
)
{
...
...
@@ -1447,9 +1447,14 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
}
}
}
else
{
switch
(
timeUnit
)
{
case
0
:
{
/* 1u */
result
=
result
/
1000
;
int64_t
unit
=
timeUnit
*
1000
/
factor
;
switch
(
unit
)
{
case
0
:
{
/* 1u or 1b */
if
(
timePrec
==
TSDB_TIME_PRECISION_NANO
&&
timeUnit
==
1
)
{
result
=
result
/
1
;
}
else
{
result
=
result
/
1000
;
}
break
;
}
case
1
:
{
/* 1a */
...
...
tests/system-test/2-query/timetruncate.py
浏览文件 @
c9a7613d
...
...
@@ -24,7 +24,8 @@ class TDTestCase:
]
self
.
db_param_precision
=
[
'ms'
,
'us'
,
'ns'
]
self
.
time_unit
=
[
'1w'
,
'1d'
,
'1h'
,
'1m'
,
'1s'
,
'1a'
,
'1u'
]
self
.
error_unit
=
[
'1b'
,
'2w'
,
'2d'
,
'2h'
,
'2m'
,
'2s'
,
'2a'
,
'2u'
,
'1c'
,
'#1'
]
#self.error_unit = ['1b','2w','2d','2h','2m','2s','2a','2u','1c','#1']
self
.
error_unit
=
[
'2w'
,
'2d'
,
'2h'
,
'2m'
,
'2s'
,
'2a'
,
'2u'
,
'1c'
,
'#1'
]
self
.
ntbname
=
'ntb'
self
.
stbname
=
'stb'
self
.
ctbname
=
'ctb'
...
...
@@ -92,7 +93,7 @@ class TDTestCase:
elif
unit
.
lower
()
==
'1d'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
ts_result
=
self
.
get_ms_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]
/
1000
/
60
/
60
/
24
)
*
24
*
60
*
60
*
1000
)
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]
/
1000
/
60
/
60
/
24
)
*
24
*
60
*
60
*
1000
)
elif
unit
.
lower
()
==
'1w'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
ts_result
=
self
.
get_ms_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
...
...
@@ -121,7 +122,7 @@ class TDTestCase:
elif
unit
.
lower
()
==
'1d'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
ts_result
=
self
.
get_us_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]
/
1000
/
1000
/
60
/
60
/
24
)
*
24
*
60
*
60
*
1000
*
1000
)
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]
/
1000
/
1000
/
60
/
60
/
24
)
*
24
*
60
*
60
*
1000
*
1000
)
elif
unit
.
lower
()
==
'1w'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
ts_result
=
self
.
get_us_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
...
...
@@ -144,21 +145,21 @@ class TDTestCase:
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(
date_time
[
i
]
*
1000
/
1000
/
1000
/
1000
/
60
/
60
)
*
60
*
60
*
1000
*
1000
*
1000
)
elif
unit
.
lower
()
==
'1d'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(
date_time
[
i
]
*
1000
/
1000
/
1000
/
1000
/
60
/
60
/
24
)
*
24
*
60
*
60
*
1000
*
1000
*
1000
)
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(
date_time
[
i
]
*
1000
/
1000
/
1000
/
1000
/
60
/
60
/
24
)
*
24
*
60
*
60
*
1000
*
1000
*
1000
)
elif
unit
.
lower
()
==
'1w'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(
date_time
[
i
]
*
1000
/
1000
/
1000
/
1000
/
60
/
60
/
24
/
7
)
*
7
*
24
*
60
*
60
*
1000
*
1000
*
1000
)
def
data_check
(
self
,
date_time
,
precision
,
tb_type
):
for
unit
in
self
.
time_unit
:
if
(
unit
.
lower
()
==
'1u'
and
precision
.
lower
()
==
'ms'
)
or
()
:
if
tb_type
.
lower
()
==
'ntb'
:
if
tb_type
.
lower
()
==
'ntb'
:
tdSql
.
error
(
f
'select timetruncate(ts,
{
unit
}
) from
{
self
.
ntbname
}
'
)
elif
tb_type
.
lower
()
==
'ctb'
:
tdSql
.
error
(
f
'select timetruncate(ts,
{
unit
}
) from
{
self
.
ctbname
}
'
)
elif
tb_type
.
lower
()
==
'stb'
:
tdSql
.
error
(
f
'select timetruncate(ts,
{
unit
}
) from
{
self
.
stbname
}
'
)
elif
precision
.
lower
()
==
'ms'
:
if
tb_type
.
lower
()
==
'ntb'
:
if
tb_type
.
lower
()
==
'ntb'
:
tdSql
.
query
(
f
'select timetruncate(ts,
{
unit
}
) from
{
self
.
ntbname
}
'
)
elif
tb_type
.
lower
()
==
'ctb'
:
tdSql
.
query
(
f
'select timetruncate(ts,
{
unit
}
) from
{
self
.
ctbname
}
'
)
...
...
@@ -167,7 +168,7 @@ class TDTestCase:
tdSql
.
checkRows
(
len
(
self
.
ts_str
))
self
.
check_ms_timestamp
(
unit
,
date_time
)
elif
precision
.
lower
()
==
'us'
:
if
tb_type
.
lower
()
==
'ntb'
:
if
tb_type
.
lower
()
==
'ntb'
:
tdSql
.
query
(
f
'select timetruncate(ts,
{
unit
}
) from
{
self
.
ntbname
}
'
)
elif
tb_type
.
lower
()
==
'ctb'
:
tdSql
.
query
(
f
'select timetruncate(ts,
{
unit
}
) from
{
self
.
ctbname
}
'
)
...
...
@@ -176,7 +177,7 @@ class TDTestCase:
tdSql
.
checkRows
(
len
(
self
.
ts_str
))
self
.
check_us_timestamp
(
unit
,
date_time
)
elif
precision
.
lower
()
==
'ns'
:
if
tb_type
.
lower
()
==
'ntb'
:
if
tb_type
.
lower
()
==
'ntb'
:
tdSql
.
query
(
f
'select timetruncate(ts,
{
unit
}
) from
{
self
.
ntbname
}
'
)
elif
tb_type
.
lower
()
==
'ctb'
:
tdSql
.
query
(
f
'select timetruncate(ts,
{
unit
}
) from
{
self
.
ctbname
}
'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录