Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
68d33b16
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看板
提交
68d33b16
编写于
6月 14, 2022
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add stddev function partial/merge
上级
cd94eabc
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
55 addition
and
1 deletion
+55
-1
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+55
-1
未找到文件。
source/libs/function/src/builtinsimpl.c
浏览文件 @
68d33b16
...
@@ -89,6 +89,7 @@ typedef struct SStddevRes {
...
@@ -89,6 +89,7 @@ typedef struct SStddevRes {
double
dsum
;
double
dsum
;
int64_t
isum
;
int64_t
isum
;
};
};
int16_t
type
;
}
SStddevRes
;
}
SStddevRes
;
typedef
struct
SLeastSQRInfo
{
typedef
struct
SLeastSQRInfo
{
...
@@ -1513,6 +1514,7 @@ int32_t stddevFunction(SqlFunctionCtx* pCtx) {
...
@@ -1513,6 +1514,7 @@ int32_t stddevFunction(SqlFunctionCtx* pCtx) {
int32_t
type
=
pInput
->
pData
[
0
]
->
info
.
type
;
int32_t
type
=
pInput
->
pData
[
0
]
->
info
.
type
;
SStddevRes
*
pStddevRes
=
GET_ROWCELL_INTERBUF
(
GET_RES_INFO
(
pCtx
));
SStddevRes
*
pStddevRes
=
GET_ROWCELL_INTERBUF
(
GET_RES_INFO
(
pCtx
));
pStddevRes
->
type
=
type
;
// computing based on the true data block
// computing based on the true data block
SColumnInfoData
*
pCol
=
pInput
->
pData
[
0
];
SColumnInfoData
*
pCol
=
pInput
->
pData
[
0
];
...
@@ -1629,6 +1631,39 @@ _stddev_over:
...
@@ -1629,6 +1631,39 @@ _stddev_over:
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
void
stddevTransferInfo
(
SStddevRes
*
pInput
,
SStddevRes
*
pOutput
)
{
pOutput
->
type
=
pInput
->
type
;
if
(
IS_INTEGER_TYPE
(
pOutput
->
type
))
{
pOutput
->
quadraticISum
+=
pInput
->
quadraticISum
;
pOutput
->
isum
+=
pInput
->
isum
;
}
else
{
pOutput
->
quadraticDSum
+=
pInput
->
quadraticDSum
;
pOutput
->
dsum
+=
pInput
->
dsum
;
}
pOutput
->
count
+=
pInput
->
count
;
return
;
}
int32_t
stddevFunctionMerge
(
SqlFunctionCtx
*
pCtx
)
{
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
SColumnInfoData
*
pCol
=
pInput
->
pData
[
0
];
ASSERT
(
pCol
->
info
.
type
==
TSDB_DATA_TYPE_BINARY
);
SStddevRes
*
pInfo
=
GET_ROWCELL_INTERBUF
(
GET_RES_INFO
(
pCtx
));
int32_t
start
=
pInput
->
startRowIndex
;
char
*
data
=
colDataGetData
(
pCol
,
start
);
SStddevRes
*
pInputInfo
=
(
SStddevRes
*
)
varDataVal
(
data
);
stddevTransferInfo
(
pInputInfo
,
pInfo
);
SET_VAL
(
GET_RES_INFO
(
pCtx
),
1
,
1
);
return
TSDB_CODE_SUCCESS
;
}
#define LIST_STDDEV_SUB_N(sumT, T) \
#define LIST_STDDEV_SUB_N(sumT, T) \
do { \
do { \
T* plist = (T*)pCol->pData; \
T* plist = (T*)pCol->pData; \
...
@@ -1694,9 +1729,10 @@ int32_t stddevInvertFunction(SqlFunctionCtx* pCtx) {
...
@@ -1694,9 +1729,10 @@ int32_t stddevInvertFunction(SqlFunctionCtx* pCtx) {
int32_t
stddevFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
)
{
int32_t
stddevFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
)
{
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
int32_t
type
=
pInput
->
pData
[
0
]
->
info
.
type
;
SStddevRes
*
pStddevRes
=
GET_ROWCELL_INTERBUF
(
GET_RES_INFO
(
pCtx
));
SStddevRes
*
pStddevRes
=
GET_ROWCELL_INTERBUF
(
GET_RES_INFO
(
pCtx
));
int32_t
type
=
pStddevRes
->
type
;
double
avg
;
double
avg
;
if
(
IS_INTEGER_TYPE
(
type
))
{
if
(
IS_INTEGER_TYPE
(
type
))
{
avg
=
pStddevRes
->
isum
/
((
double
)
pStddevRes
->
count
);
avg
=
pStddevRes
->
isum
/
((
double
)
pStddevRes
->
count
);
pStddevRes
->
result
=
sqrt
(
pStddevRes
->
quadraticISum
/
((
double
)
pStddevRes
->
count
)
-
avg
*
avg
);
pStddevRes
->
result
=
sqrt
(
pStddevRes
->
quadraticISum
/
((
double
)
pStddevRes
->
count
)
-
avg
*
avg
);
...
@@ -1708,6 +1744,24 @@ int32_t stddevFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
...
@@ -1708,6 +1744,24 @@ int32_t stddevFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
return
functionFinalize
(
pCtx
,
pBlock
);
return
functionFinalize
(
pCtx
,
pBlock
);
}
}
int32_t
stddevPartialFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
)
{
SResultRowEntryInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SStddevRes
*
pInfo
=
GET_ROWCELL_INTERBUF
(
GET_RES_INFO
(
pCtx
));
int32_t
resultBytes
=
getStddevInfoSize
();
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
stddevCombine
(
SqlFunctionCtx
*
pDestCtx
,
SqlFunctionCtx
*
pSourceCtx
)
{
int32_t
stddevCombine
(
SqlFunctionCtx
*
pDestCtx
,
SqlFunctionCtx
*
pSourceCtx
)
{
SResultRowEntryInfo
*
pDResInfo
=
GET_RES_INFO
(
pDestCtx
);
SResultRowEntryInfo
*
pDResInfo
=
GET_RES_INFO
(
pDestCtx
);
SStddevRes
*
pDBuf
=
GET_ROWCELL_INTERBUF
(
pDResInfo
);
SStddevRes
*
pDBuf
=
GET_ROWCELL_INTERBUF
(
pDResInfo
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录