Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
7075d621
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
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看板
提交
7075d621
编写于
1月 21, 2022
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-11222]<feature>: Histogram function
上级
0f507561
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
17 addition
and
2 deletion
+17
-2
src/query/src/qAggMain.c
src/query/src/qAggMain.c
+17
-2
未找到文件。
src/query/src/qAggMain.c
浏览文件 @
7075d621
...
@@ -214,6 +214,7 @@ typedef struct {
...
@@ -214,6 +214,7 @@ typedef struct {
double
lower
;
// >lower
double
lower
;
// >lower
double
upper
;
// <=upper
double
upper
;
// <=upper
int64_t
count
;
int64_t
count
;
double
count_norm
;
}
SHistogramFuncBin
;
}
SHistogramFuncBin
;
typedef
struct
{
typedef
struct
{
...
@@ -4989,6 +4990,7 @@ static void histogram_function(SQLFunctionCtx *pCtx) {
...
@@ -4989,6 +4990,7 @@ static void histogram_function(SQLFunctionCtx *pCtx) {
}
}
int32_t
notNullElems
=
0
;
int32_t
notNullElems
=
0
;
int32_t
totalElems
=
0
;
for
(
int32_t
i
=
0
;
i
<
pCtx
->
size
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pCtx
->
size
;
++
i
)
{
char
*
data
=
GET_INPUT_DATA
(
pCtx
,
i
);
char
*
data
=
GET_INPUT_DATA
(
pCtx
,
i
);
if
(
pCtx
->
hasNull
&&
isNull
(
data
,
pCtx
->
inputType
))
{
if
(
pCtx
->
hasNull
&&
isNull
(
data
,
pCtx
->
inputType
))
{
...
@@ -5002,11 +5004,18 @@ static void histogram_function(SQLFunctionCtx *pCtx) {
...
@@ -5002,11 +5004,18 @@ static void histogram_function(SQLFunctionCtx *pCtx) {
for
(
int32_t
b
=
0
;
b
<
pRes
->
numOfBins
;
++
b
)
{
for
(
int32_t
b
=
0
;
b
<
pRes
->
numOfBins
;
++
b
)
{
if
(
v
>
pRes
->
orderedBins
[
b
].
lower
&&
v
<=
pRes
->
orderedBins
[
b
].
upper
)
{
if
(
v
>
pRes
->
orderedBins
[
b
].
lower
&&
v
<=
pRes
->
orderedBins
[
b
].
upper
)
{
pRes
->
orderedBins
[
b
].
count
++
;
pRes
->
orderedBins
[
b
].
count
++
;
totalElems
++
;
break
;
break
;
}
}
}
}
}
}
if
(
pRes
->
normalized
)
{
for
(
int32_t
b
=
0
;
b
<
pRes
->
numOfBins
;
++
b
)
{
pRes
->
orderedBins
[
b
].
count_norm
=
pRes
->
orderedBins
[
b
].
count
/
totalElems
;
}
}
// treat the result as only one result
// treat the result as only one result
SET_VAL
(
pCtx
,
notNullElems
,
1
);
SET_VAL
(
pCtx
,
notNullElems
,
1
);
if
(
notNullElems
>
0
)
{
if
(
notNullElems
>
0
)
{
...
@@ -5036,8 +5045,14 @@ static void histogram_func_finalizer(SQLFunctionCtx *pCtx) {
...
@@ -5036,8 +5045,14 @@ static void histogram_func_finalizer(SQLFunctionCtx *pCtx) {
}
}
for
(
int32_t
i
=
0
;
i
<
pRes
->
numOfBins
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pRes
->
numOfBins
;
++
i
)
{
int
sz
=
sprintf
(
pCtx
->
pOutput
+
VARSTR_HEADER_SIZE
,
"(%g-%g]:%"
PRId64
,
int
sz
;
if
(
!
pRes
->
normalized
)
{
sz
=
sprintf
(
pCtx
->
pOutput
+
VARSTR_HEADER_SIZE
,
"(%g-%g]:%"
PRId64
,
pRes
->
orderedBins
[
i
].
lower
,
pRes
->
orderedBins
[
i
].
upper
,
pRes
->
orderedBins
[
i
].
count
);
pRes
->
orderedBins
[
i
].
lower
,
pRes
->
orderedBins
[
i
].
upper
,
pRes
->
orderedBins
[
i
].
count
);
}
else
{
sz
=
sprintf
(
pCtx
->
pOutput
+
VARSTR_HEADER_SIZE
,
"(%g-%g]:%lf"
,
pRes
->
orderedBins
[
i
].
lower
,
pRes
->
orderedBins
[
i
].
upper
,
pRes
->
orderedBins
[
i
].
count_norm
);
}
varDataSetLen
(
pCtx
->
pOutput
,
sz
);
varDataSetLen
(
pCtx
->
pOutput
,
sz
);
pCtx
->
pOutput
+=
pCtx
->
outputBytes
;
pCtx
->
pOutput
+=
pCtx
->
outputBytes
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录