Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e18da31a
T
TDengine
项目概览
taosdata
/
TDengine
11 个月 前同步成功
通知
1179
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,发现更多精彩内容 >>
提交
e18da31a
编写于
12月 05, 2022
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh(query): add timetruncate function ignore timezone option for 1d
上级
302a713f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
65 addition
and
8 deletion
+65
-8
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+21
-3
source/libs/scalar/src/sclfunc.c
source/libs/scalar/src/sclfunc.c
+44
-5
未找到文件。
source/libs/function/src/builtins.c
浏览文件 @
e18da31a
...
...
@@ -1924,7 +1924,8 @@ static int32_t translateToUnixtimestamp(SFunctionNode* pFunc, char* pErrBuf, int
}
static
int32_t
translateTimeTruncate
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
)
{
if
(
2
!=
LIST_LENGTH
(
pFunc
->
pParameterList
))
{
int32_t
numOfParams
=
LIST_LENGTH
(
pFunc
->
pParameterList
);
if
(
2
!=
numOfParams
&&
3
!=
numOfParams
)
{
return
invaildFuncParaNumErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
...
...
@@ -1935,9 +1936,7 @@ static int32_t translateTimeTruncate(SFunctionNode* pFunc, char* pErrBuf, int32_
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
// add database precision as param
uint8_t
dbPrec
=
pFunc
->
node
.
resType
.
precision
;
int32_t
ret
=
validateTimeUnitParam
(
dbPrec
,
(
SValueNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
1
));
if
(
ret
==
TIME_UNIT_TOO_SMALL
)
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
...
...
@@ -1948,11 +1947,30 @@ static int32_t translateTimeTruncate(SFunctionNode* pFunc, char* pErrBuf, int32_
"TIMETRUNCATE function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]"
);
}
if
(
3
==
numOfParams
)
{
uint8_t
para3Type
=
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
2
))
->
resType
.
type
;
if
(
!
IS_INTEGER_TYPE
(
para3Type
))
{
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
SValueNode
*
pValue
=
(
SValueNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
2
);
if
(
pValue
->
datum
.
i
!=
0
&&
pValue
->
datum
.
i
!=
1
)
{
return
invaildFuncParaValueErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
}
// add database precision as param
int32_t
code
=
addDbPrecisonParam
(
&
pFunc
->
pParameterList
,
dbPrec
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
// add client timezone as param
code
=
addTimezoneParam
(
pFunc
->
pParameterList
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
pFunc
->
node
.
resType
=
(
SDataType
){.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_TIMESTAMP
].
bytes
,
.
type
=
TSDB_DATA_TYPE_TIMESTAMP
};
return
TSDB_CODE_SUCCESS
;
...
...
source/libs/scalar/src/sclfunc.c
浏览文件 @
e18da31a
...
...
@@ -1174,12 +1174,35 @@ int32_t toJsonFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
}
/** Time functions **/
static
int64_t
offsetFromTz
(
char
*
timezone
,
int64_t
factor
)
{
char
*
minStr
=
&
timezone
[
3
];
int64_t
minutes
=
taosStr2Int64
(
minStr
,
NULL
,
10
);
memset
(
minStr
,
0
,
strlen
(
minStr
));
int64_t
hours
=
taosStr2Int64
(
timezone
,
NULL
,
10
);
int64_t
seconds
=
hours
*
3600
+
minutes
*
60
;
return
seconds
*
factor
;
}
int32_t
timeTruncateFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
int32_t
type
=
GET_PARAM_TYPE
(
&
pInput
[
0
]);
int64_t
timeUnit
,
timePrec
,
timeVal
=
0
;
bool
ignoreTz
=
true
;
char
timezone
[
20
]
=
{
0
};
GET_TYPED_DATA
(
timeUnit
,
int64_t
,
GET_PARAM_TYPE
(
&
pInput
[
1
]),
pInput
[
1
].
columnData
->
pData
);
GET_TYPED_DATA
(
timePrec
,
int64_t
,
GET_PARAM_TYPE
(
&
pInput
[
2
]),
pInput
[
2
].
columnData
->
pData
);
int32_t
timePrecIdx
=
2
,
timeZoneIdx
=
3
;
if
(
inputNum
==
5
)
{
timePrecIdx
+=
1
;
timeZoneIdx
+=
1
;
GET_TYPED_DATA
(
ignoreTz
,
bool
,
GET_PARAM_TYPE
(
&
pInput
[
2
]),
pInput
[
2
].
columnData
->
pData
);
}
GET_TYPED_DATA
(
timePrec
,
int64_t
,
GET_PARAM_TYPE
(
&
pInput
[
timePrecIdx
]),
pInput
[
timePrecIdx
].
columnData
->
pData
);
memcpy
(
timezone
,
varDataVal
(
pInput
[
timeZoneIdx
].
columnData
->
pData
),
varDataLen
(
pInput
[
timeZoneIdx
].
columnData
->
pData
));
int64_t
factor
=
TSDB_TICK_PER_SECOND
(
timePrec
);
int64_t
unit
=
timeUnit
*
1000
/
factor
;
...
...
@@ -1294,13 +1317,29 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
}
case
86400000
:
{
/* 1d */
if
(
tsDigits
==
TSDB_TIME_PRECISION_MILLI_DIGITS
)
{
timeVal
=
timeVal
/
1000
/
86400
*
86400
*
1000
;
if
(
ignoreTz
)
{
timeVal
=
timeVal
-
(
timeVal
+
offsetFromTz
(
timezone
,
1000
))
%
(
86400L
*
1000
);
}
else
{
timeVal
=
timeVal
/
1000
/
86400
*
86400
*
1000
;
}
}
else
if
(
tsDigits
==
TSDB_TIME_PRECISION_MICRO_DIGITS
)
{
timeVal
=
timeVal
/
1000000
/
86400
*
86400
*
1000000
;
if
(
ignoreTz
)
{
timeVal
=
timeVal
-
(
timeVal
+
offsetFromTz
(
timezone
,
1000000
))
%
(
86400L
*
1000000
);
}
else
{
timeVal
=
timeVal
/
1000000
/
86400
*
86400
*
1000000
;
}
}
else
if
(
tsDigits
==
TSDB_TIME_PRECISION_NANO_DIGITS
)
{
timeVal
=
timeVal
/
1000000000
/
86400
*
86400
*
1000000000
;
if
(
ignoreTz
)
{
timeVal
=
timeVal
-
(
timeVal
+
offsetFromTz
(
timezone
,
1000000000
))
%
(
86400L
*
1000000000
);
}
else
{
timeVal
=
timeVal
/
1000000000
/
86400
*
86400
*
1000000000
;
}
}
else
if
(
tsDigits
<=
TSDB_TIME_PRECISION_SEC_DIGITS
)
{
timeVal
=
timeVal
*
factor
/
factor
/
86400
*
86400
*
factor
;
if
(
ignoreTz
)
{
timeVal
=
(
timeVal
-
(
timeVal
+
offsetFromTz
(
timezone
,
1
))
%
(
86400L
))
*
factor
;
}
else
{
timeVal
=
timeVal
*
factor
/
factor
/
86400
*
86400
*
factor
;
}
}
else
{
colDataAppendNULL
(
pOutput
->
columnData
,
i
);
continue
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录