Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
be88d802
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,发现更多精彩内容 >>
提交
be88d802
编写于
6月 10, 2022
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh(query): refactor function merge code to provide common interface
上级
797cde53
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
82 addition
and
71 deletion
+82
-71
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+82
-71
未找到文件。
source/libs/function/src/builtinsimpl.c
浏览文件 @
be88d802
...
...
@@ -2103,70 +2103,65 @@ 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
;
static
void
apercentileTransferInfo
(
SAPercentileInfo
*
pInput
,
SAPercentileInfo
*
pOutput
)
{
pOutput
->
percent
=
pInput
->
percent
;
pOutput
->
algo
=
pInput
->
algo
;
if
(
pOutput
->
algo
==
APERCT_ALGO_TDIGEST
)
{
buildTDigestInfo
(
pInput
);
tdigestAutoFill
(
pInput
->
pTDigest
,
COMPRESSION
);
SColumnInfoData
*
pCol
=
pInput
->
pData
[
0
];
ASSERT
(
pCol
->
info
.
type
==
TSDB_DATA_TYPE_BINARY
);
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
);
}
pInfo
->
percent
=
pInputInfo
->
percent
;
pInfo
->
algo
=
pInputInfo
->
algo
;
if
(
pInfo
->
algo
==
APERCT_ALGO_TDIGEST
)
{
buildTDigestInfo
(
pInputInfo
);
tdigestAutoFill
(
pInputInfo
->
pTDigest
,
COMPRESSION
);
if
(
pInputInfo
->
pTDigest
->
num_centroids
==
0
&&
pInputInfo
->
pTDigest
->
num_buffered_pts
==
0
)
{
return
TSDB_CODE_SUCCESS
;
if
(
pInput
->
pTDigest
->
num_centroids
==
0
&&
pInput
->
pTDigest
->
num_buffered_pts
==
0
)
{
return
;
}
buildTDigestInfo
(
p
Info
);
TDigest
*
pTDigest
=
p
Info
->
pTDigest
;
buildTDigestInfo
(
p
Output
);
TDigest
*
pTDigest
=
p
Output
->
pTDigest
;
if
(
pTDigest
->
num_centroids
<=
0
)
{
memcpy
(
pTDigest
,
pInput
Info
->
pTDigest
,
(
size_t
)
TDIGEST_SIZE
(
COMPRESSION
));
memcpy
(
pTDigest
,
pInput
->
pTDigest
,
(
size_t
)
TDIGEST_SIZE
(
COMPRESSION
));
tdigestAutoFill
(
pTDigest
,
COMPRESSION
);
}
else
{
tdigestMerge
(
pTDigest
,
pInput
Info
->
pTDigest
);
tdigestMerge
(
pTDigest
,
pInput
->
pTDigest
);
}
}
else
{
buildHistogramInfo
(
pInput
Info
);
if
(
pInput
Info
->
pHisto
->
numOfElems
<=
0
)
{
return
TSDB_CODE_SUCCESS
;
buildHistogramInfo
(
pInput
);
if
(
pInput
->
pHisto
->
numOfElems
<=
0
)
{
return
;
}
buildHistogramInfo
(
p
Info
);
SHistogramInfo
*
pHisto
=
p
Info
->
pHisto
;
buildHistogramInfo
(
p
Output
);
SHistogramInfo
*
pHisto
=
p
Output
->
pHisto
;
if
(
pHisto
->
numOfElems
<=
0
)
{
memcpy
(
pHisto
,
pInput
Info
->
pHisto
,
sizeof
(
SHistogramInfo
)
+
sizeof
(
SHistBin
)
*
(
MAX_HISTOGRAM_BIN
+
1
));
memcpy
(
pHisto
,
pInput
->
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
,
pInput
Info
->
pHisto
,
MAX_HISTOGRAM_BIN
);
SHistogramInfo
*
pRes
=
tHistogramMerge
(
pHisto
,
pInput
->
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
);
int32_t
apercentileFunctionMerge
(
SqlFunctionCtx
*
pCtx
)
{
SResultRowEntryInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
SColumnInfoData
*
pCol
=
pInput
->
pData
[
0
];
ASSERT
(
pCol
->
info
.
type
==
TSDB_DATA_TYPE_BINARY
);
SAPercentileInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
int32_t
start
=
pInput
->
startRowIndex
;
char
*
data
=
colDataGetData
(
pCol
,
start
);
SAPercentileInfo
*
pInputInfo
=
(
SAPercentileInfo
*
)
varDataVal
(
data
);
apercentileTransferInfo
(
pInputInfo
,
pInfo
);
SET_VAL
(
pResInfo
,
1
,
1
);
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -3049,6 +3044,17 @@ _spread_over:
return
TSDB_CODE_SUCCESS
;
}
static
void
spreadTransferInfo
(
SSpreadInfo
*
pInput
,
SSpreadInfo
*
pOutput
)
{
pOutput
->
hasResult
=
pInput
->
hasResult
;
if
(
pInput
->
max
>
pOutput
->
max
)
{
pOutput
->
max
=
pInput
->
max
;
}
if
(
pInput
->
min
<
pOutput
->
min
)
{
pOutput
->
min
=
pInput
->
min
;
}
}
int32_t
spreadFunctionMerge
(
SqlFunctionCtx
*
pCtx
)
{
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
SColumnInfoData
*
pCol
=
pInput
->
pData
[
0
];
...
...
@@ -3061,14 +3067,7 @@ int32_t spreadFunctionMerge(SqlFunctionCtx *pCtx) {
char
*
data
=
colDataGetData
(
pCol
,
start
);
pInputInfo
=
(
SSpreadInfo
*
)
varDataVal
(
data
);
pInfo
->
hasResult
=
pInputInfo
->
hasResult
;
if
(
pInputInfo
->
max
>
pInfo
->
max
)
{
pInfo
->
max
=
pInputInfo
->
max
;
}
if
(
pInputInfo
->
min
<
pInfo
->
min
)
{
pInfo
->
min
=
pInputInfo
->
min
;
}
spreadTransferInfo
(
pInputInfo
,
pInfo
);
SET_VAL
(
GET_RES_INFO
(
pCtx
),
1
,
1
);
...
...
@@ -3206,6 +3205,17 @@ _elapsed_over:
return
TSDB_CODE_SUCCESS
;
}
static
void
elapsedTransferInfo
(
SElapsedInfo
*
pInput
,
SElapsedInfo
*
pOutput
)
{
pOutput
->
timeUnit
=
pInput
->
timeUnit
;
if
(
pOutput
->
min
>
pInput
->
min
)
{
pOutput
->
min
=
pInput
->
min
;
}
if
(
pOutput
->
max
<
pInput
->
max
)
{
pOutput
->
max
=
pInput
->
max
;
}
}
int32_t
elapsedFunctionMerge
(
SqlFunctionCtx
*
pCtx
)
{
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
SColumnInfoData
*
pCol
=
pInput
->
pData
[
0
];
...
...
@@ -3217,14 +3227,7 @@ int32_t elapsedFunctionMerge(SqlFunctionCtx *pCtx) {
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
;
}
elapsedTransferInfo
(
pInputInfo
,
pInfo
);
SET_VAL
(
GET_RES_INFO
(
pCtx
),
1
,
1
);
return
TSDB_CODE_SUCCESS
;
...
...
@@ -3470,6 +3473,17 @@ int32_t histogramFunction(SqlFunctionCtx *pCtx) {
return
TSDB_CODE_SUCCESS
;
}
static
void
histogramTransferInfo
(
SHistoFuncInfo
*
pInput
,
SHistoFuncInfo
*
pOutput
)
{
pOutput
->
normalized
=
pInput
->
normalized
;
pOutput
->
numOfBins
=
pInput
->
numOfBins
;
pOutput
->
totalCount
+=
pInput
->
totalCount
;
for
(
int32_t
k
=
0
;
k
<
pOutput
->
numOfBins
;
++
k
)
{
pOutput
->
bins
[
k
].
lower
=
pInput
->
bins
[
k
].
lower
;
pOutput
->
bins
[
k
].
upper
=
pInput
->
bins
[
k
].
upper
;
pOutput
->
bins
[
k
].
count
+=
pInput
->
bins
[
k
].
count
;
}
}
int32_t
histogramFunctionMerge
(
SqlFunctionCtx
*
pCtx
)
{
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
SColumnInfoData
*
pCol
=
pInput
->
pData
[
0
];
...
...
@@ -3481,14 +3495,7 @@ int32_t histogramFunctionMerge(SqlFunctionCtx *pCtx) {
char
*
data
=
colDataGetData
(
pCol
,
start
);
SHistoFuncInfo
*
pInputInfo
=
(
SHistoFuncInfo
*
)
varDataVal
(
data
);
pInfo
->
normalized
=
pInputInfo
->
normalized
;
pInfo
->
numOfBins
=
pInputInfo
->
numOfBins
;
pInfo
->
totalCount
+=
pInputInfo
->
totalCount
;
for
(
int32_t
k
=
0
;
k
<
pInfo
->
numOfBins
;
++
k
)
{
pInfo
->
bins
[
k
].
lower
=
pInputInfo
->
bins
[
k
].
lower
;
pInfo
->
bins
[
k
].
upper
=
pInputInfo
->
bins
[
k
].
upper
;
pInfo
->
bins
[
k
].
count
+=
pInputInfo
->
bins
[
k
].
count
;
}
histogramTransferInfo
(
pInputInfo
,
pInfo
);
SET_VAL
(
GET_RES_INFO
(
pCtx
),
pInfo
->
numOfBins
,
pInfo
->
numOfBins
);
return
TSDB_CODE_SUCCESS
;
...
...
@@ -3676,6 +3683,14 @@ int32_t hllFunction(SqlFunctionCtx *pCtx) {
return
TSDB_CODE_SUCCESS
;
}
static
void
hllTransferInfo
(
SHLLInfo
*
pInput
,
SHLLInfo
*
pOutput
)
{
for
(
int32_t
k
=
0
;
k
<
HLL_BUCKETS
;
++
k
)
{
if
(
pOutput
->
buckets
[
k
]
<
pInput
->
buckets
[
k
])
{
pOutput
->
buckets
[
k
]
=
pInput
->
buckets
[
k
];
}
}
}
int32_t
hllFunctionMerge
(
SqlFunctionCtx
*
pCtx
)
{
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
SColumnInfoData
*
pCol
=
pInput
->
pData
[
0
];
...
...
@@ -3687,11 +3702,7 @@ int32_t hllFunctionMerge(SqlFunctionCtx *pCtx) {
char
*
data
=
colDataGetData
(
pCol
,
start
);
SHLLInfo
*
pInputInfo
=
(
SHLLInfo
*
)
varDataVal
(
data
);
for
(
int32_t
k
=
0
;
k
<
HLL_BUCKETS
;
++
k
)
{
if
(
pInfo
->
buckets
[
k
]
<
pInputInfo
->
buckets
[
k
])
{
pInfo
->
buckets
[
k
]
=
pInputInfo
->
buckets
[
k
];
}
}
hllTransferInfo
(
pInputInfo
,
pInfo
);
SET_VAL
(
GET_RES_INFO
(
pCtx
),
1
,
1
);
return
TSDB_CODE_SUCCESS
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录