Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
77c9414d
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看板
未验证
提交
77c9414d
编写于
7月 16, 2022
作者:
G
Ganlin Zhao
提交者:
GitHub
7月 16, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #14955 from taosdata/feat/agg_client_api
feat(query): add percentile/apercentile scalar version
上级
9ea0e840
624e7b71
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
85 addition
and
2 deletion
+85
-2
include/libs/scalar/scalar.h
include/libs/scalar/scalar.h
+3
-0
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+3
-0
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+5
-1
source/libs/scalar/src/scalar.c
source/libs/scalar/src/scalar.c
+1
-1
source/libs/scalar/src/sclfunc.c
source/libs/scalar/src/sclfunc.c
+73
-0
未找到文件。
include/libs/scalar/scalar.h
浏览文件 @
77c9414d
...
...
@@ -104,6 +104,9 @@ int32_t maxScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *
int32_t
avgScalarFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
int32_t
stddevScalarFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
int32_t
leastSQRScalarFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
int32_t
percentileScalarFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
int32_t
apercentileScalarFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
int32_t
spreadScalarFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
#ifdef __cplusplus
}
...
...
source/libs/function/src/builtins.c
浏览文件 @
77c9414d
...
...
@@ -2034,6 +2034,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
getEnvFunc
=
getPercentileFuncEnv
,
.
initFunc
=
percentileFunctionSetup
,
.
processFunc
=
percentileFunction
,
.
sprocessFunc
=
percentileScalarFunction
,
.
finalizeFunc
=
percentileFinalize
,
.
invertFunc
=
NULL
,
.
combineFunc
=
NULL
,
...
...
@@ -2046,6 +2047,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
getEnvFunc
=
getApercentileFuncEnv
,
.
initFunc
=
apercentileFunctionSetup
,
.
processFunc
=
apercentileFunction
,
.
sprocessFunc
=
apercentileScalarFunction
,
.
finalizeFunc
=
apercentileFinalize
,
.
invertFunc
=
NULL
,
.
combineFunc
=
apercentileCombine
,
...
...
@@ -2113,6 +2115,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
getEnvFunc
=
getSpreadFuncEnv
,
.
initFunc
=
spreadFunctionSetup
,
.
processFunc
=
spreadFunction
,
.
sprocessFunc
=
spreadScalarFunction
,
.
finalizeFunc
=
spreadFinalize
,
.
invertFunc
=
NULL
,
.
combineFunc
=
spreadCombine
,
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
77c9414d
...
...
@@ -1167,7 +1167,11 @@ static int32_t translateRepeatScanFunc(STranslateContext* pCxt, SFunctionNode* p
if
(
!
fmIsRepeatScanFunc
(
pFunc
->
funcId
))
{
return
TSDB_CODE_SUCCESS
;
}
if
(
isSelectStmt
(
pCxt
->
pCurrStmt
)
&&
NULL
!=
((
SSelectStmt
*
)
pCxt
->
pCurrStmt
)
->
pFromTable
)
{
if
(
isSelectStmt
(
pCxt
->
pCurrStmt
))
{
//select percentile() without from clause is also valid
if
(
NULL
==
((
SSelectStmt
*
)
pCxt
->
pCurrStmt
)
->
pFromTable
)
{
return
TSDB_CODE_SUCCESS
;
}
SNode
*
pTable
=
((
SSelectStmt
*
)
pCxt
->
pCurrStmt
)
->
pFromTable
;
if
(
QUERY_NODE_REAL_TABLE
==
nodeType
(
pTable
)
&&
(
TSDB_CHILD_TABLE
==
((
SRealTableNode
*
)
pTable
)
->
pMeta
->
tableType
||
...
...
source/libs/scalar/src/scalar.c
浏览文件 @
77c9414d
...
...
@@ -700,7 +700,7 @@ EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) {
EDealRes
sclRewriteFunction
(
SNode
**
pNode
,
SScalarCtx
*
ctx
)
{
SFunctionNode
*
node
=
(
SFunctionNode
*
)
*
pNode
;
SNode
*
tnode
=
NULL
;
if
(
!
fmIsScalarFunc
(
node
->
funcId
))
{
if
(
!
fmIsScalarFunc
(
node
->
funcId
)
&&
(
!
ctx
->
dual
)
)
{
return
DEAL_RES_CONTINUE
;
}
...
...
source/libs/scalar/src/sclfunc.c
浏览文件 @
77c9414d
...
...
@@ -2307,3 +2307,76 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
pOutput
->
numOfRows
=
1
;
return
TSDB_CODE_SUCCESS
;
}
int32_t
percentileScalarFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
SColumnInfoData
*
pInputData
=
pInput
->
columnData
;
SColumnInfoData
*
pOutputData
=
pOutput
->
columnData
;
int32_t
type
=
GET_PARAM_TYPE
(
pInput
);
double
val
;
bool
hasNull
=
false
;
for
(
int32_t
i
=
0
;
i
<
pInput
->
numOfRows
;
++
i
)
{
if
(
colDataIsNull_s
(
pInputData
,
i
))
{
hasNull
=
true
;
break
;
}
char
*
in
=
pInputData
->
pData
;
GET_TYPED_DATA
(
val
,
double
,
type
,
in
);
}
if
(
hasNull
)
{
colDataAppendNULL
(
pOutputData
,
0
);
}
else
{
colDataAppend
(
pOutputData
,
0
,
(
char
*
)
&
val
,
false
);
}
pOutput
->
numOfRows
=
1
;
return
TSDB_CODE_SUCCESS
;
}
int32_t
apercentileScalarFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
return
percentileScalarFunction
(
pInput
,
inputNum
,
pOutput
);
}
int32_t
spreadScalarFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
SColumnInfoData
*
pInputData
=
pInput
->
columnData
;
SColumnInfoData
*
pOutputData
=
pOutput
->
columnData
;
int32_t
type
=
GET_PARAM_TYPE
(
pInput
);
double
min
,
max
;
SET_DOUBLE_VAL
(
&
min
,
DBL_MAX
);
SET_DOUBLE_VAL
(
&
max
,
-
DBL_MAX
);
bool
hasNull
=
false
;
for
(
int32_t
i
=
0
;
i
<
pInput
->
numOfRows
;
++
i
)
{
if
(
colDataIsNull_s
(
pInputData
,
i
))
{
hasNull
=
true
;
break
;
}
char
*
in
=
pInputData
->
pData
;
double
val
=
0
;
GET_TYPED_DATA
(
val
,
double
,
type
,
in
);
if
(
val
<
GET_DOUBLE_VAL
(
&
min
))
{
SET_DOUBLE_VAL
(
&
min
,
val
);
}
if
(
val
>
GET_DOUBLE_VAL
(
&
max
))
{
SET_DOUBLE_VAL
(
&
max
,
val
);
}
}
if
(
hasNull
)
{
colDataAppendNULL
(
pOutputData
,
0
);
}
else
{
double
result
=
max
-
min
;
colDataAppend
(
pOutputData
,
0
,
(
char
*
)
&
result
,
false
);
}
pOutput
->
numOfRows
=
1
;
return
TSDB_CODE_SUCCESS
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录