Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e7e5fd43
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看板
提交
e7e5fd43
编写于
4月 02, 2022
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-14393] support percentile function.
上级
b0310c90
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
65 addition
and
42 deletion
+65
-42
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+0
-1
source/libs/function/inc/builtinsimpl.h
source/libs/function/inc/builtinsimpl.h
+1
-0
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+3
-3
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+46
-26
tests/script/tsim/query/session.sim
tests/script/tsim/query/session.sim
+15
-12
未找到文件。
source/libs/executor/src/executorimpl.c
浏览文件 @
e7e5fd43
...
...
@@ -6104,7 +6104,6 @@ static int32_t doOpenAggregateOptr(SOperatorInfo* pOperator) {
if
(
pBlock
==
NULL
)
{
break
;
}
// if (pAggInfo->current != NULL) {
// setTagValue(pOperator, pAggInfo->current->pTable, pInfo->pCtx, pOperator->numOfOutput);
// }
...
...
source/libs/function/inc/builtinsimpl.h
浏览文件 @
e7e5fd43
...
...
@@ -45,6 +45,7 @@ void stddevFinalize(SqlFunctionCtx* pCtx);
bool
getPercentileFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
bool
percentileFunctionSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
);
void
percentileFunction
(
SqlFunctionCtx
*
pCtx
);
void
percentileFinalize
(
SqlFunctionCtx
*
pCtx
);
bool
getFirstLastFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
void
firstFunction
(
SqlFunctionCtx
*
pCtx
);
...
...
source/libs/function/src/builtins.c
浏览文件 @
e7e5fd43
...
...
@@ -77,9 +77,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
type
=
FUNCTION_TYPE_PERCENTILE
,
.
classification
=
FUNC_MGT_AGG_FUNC
,
.
checkFunc
=
stubCheckAndGetResultType
,
.
getEnvFunc
=
get
Minmax
FuncEnv
,
.
initFunc
=
max
FunctionSetup
,
.
processFunc
=
max
Function
,
.
getEnvFunc
=
get
Percentile
FuncEnv
,
.
initFunc
=
percentile
FunctionSetup
,
.
processFunc
=
percentile
Function
,
.
finalizeFunc
=
functionFinalize
},
{
...
...
source/libs/function/src/builtinsimpl.c
浏览文件 @
e7e5fd43
...
...
@@ -480,7 +480,6 @@ void stddevFunction(SqlFunctionCtx* pCtx) {
// Only the pre-computing information loaded and actual data does not loaded
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
SColumnDataAgg
*
pAgg
=
pInput
->
pColumnDataAgg
[
0
];
int32_t
type
=
pInput
->
pData
[
0
]
->
info
.
type
;
SStddevRes
*
pStddevRes
=
GET_ROWCELL_INTERBUF
(
GET_RES_INFO
(
pCtx
));
...
...
@@ -601,6 +600,7 @@ void stddevFinalize(SqlFunctionCtx* pCtx) {
}
typedef
struct
SPercentileInfo
{
double
result
;
tMemBucket
*
pMemBucket
;
int32_t
stage
;
double
minval
;
...
...
@@ -629,10 +629,15 @@ bool percentileFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultI
void
percentileFunction
(
SqlFunctionCtx
*
pCtx
)
{
int32_t
notNullElems
=
0
;
#if 0
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
SPercentileInfo *pInfo = GET_ROWCELL_INTERBUF(pResInfo);
SResultRowEntryInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
SColumnDataAgg
*
pAgg
=
pInput
->
pColumnDataAgg
[
0
];
SColumnInfoData
*
pCol
=
pInput
->
pData
[
0
];
int32_t
type
=
pCol
->
info
.
type
;
SPercentileInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
if
(
pCtx
->
currentStage
==
REPEAT_SCAN
&&
pInfo
->
stage
==
0
)
{
pInfo
->
stage
+=
1
;
...
...
@@ -647,19 +652,17 @@ void percentileFunction(SqlFunctionCtx *pCtx) {
// the first stage, only acquire the min/max value
if
(
pInfo
->
stage
==
0
)
{
if (pCtx->
preAggVals.i
sSet) {
if
(
pCtx
->
input
.
colDataAggI
sSet
)
{
double
tmin
=
0
.
0
,
tmax
=
0
.
0
;
if (IS_SIGNED_NUMERIC_TYPE(pCtx->inputType)) {
tmin = (double)GET_INT64_VAL(&pCtx->preAggVals.statis.min);
tmax = (double)GET_INT64_VAL(&pCtx->preAggVals.statis.max);
} else if (IS_FLOAT_TYPE(pCtx->inputType)) {
tmin = GET_DOUBLE_VAL(&pCtx->preAggVals.statis.min);
tmax = GET_DOUBLE_VAL(&pCtx->preAggVals.statis.max);
} else if (IS_UNSIGNED_NUMERIC_TYPE(pCtx->inputType)) {
tmin = (double)GET_UINT64_VAL(&pCtx->preAggVals.statis.min);
tmax = (double)GET_UINT64_VAL(&pCtx->preAggVals.statis.max);
} else {
assert(true);
if
(
IS_SIGNED_NUMERIC_TYPE
(
type
))
{
tmin
=
(
double
)
GET_INT64_VAL
(
&
pAgg
->
min
);
tmax
=
(
double
)
GET_INT64_VAL
(
&
pAgg
->
max
);
}
else
if
(
IS_FLOAT_TYPE
(
type
))
{
tmin
=
GET_DOUBLE_VAL
(
&
pAgg
->
min
);
tmax
=
GET_DOUBLE_VAL
(
&
pAgg
->
max
);
}
else
if
(
IS_UNSIGNED_NUMERIC_TYPE
(
type
))
{
tmin
=
(
double
)
GET_UINT64_VAL
(
&
pAgg
->
min
);
tmax
=
(
double
)
GET_UINT64_VAL
(
&
pAgg
->
max
);
}
if
(
GET_DOUBLE_VAL
(
&
pInfo
->
minval
)
>
tmin
)
{
...
...
@@ -670,17 +673,19 @@ void percentileFunction(SqlFunctionCtx *pCtx) {
SET_DOUBLE_VAL
(
&
pInfo
->
maxval
,
tmax
);
}
pInfo->numOfElems += (p
Ctx->size - pCtx->preAggVals.statis.
numOfNull);
pInfo
->
numOfElems
+=
(
p
Input
->
numOfRows
-
pAgg
->
numOfNull
);
}
else
{
for (int32_t i = 0; i < pCtx->size; ++i) {
char *data = GET_INPUT_DATA(pCtx, i);
if (pCtx->hasNull && isNull(data, pCtx->inputType)) {
// check the valid data one by one
int32_t
start
=
pInput
->
startRowIndex
;
for
(
int32_t
i
=
start
;
i
<
pInput
->
numOfRows
+
start
;
++
i
)
{
if
(
colDataIsNull_f
(
pCol
->
nullbitmap
,
i
))
{
continue
;
}
char
*
data
=
colDataGetData
(
pCol
,
i
);
double
v
=
0
;
GET_TYPED_DATA
(
v
,
double
,
pCtx
->
inputType
,
data
);
if
(
v
<
GET_DOUBLE_VAL
(
&
pInfo
->
minval
))
{
SET_DOUBLE_VAL
(
&
pInfo
->
minval
,
v
);
}
...
...
@@ -697,20 +702,35 @@ void percentileFunction(SqlFunctionCtx *pCtx) {
}
// the second stage, calculate the true percentile value
for (int32_t i = 0; i < pCtx->size; ++i) {
char *data = GET_INPUT_DATA(pCtx, i);
if (
pCtx->hasNull && isNull(data, pCtx->inputType
)) {
int32_t
start
=
pInput
->
startRowIndex
;
for
(
int32_t
i
=
start
;
i
<
pInput
->
numOfRows
+
start
;
++
i
)
{
if
(
colDataIsNull_f
(
pCol
->
nullbitmap
,
i
))
{
continue
;
}
char
*
data
=
colDataGetData
(
pCol
,
i
);
notNullElems
+=
1
;
tMemBucketPut
(
pInfo
->
pMemBucket
,
data
,
1
);
}
SET_VAL(p
Ctx
, notNullElems, 1);
SET_VAL
(
p
ResInfo
,
notNullElems
,
1
);
pResInfo
->
hasResult
=
DATA_SET_FLAG
;
#endif
}
void
percentileFinalize
(
SqlFunctionCtx
*
pCtx
)
{
double
v
=
50
;
//pCtx->param[0].nType == TSDB_DATA_TYPE_INT ? pCtx->param[0].i64 : pCtx->param[0].dKey;
SResultRowEntryInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SPercentileInfo
*
ppInfo
=
(
SPercentileInfo
*
)
GET_ROWCELL_INTERBUF
(
pResInfo
);
tMemBucket
*
pMemBucket
=
ppInfo
->
pMemBucket
;
if
(
pMemBucket
!=
NULL
&&
pMemBucket
->
total
>
0
)
{
// check for null
SET_DOUBLE_VAL
(
&
ppInfo
->
result
,
getPercentile
(
pMemBucket
,
v
));
}
tMemBucketDestroy
(
pMemBucket
);
functionFinalize
(
pCtx
);
}
bool
getFirstLastFuncEnv
(
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
)
{
...
...
tests/script/tsim/query/session.sim
浏览文件 @
e7e5fd43
...
...
@@ -284,14 +284,15 @@ print ====> select count(*),first(tagtype),last(tagtype),avg(tagtype),sum(tagtyp
# return -1
#endi
sql_error select * from dev_001 session(ts,1w)
sql_error select count(*) from st session(ts,1w)
sql_error select count(*) from dev_001 group by tagtype session(ts,1w)
sql_error select count(*) from dev_001 session(ts,1n)
sql_error select count(*) from dev_001 session(ts,1y)
sql_error select count(*) from dev_001 session(ts,0s)
sql_error select count(*) from dev_001 session(i,1y)
sql_error select count(*) from dev_001 session(ts,1d) where ts <'2020-05-20 0:0:0'
print ================> syntax error check not active ================> reactive
#sql_error select * from dev_001 session(ts,1w)
#sql_error select count(*) from st session(ts,1w)
#sql_error select count(*) from dev_001 group by tagtype session(ts,1w)
#sql_error select count(*) from dev_001 session(ts,1n)
#sql_error select count(*) from dev_001 session(ts,1y)
#sql_error select count(*) from dev_001 session(ts,0s)
#sql_error select count(*) from dev_001 session(i,1y)
#sql_error select count(*) from dev_001 session(ts,1d) where ts <'2020-05-20 0:0:0'
print ====> create database d1 precision 'us'
sql create database d1 precision 'us'
...
...
@@ -299,17 +300,19 @@ sql use d1
sql create table dev_001 (ts timestamp ,i timestamp ,j int)
sql insert into dev_001 values(1623046993681000,now,1)(1623046993681001,now+1s,2)(1623046993681002,now+2s,3)(1623046993681004,now+5s,4)
print ====> select count(*) from dev_001 session(ts,1u)
sql select count(*) from dev_001 session(ts,1u)
sql select
_wstartts,
count(*) from dev_001 session(ts,1u)
if $rows != 2 then
print expect 2, actual: $rows
return -1
endi
if $data01 != 3 then
return -1
endi
sql_error select count(*) from dev_001 session(i,1s)
sql create table secondts(ts timestamp,t2 timestamp,i int)
sql_error select count(*) from secondts session(t2,2s)
#sql_error select count(*) from dev_001 session(i,1s)
#sql create table secondts(ts timestamp,t2 timestamp,i int)
#sql_error select count(*) from secondts session(t2,2s)
if $loop_test == 0 then
print =============== stop and restart taosd
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录