Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
977c3fe4
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看板
提交
977c3fe4
编写于
5月 11, 2022
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(query): add state_duration function
上级
46c9e0f1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
91 addition
and
3 deletion
+91
-3
source/libs/function/inc/builtinsimpl.h
source/libs/function/inc/builtinsimpl.h
+1
-0
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+37
-2
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+53
-1
未找到文件。
source/libs/function/inc/builtinsimpl.h
浏览文件 @
977c3fe4
...
...
@@ -92,6 +92,7 @@ int32_t histogramFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
bool
getStateFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
bool
stateFunctionSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
);
int32_t
stateCountFunction
(
SqlFunctionCtx
*
pCtx
);
int32_t
stateDurationFunction
(
SqlFunctionCtx
*
pCtx
);
bool
getSelectivityFuncEnv
(
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
...
...
source/libs/function/src/builtins.c
浏览文件 @
977c3fe4
...
...
@@ -263,7 +263,7 @@ static int32_t translateHistogram(SFunctionNode* pFunc, char* pErrBuf, int32_t l
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
translateState
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
)
{
static
int32_t
translateState
Count
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
)
{
if
(
3
!=
LIST_LENGTH
(
pFunc
->
pParameterList
))
{
return
invaildFuncParaNumErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
...
...
@@ -283,6 +283,31 @@ static int32_t translateState(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
translateStateDuration
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
)
{
int32_t
paraNum
=
LIST_LENGTH
(
pFunc
->
pParameterList
);
if
(
3
!=
paraNum
&&
4
!=
paraNum
)
{
return
invaildFuncParaNumErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
uint8_t
colType
=
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
0
))
->
resType
.
type
;
if
(
!
IS_NUMERIC_TYPE
(
colType
))
{
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
if
(((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
1
))
->
resType
.
type
!=
TSDB_DATA_TYPE_BINARY
||
(((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
2
))
->
resType
.
type
!=
TSDB_DATA_TYPE_BIGINT
&&
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
2
))
->
resType
.
type
!=
TSDB_DATA_TYPE_DOUBLE
))
{
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
if
(
paraNum
==
4
&&
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
3
))
->
resType
.
type
!=
TSDB_DATA_TYPE_BIGINT
)
{
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
pFunc
->
node
.
resType
=
(
SDataType
)
{
.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_BIGINT
].
bytes
,
.
type
=
TSDB_DATA_TYPE_BIGINT
};
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
translateLastRow
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
)
{
// todo
return
TSDB_CODE_SUCCESS
;
...
...
@@ -701,12 +726,22 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
name
=
"state_count"
,
.
type
=
FUNCTION_TYPE_STATE_COUNT
,
.
classification
=
FUNC_MGT_NONSTANDARD_SQL_FUNC
,
.
translateFunc
=
translateState
,
.
translateFunc
=
translateState
Count
,
.
getEnvFunc
=
getStateFuncEnv
,
.
initFunc
=
functionSetup
,
.
processFunc
=
stateCountFunction
,
.
finalizeFunc
=
NULL
},
{
.
name
=
"state_duration"
,
.
type
=
FUNCTION_TYPE_STATE_DURATION
,
.
classification
=
FUNC_MGT_NONSTANDARD_SQL_FUNC
|
FUNC_MGT_TIMELINE_FUNC
,
.
translateFunc
=
translateStateDuration
,
.
getEnvFunc
=
getStateFuncEnv
,
.
initFunc
=
functionSetup
,
.
processFunc
=
stateDurationFunction
,
.
finalizeFunc
=
NULL
},
{
.
name
=
"abs"
,
.
type
=
FUNCTION_TYPE_ABS
,
...
...
source/libs/function/src/builtinsimpl.c
浏览文件 @
977c3fe4
...
...
@@ -125,7 +125,10 @@ typedef enum {
}
EHistoBinType
;
typedef
struct
SStateInfo
{
int64_t
count
;
union
{
int64_t
count
;
int64_t
durationStart
;
};
}
SStateInfo
;
typedef
enum
{
...
...
@@ -2841,3 +2844,52 @@ int32_t stateCountFunction(SqlFunctionCtx* pCtx) {
return
numOfElems
;
}
int32_t
stateDurationFunction
(
SqlFunctionCtx
*
pCtx
)
{
SResultRowEntryInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SStateInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
TSKEY
*
tsList
=
(
int64_t
*
)
pInput
->
pPTS
->
pData
;
SColumnInfoData
*
pInputCol
=
pInput
->
pData
[
0
];
SColumnInfoData
*
pTsOutput
=
pCtx
->
pTsOutput
;
int32_t
numOfElems
=
0
;
SColumnInfoData
*
pOutput
=
(
SColumnInfoData
*
)
pCtx
->
pOutput
;
//TODO: process timeUnit for different db precisions
int32_t
timeUnit
=
1000
;
if
(
pCtx
->
numOfParams
==
5
)
{
//TODO: param number incorrect
timeUnit
=
pCtx
->
param
[
3
].
param
.
i
;
}
int8_t
op
=
getStateOpType
(
varDataVal
(
pCtx
->
param
[
1
].
param
.
pz
));
if
(
STATE_OPER_INVALID
==
op
)
{
return
0
;
}
for
(
int32_t
i
=
pInput
->
startRowIndex
;
i
<
pInput
->
numOfRows
+
pInput
->
startRowIndex
;
i
+=
1
)
{
numOfElems
++
;
if
(
colDataIsNull_f
(
pInputCol
->
nullbitmap
,
i
))
{
colDataAppendNULL
(
pOutput
,
i
);
continue
;
}
bool
ret
=
checkStateOp
(
op
,
pInputCol
,
i
,
pCtx
->
param
[
2
].
param
);
int64_t
output
=
-
1
;
if
(
ret
)
{
if
(
pInfo
->
durationStart
==
0
)
{
output
=
0
;
pInfo
->
durationStart
=
tsList
[
i
];
}
else
{
output
=
(
tsList
[
i
]
-
pInfo
->
durationStart
)
/
timeUnit
;
}
}
else
{
pInfo
->
durationStart
=
0
;
}
colDataAppend
(
pOutput
,
i
,
(
char
*
)
&
output
,
false
);
}
return
numOfElems
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录