Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
71b85039
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
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看板
提交
71b85039
编写于
12月 25, 2021
作者:
S
shenglian zhou
提交者:
shenglian zhou
12月 26, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-InfluxDB2.6]<feature>(query):diff ignore negative
上级
789851ac
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
40 addition
and
2 deletion
+40
-2
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+20
-2
src/query/src/qAggMain.c
src/query/src/qAggMain.c
+20
-0
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
71b85039
...
...
@@ -2668,6 +2668,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
const
char
*
msg14
=
"third parameter algorithm must be 'default' or 't-digest'"
;
const
char
*
msg15
=
"parameter is out of range [1, 1000]"
;
const
char
*
msg16
=
"elapsed duration should be greater than or equal to database precision"
;
const
char
*
msg17
=
"the second paramter of diff should be 0 or 1"
;
switch
(
functionId
)
{
case
TSDB_FUNC_COUNT
:
{
...
...
@@ -2766,9 +2767,11 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
// no parameters or more than one parameter for function
if
(
pItem
->
pNode
->
Expr
.
paramList
==
NULL
||
(
functionId
!=
TSDB_FUNC_LEASTSQR
&&
functionId
!=
TSDB_FUNC_DERIVATIVE
&&
functionId
!=
TSDB_FUNC_ELAPSED
&&
numOfParams
!=
1
)
||
(
functionId
!=
TSDB_FUNC_LEASTSQR
&&
functionId
!=
TSDB_FUNC_DERIVATIVE
&&
functionId
!=
TSDB_FUNC_ELAPSED
&&
functionId
!=
TSDB_FUNC_DIFF
&&
numOfParams
!=
1
)
||
((
functionId
==
TSDB_FUNC_LEASTSQR
||
functionId
==
TSDB_FUNC_DERIVATIVE
)
&&
numOfParams
!=
3
)
||
(
functionId
==
TSDB_FUNC_ELAPSED
&&
numOfParams
!=
1
&&
numOfParams
!=
2
))
{
(
functionId
==
TSDB_FUNC_ELAPSED
&&
numOfParams
!=
1
&&
numOfParams
!=
2
)
||
(
functionId
==
TSDB_FUNC_DIFF
&&
numOfParams
!=
1
&&
numOfParams
!=
2
))
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
...
...
@@ -2883,6 +2886,21 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
tscExprAddParams
(
&
pExpr
->
base
,
val
,
TSDB_DATA_TYPE_BIGINT
,
LONG_BYTES
);
}
}
else
if
(
functionId
==
TSDB_FUNC_DIFF
)
{
char
val
[
8
]
=
{
0
};
if
(
numOfParams
==
2
)
{
tVariant
*
variantDiff
=
&
pParamElem
[
1
].
pNode
->
value
;
if
(
variantDiff
->
nType
!=
TSDB_DATA_TYPE_BIGINT
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
tVariantDump
(
variantDiff
,
val
,
TSDB_DATA_TYPE_BIGINT
,
true
);
int64_t
ignoreNegative
=
GET_INT64_VAL
(
val
);
if
(
ignoreNegative
!=
0
&&
ignoreNegative
!=
1
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg17
);
}
}
tscExprAddParams
(
&
pExpr
->
base
,
val
,
TSDB_DATA_TYPE_BIGINT
,
sizeof
(
int64_t
));
}
SColumnList
ids
=
createColumnList
(
1
,
index
.
tableIndex
,
index
.
columnIndex
);
...
...
src/query/src/qAggMain.c
浏览文件 @
71b85039
...
...
@@ -204,6 +204,7 @@ typedef struct SElapsedInfo {
typedef
struct
{
bool
valueAssigned
;
bool
ignoreNegative
;
union
{
int64_t
i64Prev
;
double
d64Prev
;
...
...
@@ -3025,6 +3026,7 @@ static bool diff_function_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo* pResIn
SDiffFuncInfo
*
pDiffInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
pDiffInfo
->
valueAssigned
=
false
;
pDiffInfo
->
i64Prev
=
0
;
pDiffInfo
->
ignoreNegative
=
(
pCtx
->
param
[
0
].
i64
==
1
)
?
true
:
false
;
return
true
;
}
...
...
@@ -3257,6 +3259,9 @@ static void diff_function(SQLFunctionCtx *pCtx) {
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
pData
[
i
],
pCtx
->
inputType
))
{
continue
;
}
if
((
pDiffInfo
->
ignoreNegative
)
&&
(
pData
[
i
]
<
0
))
{
continue
;
}
if
(
pDiffInfo
->
valueAssigned
)
{
*
pOutput
=
(
int32_t
)(
pData
[
i
]
-
pDiffInfo
->
i64Prev
);
// direct previous may be null
...
...
@@ -3279,6 +3284,9 @@ static void diff_function(SQLFunctionCtx *pCtx) {
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
pData
[
i
],
pCtx
->
inputType
))
{
continue
;
}
if
((
pDiffInfo
->
ignoreNegative
)
&&
(
pData
[
i
]
<
0
))
{
continue
;
}
if
(
pDiffInfo
->
valueAssigned
)
{
*
pOutput
=
pData
[
i
]
-
pDiffInfo
->
i64Prev
;
// direct previous may be null
...
...
@@ -3301,6 +3309,9 @@ static void diff_function(SQLFunctionCtx *pCtx) {
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
pData
[
i
],
pCtx
->
inputType
))
{
continue
;
}
if
((
pDiffInfo
->
ignoreNegative
)
&&
(
pData
[
i
]
<
0
))
{
continue
;
}
if
(
pDiffInfo
->
valueAssigned
)
{
// initial value is not set yet
SET_DOUBLE_VAL
(
pOutput
,
pData
[
i
]
-
pDiffInfo
->
d64Prev
);
// direct previous may be null
...
...
@@ -3323,6 +3334,9 @@ static void diff_function(SQLFunctionCtx *pCtx) {
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
pData
[
i
],
pCtx
->
inputType
))
{
continue
;
}
if
((
pDiffInfo
->
ignoreNegative
)
&&
(
pData
[
i
]
<
0
))
{
continue
;
}
if
(
pDiffInfo
->
valueAssigned
)
{
// initial value is not set yet
*
pOutput
=
(
float
)(
pData
[
i
]
-
pDiffInfo
->
d64Prev
);
// direct previous may be null
...
...
@@ -3345,6 +3359,9 @@ static void diff_function(SQLFunctionCtx *pCtx) {
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
pData
[
i
],
pCtx
->
inputType
))
{
continue
;
}
if
((
pDiffInfo
->
ignoreNegative
)
&&
(
pData
[
i
]
<
0
))
{
continue
;
}
if
(
pDiffInfo
->
valueAssigned
)
{
// initial value is not set yet
*
pOutput
=
(
int16_t
)(
pData
[
i
]
-
pDiffInfo
->
i64Prev
);
// direct previous may be null
...
...
@@ -3368,6 +3385,9 @@ static void diff_function(SQLFunctionCtx *pCtx) {
if
(
pCtx
->
hasNull
&&
isNull
((
char
*
)
&
pData
[
i
],
pCtx
->
inputType
))
{
continue
;
}
if
((
pDiffInfo
->
ignoreNegative
)
&&
(
pData
[
i
]
<
0
))
{
continue
;
}
if
(
pDiffInfo
->
valueAssigned
)
{
// initial value is not set yet
*
pOutput
=
(
int8_t
)(
pData
[
i
]
-
pDiffInfo
->
i64Prev
);
// direct previous may be null
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录