Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
dff653ed
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看板
提交
dff653ed
编写于
6月 07, 2022
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add apercentile distributed spliting
上级
49b277e6
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
113 addition
and
7 deletion
+113
-7
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+61
-6
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+52
-1
未找到文件。
source/libs/function/src/builtins.c
浏览文件 @
dff653ed
...
...
@@ -205,7 +205,7 @@ static bool validateApercentileAlgo(const SValueNode* pVal) {
0
==
strcasecmp
(
varDataVal
(
pVal
->
datum
.
p
),
"t-digest"
));
}
static
int32_t
translateApercentile
Impl
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
,
bool
isPartial
)
{
static
int32_t
translateApercentile
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
)
{
int32_t
numOfParams
=
LIST_LENGTH
(
pFunc
->
pParameterList
);
if
(
2
!=
numOfParams
&&
3
!=
numOfParams
)
{
return
invaildFuncParaNumErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
...
...
@@ -247,11 +247,66 @@ static int32_t translateApercentileImpl(SFunctionNode* pFunc, char* pErrBuf, int
pValue
->
notReserved
=
true
;
}
if
(
!
isPartial
)
{
pFunc
->
node
.
resType
=
(
SDataType
){.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_DOUBLE
].
bytes
,
.
type
=
TSDB_DATA_TYPE_DOUBLE
};
pFunc
->
node
.
resType
=
(
SDataType
){.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_DOUBLE
].
bytes
,
.
type
=
TSDB_DATA_TYPE_DOUBLE
};
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
translateApercentileImpl
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
,
bool
isPartial
)
{
int32_t
numOfParams
=
LIST_LENGTH
(
pFunc
->
pParameterList
);
if
(
isPartial
)
{
if
(
2
!=
numOfParams
&&
3
!=
numOfParams
)
{
return
invaildFuncParaNumErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
// param1
SNode
*
pParamNode1
=
nodesListGetNode
(
pFunc
->
pParameterList
,
1
);
if
(
nodeType
(
pParamNode1
)
!=
QUERY_NODE_VALUE
)
{
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
SValueNode
*
pValue
=
(
SValueNode
*
)
pParamNode1
;
if
(
pValue
->
datum
.
i
<
0
||
pValue
->
datum
.
i
>
100
)
{
return
invaildFuncParaValueErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
pValue
->
notReserved
=
true
;
uint8_t
para1Type
=
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
0
))
->
resType
.
type
;
uint8_t
para2Type
=
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
1
))
->
resType
.
type
;
if
(
!
IS_NUMERIC_TYPE
(
para1Type
)
||
!
IS_INTEGER_TYPE
(
para2Type
))
{
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
// param2
if
(
3
==
numOfParams
)
{
uint8_t
para3Type
=
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
2
))
->
resType
.
type
;
if
(
!
IS_VAR_DATA_TYPE
(
para3Type
))
{
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
SNode
*
pParamNode2
=
nodesListGetNode
(
pFunc
->
pParameterList
,
2
);
if
(
QUERY_NODE_VALUE
!=
nodeType
(
pParamNode2
)
||
!
validateApercentileAlgo
((
SValueNode
*
)
pParamNode2
))
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"Third parameter algorithm of apercentile must be 'default' or 't-digest'"
);
}
pValue
=
(
SValueNode
*
)
pParamNode2
;
pValue
->
notReserved
=
true
;
}
pFunc
->
node
.
resType
=
(
SDataType
){.
bytes
=
getApercentileMaxSize
()
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
};
}
else
{
pFunc
->
node
.
resType
=
(
SDataType
){.
bytes
=
1000
,
.
type
=
TSDB_DATA_TYPE_BINARY
};
if
(
1
!=
numOfParams
)
{
return
invaildFuncParaNumErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
uint8_t
para1Type
=
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
0
))
->
resType
.
type
;
if
(
!
IS_NUMERIC_TYPE
(
para1Type
))
{
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
;
}
...
...
@@ -1164,7 +1219,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
name
=
"apercentile"
,
.
type
=
FUNCTION_TYPE_APERCENTILE
,
.
classification
=
FUNC_MGT_AGG_FUNC
,
.
translateFunc
=
translateApercentile
Final
,
.
translateFunc
=
translateApercentile
,
.
getEnvFunc
=
getApercentileFuncEnv
,
.
initFunc
=
apercentileFunctionSetup
,
.
processFunc
=
apercentileFunction
,
...
...
@@ -1188,7 +1243,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
classification
=
FUNC_MGT_AGG_FUNC
,
.
translateFunc
=
translateApercentileFinal
,
.
getEnvFunc
=
getApercentileFuncEnv
,
.
initFunc
=
apercentileFunctionSetup
,
.
initFunc
=
NULL
,
//
apercentileFunctionSetup,
.
processFunc
=
apercentileFunction
,
.
finalizeFunc
=
apercentileFinalize
},
...
...
source/libs/function/src/builtinsimpl.c
浏览文件 @
dff653ed
...
...
@@ -2047,6 +2047,55 @@ int32_t apercentileFunction(SqlFunctionCtx* pCtx) {
return
TSDB_CODE_SUCCESS
;
}
int32_t
apercentileFunctionMerge
(
SqlFunctionCtx
*
pCtx
)
{
int32_t
numOfElems
=
0
;
SResultRowEntryInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
SColumnInfoData
*
pCol
=
pInput
->
pData
[
0
];
int32_t
type
=
pCol
->
info
.
type
;
SAPercentileInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
SAPercentileInfo
*
pInputInfo
;
int32_t
start
=
pInput
->
startRowIndex
;
for
(
int32_t
i
=
start
;
i
<
pInput
->
numOfRows
+
start
;
++
i
)
{
//if (colDataIsNull_s(pCol, i)) {
// continue;
//}
numOfElems
+=
1
;
char
*
data
=
colDataGetData
(
pCol
,
i
);
pInputInfo
=
(
SAPercentileInfo
*
)
varDataVal
(
data
);
}
if
(
pInfo
->
algo
==
APERCT_ALGO_TDIGEST
)
{
}
else
{
buildHistogramInfo
(
pInputInfo
);
if
(
pInputInfo
->
pHisto
->
numOfElems
<=
0
)
{
return
TSDB_CODE_SUCCESS
;
}
buildHistogramInfo
(
pInfo
);
SHistogramInfo
*
pHisto
=
pInfo
->
pHisto
;
if
(
pHisto
->
numOfElems
<=
0
)
{
memcpy
(
pHisto
,
pInputInfo
->
pHisto
,
sizeof
(
SHistogramInfo
)
+
sizeof
(
SHistBin
)
*
(
MAX_HISTOGRAM_BIN
+
1
));
pHisto
->
elems
=
(
SHistBin
*
)
((
char
*
)
pHisto
+
sizeof
(
SHistogramInfo
));
}
else
{
pHisto
->
elems
=
(
SHistBin
*
)
((
char
*
)
pHisto
+
sizeof
(
SHistogramInfo
));
SHistogramInfo
*
pRes
=
tHistogramMerge
(
pHisto
,
pInputInfo
->
pHisto
,
MAX_HISTOGRAM_BIN
);
memcpy
(
pHisto
,
pRes
,
sizeof
(
SHistogramInfo
)
+
sizeof
(
SHistBin
)
*
MAX_HISTOGRAM_BIN
);
pHisto
->
elems
=
(
SHistBin
*
)
((
char
*
)
pHisto
+
sizeof
(
SHistogramInfo
));
tHistogramDestroy
(
&
pRes
);
}
}
SET_VAL
(
pResInfo
,
numOfElems
,
1
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
apercentileFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
)
{
SVariant
*
pVal
=
&
pCtx
->
param
[
1
].
param
;
double
percent
=
(
pVal
->
nType
==
TSDB_DATA_TYPE_BIGINT
)
?
pVal
->
i
:
pVal
->
d
;
...
...
@@ -2091,13 +2140,15 @@ int32_t apercentilePartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
if
(
pInfo
->
algo
==
APERCT_ALGO_TDIGEST
)
{
if
(
pInfo
->
pTDigest
->
size
>
0
)
{
memcpy
(
varDataVal
(
tmp
),
pInfo
->
pTDigest
,
resultBytes
);
memcpy
(
varDataVal
(
tmp
),
pInfo
,
resultBytes
);
varDataSetLen
(
tmp
,
resultBytes
);
}
else
{
return
TSDB_CODE_SUCCESS
;
}
}
else
{
if
(
pInfo
->
pHisto
->
numOfElems
>
0
)
{
memcpy
(
varDataVal
(
tmp
),
pInfo
->
pHisto
,
resultBytes
);
varDataSetLen
(
tmp
,
resultBytes
);
}
else
{
return
TSDB_CODE_SUCCESS
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录