Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
50beba99
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看板
未验证
提交
50beba99
编写于
6月 10, 2022
作者:
G
Ganlin Zhao
提交者:
GitHub
6月 10, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #13660 from taosdata/enh/elapsed_split
enh(query): enable elapsed function distributed splitting
上级
a4ad2b3f
134ad9fa
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
133 addition
and
0 deletion
+133
-0
include/libs/function/functionMgt.h
include/libs/function/functionMgt.h
+2
-0
source/libs/function/inc/builtinsimpl.h
source/libs/function/inc/builtinsimpl.h
+3
-0
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+82
-0
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+46
-0
未找到文件。
include/libs/function/functionMgt.h
浏览文件 @
50beba99
...
...
@@ -131,6 +131,8 @@ typedef enum EFunctionType {
FUNCTION_TYPE_HISTOGRAM_MERGE
,
FUNCTION_TYPE_HYPERLOGLOG_PARTIAL
,
FUNCTION_TYPE_HYPERLOGLOG_MERGE
,
FUNCTION_TYPE_ELAPSED_PARTIAL
,
FUNCTION_TYPE_ELAPSED_MERGE
,
// user defined funcion
FUNCTION_TYPE_UDF
=
10000
...
...
source/libs/function/inc/builtinsimpl.h
浏览文件 @
50beba99
...
...
@@ -116,7 +116,10 @@ int32_t getSpreadInfoSize();
bool
getElapsedFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
bool
elapsedFunctionSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
);
int32_t
elapsedFunction
(
SqlFunctionCtx
*
pCtx
);
int32_t
elapsedFunctionMerge
(
SqlFunctionCtx
*
pCtx
);
int32_t
elapsedFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
);
int32_t
elapsedPartialFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
);
int32_t
getElapsedInfoSize
();
bool
getHistogramFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
bool
histogramFunctionSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
);
...
...
source/libs/function/src/builtins.c
浏览文件 @
50beba99
...
...
@@ -444,6 +444,64 @@ static int32_t translateElapsed(SFunctionNode* pFunc, char* pErrBuf, int32_t len
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
translateElapsedImpl
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
,
bool
isPartial
)
{
int32_t
numOfParams
=
LIST_LENGTH
(
pFunc
->
pParameterList
);
if
(
isPartial
)
{
if
(
1
!=
numOfParams
&&
2
!=
numOfParams
)
{
return
invaildFuncParaNumErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
uint8_t
paraType
=
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
0
))
->
resType
.
type
;
if
(
TSDB_DATA_TYPE_TIMESTAMP
!=
paraType
)
{
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
// param1
if
(
2
==
numOfParams
)
{
SNode
*
pParamNode1
=
nodesListGetNode
(
pFunc
->
pParameterList
,
1
);
if
(
QUERY_NODE_VALUE
!=
nodeType
(
pParamNode1
))
{
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
SValueNode
*
pValue
=
(
SValueNode
*
)
pParamNode1
;
pValue
->
notReserved
=
true
;
paraType
=
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
1
))
->
resType
.
type
;
if
(
!
IS_INTEGER_TYPE
(
paraType
))
{
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
if
(
pValue
->
datum
.
i
==
0
)
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"ELAPSED function time unit parameter should be greater than db precision"
);
}
}
pFunc
->
node
.
resType
=
(
SDataType
){.
bytes
=
getElapsedInfoSize
()
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
};
}
else
{
if
(
1
!=
numOfParams
)
{
return
invaildFuncParaNumErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
uint8_t
paraType
=
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
0
))
->
resType
.
type
;
if
(
TSDB_DATA_TYPE_BINARY
!=
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
translateElapsedPartial
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
)
{
return
translateElapsedImpl
(
pFunc
,
pErrBuf
,
len
,
true
);
}
static
int32_t
translateElapsedMerge
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
)
{
return
translateElapsedImpl
(
pFunc
,
pErrBuf
,
len
,
false
);
}
static
int32_t
translateLeastSQR
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
)
{
int32_t
numOfParams
=
LIST_LENGTH
(
pFunc
->
pParameterList
);
if
(
3
!=
numOfParams
)
{
...
...
@@ -1468,6 +1526,30 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
getEnvFunc
=
getElapsedFuncEnv
,
.
initFunc
=
elapsedFunctionSetup
,
.
processFunc
=
elapsedFunction
,
.
finalizeFunc
=
elapsedFinalize
,
.
pPartialFunc
=
"_elapsed_partial"
,
.
pMergeFunc
=
"_elapsed_merge"
},
{
.
name
=
"_elapsed_partial"
,
.
type
=
FUNCTION_TYPE_ELAPSED
,
.
classification
=
FUNC_MGT_AGG_FUNC
,
.
dataRequiredFunc
=
statisDataRequired
,
.
translateFunc
=
translateElapsedPartial
,
.
getEnvFunc
=
getElapsedFuncEnv
,
.
initFunc
=
elapsedFunctionSetup
,
.
processFunc
=
elapsedFunction
,
.
finalizeFunc
=
elapsedPartialFinalize
},
{
.
name
=
"_elapsed_merge"
,
.
type
=
FUNCTION_TYPE_ELAPSED
,
.
classification
=
FUNC_MGT_AGG_FUNC
,
.
dataRequiredFunc
=
statisDataRequired
,
.
translateFunc
=
translateElapsedMerge
,
.
getEnvFunc
=
getElapsedFuncEnv
,
.
initFunc
=
elapsedFunctionSetup
,
.
processFunc
=
elapsedFunctionMerge
,
.
finalizeFunc
=
elapsedFinalize
},
{
...
...
source/libs/function/src/builtinsimpl.c
浏览文件 @
50beba99
...
...
@@ -3101,6 +3101,10 @@ int32_t spreadPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
return
pResInfo
->
numOfRes
;
}
int32_t
getElapsedInfoSize
()
{
return
(
int32_t
)
sizeof
(
SElapsedInfo
);
}
bool
getElapsedFuncEnv
(
SFunctionNode
*
UNUSED_PARAM
(
pFunc
),
SFuncExecEnv
*
pEnv
)
{
pEnv
->
calcMemSize
=
sizeof
(
SElapsedInfo
);
return
true
;
...
...
@@ -3202,6 +3206,30 @@ _elapsed_over:
return
TSDB_CODE_SUCCESS
;
}
int32_t
elapsedFunctionMerge
(
SqlFunctionCtx
*
pCtx
)
{
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
SColumnInfoData
*
pCol
=
pInput
->
pData
[
0
];
ASSERT
(
pCol
->
info
.
type
==
TSDB_DATA_TYPE_BINARY
);
SElapsedInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
GET_RES_INFO
(
pCtx
));
int32_t
start
=
pInput
->
startRowIndex
;
char
*
data
=
colDataGetData
(
pCol
,
start
);
SElapsedInfo
*
pInputInfo
=
(
SElapsedInfo
*
)
varDataVal
(
data
);
pInfo
->
timeUnit
=
pInputInfo
->
timeUnit
;
if
(
pInfo
->
min
>
pInputInfo
->
min
)
{
pInfo
->
min
=
pInputInfo
->
min
;
}
if
(
pInfo
->
max
<
pInputInfo
->
max
)
{
pInfo
->
max
=
pInputInfo
->
max
;
}
SET_VAL
(
GET_RES_INFO
(
pCtx
),
1
,
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
;
...
...
@@ -3210,6 +3238,24 @@ int32_t elapsedFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
return
functionFinalize
(
pCtx
,
pBlock
);
}
int32_t
elapsedPartialFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
)
{
SResultRowEntryInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SElapsedInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
GET_RES_INFO
(
pCtx
));
int32_t
resultBytes
=
getElapsedInfoSize
();
char
*
res
=
taosMemoryCalloc
(
resultBytes
+
VARSTR_HEADER_SIZE
,
sizeof
(
char
));
memcpy
(
varDataVal
(
res
),
pInfo
,
resultBytes
);
varDataSetLen
(
res
,
resultBytes
);
int32_t
slotId
=
pCtx
->
pExpr
->
base
.
resSchema
.
slotId
;
SColumnInfoData
*
pCol
=
taosArrayGet
(
pBlock
->
pDataBlock
,
slotId
);
colDataAppend
(
pCol
,
pBlock
->
info
.
rows
,
res
,
false
);
taosMemoryFree
(
res
);
return
pResInfo
->
numOfRes
;
}
int32_t
getHistogramInfoSize
()
{
return
(
int32_t
)
sizeof
(
SHistoFuncInfo
)
+
HISTOGRAM_MAX_BINS_NUM
*
sizeof
(
SHistoFuncBin
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录