Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
2f128fa3
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1181
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,发现更多精彩内容 >>
未验证
提交
2f128fa3
编写于
5月 17, 2022
作者:
G
Ganlin Zhao
提交者:
GitHub
5月 17, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #12607 from taosdata/feature/3.0_glzhao
feat(query): add elapsed function
上级
5bf01ca2
1b0b410f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
154 addition
and
0 deletion
+154
-0
source/libs/function/inc/builtinsimpl.h
source/libs/function/inc/builtinsimpl.h
+5
-0
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+32
-0
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+117
-0
未找到文件。
source/libs/function/inc/builtinsimpl.h
浏览文件 @
2f128fa3
...
...
@@ -85,6 +85,11 @@ bool spreadFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo)
int32_t
spreadFunction
(
SqlFunctionCtx
*
pCtx
);
int32_t
spreadFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
);
bool
getElapsedFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
bool
elapsedFunctionSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
);
int32_t
elapsedFunction
(
SqlFunctionCtx
*
pCtx
);
int32_t
elapsedFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
);
bool
getHistogramFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
bool
histogramFunctionSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
);
int32_t
histogramFunction
(
SqlFunctionCtx
*
pCtx
);
...
...
source/libs/function/src/builtins.c
浏览文件 @
2f128fa3
...
...
@@ -226,6 +226,27 @@ static int32_t translateSpread(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
translateElapsed
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
)
{
int32_t
paraNum
=
LIST_LENGTH
(
pFunc
->
pParameterList
);
if
(
1
!=
paraNum
&&
2
!=
paraNum
)
{
return
invaildFuncParaNumErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
SNode
*
pPara
=
nodesListGetNode
(
pFunc
->
pParameterList
,
0
);
if
(
QUERY_NODE_COLUMN
!=
nodeType
(
pPara
))
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"The input parameter of ELAPSED function can only be column"
);
}
uint8_t
paraType
=
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
0
))
->
resType
.
type
;
if
(
TSDB_DATA_TYPE_TIMESTAMP
!=
paraType
)
{
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
pFunc
->
node
.
resType
=
(
SDataType
){.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_DOUBLE
].
bytes
,
.
type
=
TSDB_DATA_TYPE_DOUBLE
};
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
translateLeastSQR
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
)
{
int32_t
numOfParams
=
LIST_LENGTH
(
pFunc
->
pParameterList
);
if
(
3
!=
numOfParams
)
{
...
...
@@ -794,6 +815,17 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
processFunc
=
spreadFunction
,
.
finalizeFunc
=
spreadFinalize
},
{
.
name
=
"elapsed"
,
.
type
=
FUNCTION_TYPE_ELAPSED
,
.
classification
=
FUNC_MGT_AGG_FUNC
,
.
dataRequiredFunc
=
statisDataRequired
,
.
translateFunc
=
translateElapsed
,
.
getEnvFunc
=
getElapsedFuncEnv
,
.
initFunc
=
elapsedFunctionSetup
,
.
processFunc
=
elapsedFunction
,
.
finalizeFunc
=
elapsedFinalize
},
{
.
name
=
"last_row"
,
.
type
=
FUNCTION_TYPE_LAST_ROW
,
...
...
source/libs/function/src/builtinsimpl.c
浏览文件 @
2f128fa3
...
...
@@ -112,6 +112,13 @@ typedef struct SSpreadInfo {
double
max
;
}
SSpreadInfo
;
typedef
struct
SElapsedInfo
{
double
result
;
TSKEY
min
;
TSKEY
max
;
int64_t
timeUnit
;
}
SElapsedInfo
;
typedef
struct
SHistoFuncBin
{
double
lower
;
double
upper
;
...
...
@@ -2494,6 +2501,116 @@ int32_t spreadFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
return
functionFinalize
(
pCtx
,
pBlock
);
}
bool
getElapsedFuncEnv
(
SFunctionNode
*
UNUSED_PARAM
(
pFunc
),
SFuncExecEnv
*
pEnv
)
{
pEnv
->
calcMemSize
=
sizeof
(
SElapsedInfo
);
return
true
;
}
bool
elapsedFunctionSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
)
{
if
(
!
functionSetup
(
pCtx
,
pResultInfo
))
{
return
false
;
}
SElapsedInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResultInfo
);
pInfo
->
result
=
0
;
pInfo
->
min
=
MAX_TS_KEY
;
pInfo
->
max
=
0
;
if
(
pCtx
->
numOfParams
==
3
)
{
pInfo
->
timeUnit
=
pCtx
->
param
[
1
].
param
.
i
;
}
else
{
pInfo
->
timeUnit
=
1
;
}
return
true
;
}
int32_t
elapsedFunction
(
SqlFunctionCtx
*
pCtx
)
{
int32_t
numOfElems
=
0
;
// Only the pre-computing information loaded and actual data does not loaded
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
SColumnDataAgg
*
pAgg
=
pInput
->
pColumnDataAgg
[
0
];
SElapsedInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
GET_RES_INFO
(
pCtx
));
numOfElems
=
pInput
->
numOfRows
;
//since this is the primary timestamp, no need to exclude NULL values
if
(
numOfElems
==
0
)
{
goto
_elapsed_over
;
}
if
(
pInput
->
colDataAggIsSet
)
{
if
(
pInfo
->
min
==
MAX_TS_KEY
)
{
pInfo
->
min
=
GET_INT64_VAL
(
&
pAgg
->
min
);
pInfo
->
max
=
GET_INT64_VAL
(
&
pAgg
->
max
);
}
else
{
if
(
pCtx
->
order
==
TSDB_ORDER_ASC
)
{
pInfo
->
max
=
GET_INT64_VAL
(
&
pAgg
->
max
);
}
else
{
pInfo
->
min
=
GET_INT64_VAL
(
&
pAgg
->
min
);
}
}
}
else
{
// computing based on the true data block
if
(
0
==
pCtx
->
size
)
{
if
(
pCtx
->
order
==
TSDB_ORDER_DESC
)
{
if
(
pCtx
->
end
.
key
!=
INT64_MIN
)
{
pInfo
->
min
=
pCtx
->
end
.
key
;
}
}
else
{
if
(
pCtx
->
end
.
key
!=
INT64_MIN
)
{
pInfo
->
max
=
pCtx
->
end
.
key
+
1
;
}
}
goto
_elapsed_over
;
}
SColumnInfoData
*
pCol
=
pInput
->
pData
[
0
];
int32_t
start
=
pInput
->
startRowIndex
;
TSKEY
*
ptsList
=
(
int64_t
*
)
colDataGetData
(
pCol
,
start
);
if
(
pCtx
->
order
==
TSDB_ORDER_DESC
)
{
if
(
pCtx
->
start
.
key
==
INT64_MIN
)
{
pInfo
->
max
=
(
pInfo
->
max
<
ptsList
[
pCtx
->
size
-
1
])
?
ptsList
[
pCtx
->
size
-
1
]
:
pInfo
->
max
;
}
else
{
pInfo
->
max
=
pCtx
->
start
.
key
+
1
;
}
if
(
pCtx
->
end
.
key
!=
INT64_MIN
)
{
pInfo
->
min
=
pCtx
->
end
.
key
;
}
else
{
pInfo
->
min
=
ptsList
[
0
];
}
}
else
{
if
(
pCtx
->
start
.
key
==
INT64_MIN
)
{
pInfo
->
min
=
(
pInfo
->
min
>
ptsList
[
0
])
?
ptsList
[
0
]
:
pInfo
->
min
;
}
else
{
pInfo
->
min
=
pCtx
->
start
.
key
;
}
if
(
pCtx
->
end
.
key
!=
INT64_MIN
)
{
pInfo
->
max
=
pCtx
->
end
.
key
+
1
;
}
else
{
pInfo
->
max
=
ptsList
[
pCtx
->
size
-
1
];
}
}
}
_elapsed_over:
// data in the check operation are all null, not output
SET_VAL
(
GET_RES_INFO
(
pCtx
),
numOfElems
,
1
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
elapsedFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
)
{
SElapsedInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
GET_RES_INFO
(
pCtx
));
double
result
=
(
double
)
pInfo
->
max
-
(
double
)
pInfo
->
min
;
result
=
(
result
>=
0
)
?
result
:
-
result
;
pInfo
->
result
=
result
/
pInfo
->
timeUnit
;
return
functionFinalize
(
pCtx
,
pBlock
);
}
bool
getHistogramFuncEnv
(
SFunctionNode
*
UNUSED_PARAM
(
pFunc
),
SFuncExecEnv
*
pEnv
)
{
pEnv
->
calcMemSize
=
sizeof
(
SHistoFuncInfo
)
+
HISTOGRAM_MAX_BINS_NUM
*
sizeof
(
SHistoFuncBin
);
return
true
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录