Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
266da48c
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
266da48c
编写于
5月 27, 2022
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(query): fix diff function result type to avoid overflow
TD-16068
上级
1f6c6b11
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
16 addition
and
10 deletion
+16
-10
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+7
-1
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+9
-9
未找到文件。
source/libs/function/src/builtins.c
浏览文件 @
266da48c
...
...
@@ -709,7 +709,13 @@ static int32_t translateDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
pValue
->
notReserved
=
true
;
}
pFunc
->
node
.
resType
=
(
SDataType
){.
bytes
=
tDataTypes
[
colType
].
bytes
,
.
type
=
colType
};
uint8_t
resType
;
if
(
IS_SIGNED_NUMERIC_TYPE
(
colType
))
{
resType
=
TSDB_DATA_TYPE_BIGINT
;
}
else
{
resType
=
TSDB_DATA_TYPE_DOUBLE
;
}
pFunc
->
node
.
resType
=
(
SDataType
){.
bytes
=
tDataTypes
[
resType
].
bytes
,
.
type
=
resType
};
return
TSDB_CODE_SUCCESS
;
}
...
...
source/libs/function/src/builtinsimpl.c
浏览文件 @
266da48c
...
...
@@ -2303,11 +2303,11 @@ static void doHandleDiff(SDiffInfo* pDiffInfo, int32_t type, const char* pv, SCo
switch
(
type
)
{
case
TSDB_DATA_TYPE_INT
:
{
int32_t
v
=
*
(
int32_t
*
)
pv
;
int
32
_t
delta
=
factor
*
(
v
-
pDiffInfo
->
prev
.
i64
);
// direct previous may be null
int
64
_t
delta
=
factor
*
(
v
-
pDiffInfo
->
prev
.
i64
);
// direct previous may be null
if
(
delta
<
0
&&
pDiffInfo
->
ignoreNegative
)
{
colDataSetNull_f
(
pOutput
->
nullbitmap
,
pos
);
}
else
{
colDataAppendInt
32
(
pOutput
,
pos
,
&
delta
);
colDataAppendInt
64
(
pOutput
,
pos
,
&
delta
);
}
pDiffInfo
->
prev
.
i64
=
v
;
break
;
...
...
@@ -2315,22 +2315,22 @@ static void doHandleDiff(SDiffInfo* pDiffInfo, int32_t type, const char* pv, SCo
case
TSDB_DATA_TYPE_BOOL
:
case
TSDB_DATA_TYPE_TINYINT
:
{
int8_t
v
=
*
(
int8_t
*
)
pv
;
int
8
_t
delta
=
factor
*
(
v
-
pDiffInfo
->
prev
.
i64
);
// direct previous may be null
int
64
_t
delta
=
factor
*
(
v
-
pDiffInfo
->
prev
.
i64
);
// direct previous may be null
if
(
delta
<
0
&&
pDiffInfo
->
ignoreNegative
)
{
colDataSetNull_f
(
pOutput
->
nullbitmap
,
pos
);
}
else
{
colDataAppendInt
8
(
pOutput
,
pos
,
&
delta
);
colDataAppendInt
64
(
pOutput
,
pos
,
&
delta
);
}
pDiffInfo
->
prev
.
i64
=
v
;
break
;
}
case
TSDB_DATA_TYPE_SMALLINT
:
{
int16_t
v
=
*
(
int16_t
*
)
pv
;
int
16
_t
delta
=
factor
*
(
v
-
pDiffInfo
->
prev
.
i64
);
// direct previous may be null
int
64
_t
delta
=
factor
*
(
v
-
pDiffInfo
->
prev
.
i64
);
// direct previous may be null
if
(
delta
<
0
&&
pDiffInfo
->
ignoreNegative
)
{
colDataSetNull_f
(
pOutput
->
nullbitmap
,
pos
);
}
else
{
colDataAppendInt
16
(
pOutput
,
pos
,
&
delta
);
colDataAppendInt
64
(
pOutput
,
pos
,
&
delta
);
}
pDiffInfo
->
prev
.
i64
=
v
;
break
;
...
...
@@ -2348,11 +2348,11 @@ static void doHandleDiff(SDiffInfo* pDiffInfo, int32_t type, const char* pv, SCo
}
case
TSDB_DATA_TYPE_FLOAT
:
{
float
v
=
*
(
float
*
)
pv
;
float
delta
=
factor
*
(
v
-
pDiffInfo
->
prev
.
d64
);
// direct previous may be null
double
delta
=
factor
*
(
v
-
pDiffInfo
->
prev
.
d64
);
// direct previous may be null
if
((
delta
<
0
&&
pDiffInfo
->
ignoreNegative
)
||
isinf
(
delta
)
||
isnan
(
delta
))
{
//check for overflow
colDataSetNull_f
(
pOutput
->
nullbitmap
,
pos
);
}
else
{
colDataAppend
Float
(
pOutput
,
pos
,
&
delta
);
colDataAppend
Double
(
pOutput
,
pos
,
&
delta
);
}
pDiffInfo
->
prev
.
d64
=
v
;
break
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录