Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9a038322
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看板
提交
9a038322
编写于
4月 21, 2022
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(query): do some internal refactor.
上级
a6e8ad6e
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
205 addition
and
318 deletion
+205
-318
include/libs/function/function.h
include/libs/function/function.h
+1
-1
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+48
-54
source/libs/function/inc/builtinsimpl.h
source/libs/function/inc/builtinsimpl.h
+3
-0
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+5
-4
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+28
-17
source/libs/function/src/taggfunction.c
source/libs/function/src/taggfunction.c
+120
-242
未找到文件。
include/libs/function/function.h
浏览文件 @
9a038322
...
...
@@ -192,7 +192,7 @@ typedef struct SqlFunctionCtx {
int16_t
functionId
;
// function id
char
*
pOutput
;
// final result output buffer, point to sdata->data
int32_t
numOfParams
;
S
Variant
param
[
4
];
// input parameter, e.g., top(k, 20), the number of results for top query is kept in param
S
FunctParam
*
param
;
// input parameter, e.g., top(k, 20), the number of results for top query is kept in param
int64_t
*
ptsList
;
// corresponding timestamp array list
SColumnInfoData
*
pTsOutput
;
// corresponding output buffer for timestamp of each result, e.g., top/bottom*/
int32_t
offset
;
...
...
source/libs/executor/src/executorimpl.c
浏览文件 @
9a038322
...
...
@@ -1087,6 +1087,7 @@ static int32_t doSetInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCt
pCtx
[
i
].
currentStage
=
MAIN_SCAN
;
SInputColumnInfoData
*
pInput
=
&
pCtx
[
i
].
input
;
pInput
->
uid
=
pBlock
->
info
.
uid
;
SExprInfo
*
pOneExpr
=
&
pOperator
->
pExpr
[
i
];
for
(
int32_t
j
=
0
;
j
<
pOneExpr
->
base
.
numOfParams
;
++
j
)
{
...
...
@@ -1101,7 +1102,9 @@ static int32_t doSetInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCt
pInput
->
pPTS
=
taosArrayGet
(
pBlock
->
pDataBlock
,
0
);
// todo set the correct timestamp column
ASSERT
(
pInput
->
pData
[
j
]
!=
NULL
);
}
else
if
(
pFuncParam
->
type
==
FUNC_PARAM_TYPE_VALUE
)
{
if
(
createDummyCol
)
{
// todo avoid case: top(k, 12), 12 is the value parameter.
// sum(11), 11 is also the value parameter.
if
(
createDummyCol
&&
pOneExpr
->
base
.
numOfParams
==
1
)
{
code
=
doCreateConstantValColumnInfo
(
pInput
,
pFuncParam
,
pFuncParam
->
param
.
nType
,
j
,
pBlock
->
info
.
rows
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
...
...
@@ -1876,67 +1879,58 @@ SqlFunctionCtx* createSqlFunctionCtx(SExprInfo* pExprInfo, int32_t numOfOutput,
}
}
pCtx
->
resDataInfo
.
interBufSize
=
env
.
calcMemSize
;
}
else
if
(
pExpr
->
pExpr
->
nodeType
==
QUERY_NODE_COLUMN
||
pExpr
->
pExpr
->
nodeType
==
QUERY_NODE_OPERATOR
||
pExpr
->
pExpr
->
nodeType
==
QUERY_NODE_VALUE
)
{
pCtx
->
resDataInfo
.
interBufSize
=
pFunct
->
resSchema
.
bytes
;
// for simple column, the intermediate buffer needs to hold one element.
}
else
if
(
pExpr
->
pExpr
->
nodeType
==
QUERY_NODE_COLUMN
||
pExpr
->
pExpr
->
nodeType
==
QUERY_NODE_OPERATOR
||
pExpr
->
pExpr
->
nodeType
==
QUERY_NODE_VALUE
)
{
// for simple column, the intermediate buffer needs to hold one element.
pCtx
->
resDataInfo
.
interBufSize
=
pFunct
->
resSchema
.
bytes
;
}
pCtx
->
input
.
numOfInputCols
=
pFunct
->
numOfParams
;
pCtx
->
input
.
pData
=
taosMemoryCalloc
(
pFunct
->
numOfParams
,
POINTER_BYTES
);
pCtx
->
input
.
pColumnDataAgg
=
taosMemoryCalloc
(
pFunct
->
numOfParams
,
POINTER_BYTES
);
pCtx
->
pTsOutput
=
NULL
;
pCtx
->
pTsOutput
=
NULL
;
pCtx
->
resDataInfo
.
bytes
=
pFunct
->
resSchema
.
bytes
;
pCtx
->
resDataInfo
.
type
=
pFunct
->
resSchema
.
type
;
pCtx
->
order
=
TSDB_ORDER_ASC
;
pCtx
->
start
.
key
=
INT64_MIN
;
pCtx
->
end
.
key
=
INT64_MIN
;
#if 0
for (int32_t j = 0; j < pCtx->numOfParams; ++j) {
// int16_t type = pFunct->param[j].nType;
// int16_t bytes = pFunct->param[j].nLen;
// if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) {
// taosVariantCreateFromBinary(&pCtx->param[j], pFunct->param[j].pz, bytes, type);
// } else {
// taosVariantCreateFromBinary(&pCtx->param[j], (char *)&pFunct->param[j].i, bytes, type);
// }
}
pCtx
->
resDataInfo
.
type
=
pFunct
->
resSchema
.
type
;
pCtx
->
order
=
TSDB_ORDER_ASC
;
pCtx
->
start
.
key
=
INT64_MIN
;
pCtx
->
end
.
key
=
INT64_MIN
;
pCtx
->
numOfParams
=
pExpr
->
base
.
numOfParams
;
// set the order information for top/bottom query
int32_t functionId = pCtx->functionId;
if (functionId == FUNCTION_TOP || functionId == FUNCTION_BOTTOM || functionId == FUNCTION_DIFF) {
int32_t f
= getExprFunctionId(&pExpr[0])
;
assert(f == FUNCTION_TS || f == FUNCTION_TS_DUMMY);
// pCtx->param[2].i = pQueryAttr->order.order
;
pCtx->param[2].nType = TSDB_DATA_TYPE_BIGINT;
pCtx->param[3].i = functionId
;
pCtx->param[3
].nType = TSDB_DATA_TYPE_BIGINT;
// pCtx->param[1].i = pQueryAttr->order.col.info.colId
;
} else if (functionId == FUNCTION_INTERP) {
// pCtx->param[2].i = (int8_t)pQueryAttr->fillType
;
// if (pQueryAttr->fillVal != NULL
) {
// if (isNull((const char *)&pQueryAttr->fillVal[i], pCtx->inputType)) {
// pCtx->param[1].nType = TSDB_DATA_TYPE_NULL;
// } else { // todo refactor, taosVariantCreateFromBinary should handle the NULL value
// if (pCtx->inputType != TSDB_DATA_TYPE_BINARY && pCtx->inputType != TSDB_DATA_TYPE_NCHAR) {
// taosVariantCreateFromBinary(&pCtx->param[1], (char *)&pQueryAttr->fillVal[i], pCtx->inputBytes, pCtx->inputType);
// }
// }
//
}
} else if (functionId == FUNCTION_TS_COMP) {
// pCtx->param[0].i = pQueryAttr->vgId; //TODO this should be the parameter from client
pCtx->param[0].nType = TSDB_DATA_TYPE_BIGINT;
} else if (functionId == FUNCTION_TWA) {
// pCtx->param[1].i = pQueryAttr->window.skey
;
pCtx->param[1].nType = TSDB_DATA_TYPE_BIGINT
;
// pCtx->param[2].i = pQueryAttr->window.ekey
;
pCtx->param[2].nType = TSDB_DATA_TYPE_BIGINT;
} else if (functionId == FUNCTION_ARITHM) {
// pCtx->param[1].pz = (char*) getScalarFuncSupport(pRuntimeEnv->scalarSup, i);
pCtx
->
param
=
pFunct
->
pParam
;
for
(
int32_t
j
=
0
;
j
<
pCtx
->
numOfParams
;
++
j
)
{
// set the order information for top/bottom query
int32_t
f
unctionId
=
pCtx
->
functionId
;
if
(
functionId
==
FUNCTION_TOP
||
functionId
==
FUNCTION_BOTTOM
||
functionId
==
FUNCTION_DIFF
)
{
int32_t
f
=
getExprFunctionId
(
&
pExpr
[
0
]);
assert
(
f
==
FUNCTION_TS
||
f
==
FUNCTION_TS_DUMMY
)
;
// pCtx->param[2].i = pQueryAttr->order.order
;
// pCtx->param[2
].nType = TSDB_DATA_TYPE_BIGINT;
// pCtx->param[3].i = functionId;
// pCtx->param[3].nType = TSDB_DATA_TYPE_BIGINT
;
// pCtx->param[1].i = pQueryAttr->order.col.info.colId
;
}
else
if
(
functionId
==
FUNCTION_INTERP
)
{
// pCtx->param[2].i = (int8_t)pQueryAttr->fillType;
// if (pQueryAttr->fillVal != NULL) {
// if (isNull((const char *)&pQueryAttr->fillVal[i], pCtx->inputType)) {
// pCtx->param[1].nType = TSDB_DATA_TYPE_NULL;
// } else { // todo refactor, taosVariantCreateFromBinary should handle the NULL value
// if (pCtx->inputType != TSDB_DATA_TYPE_BINARY && pCtx->inputType != TSDB_DATA_TYPE_NCHAR) {
// taosVariantCreateFromBinary(&pCtx->param[1], (char *)&pQueryAttr->fillVal[i], pCtx->inputBytes, pCtx->inputType);
//
}
// }
// }
}
else
if
(
functionId
==
FUNCTION_TWA
)
{
// pCtx->param[1].i = pQueryAttr->window.skey;
// pCtx->param[1].nType = TSDB_DATA_TYPE_BIGINT
;
// pCtx->param[2].i = pQueryAttr->window.ekey
;
// pCtx->param[2].nType = TSDB_DATA_TYPE_BIGINT
;
}
else
if
(
functionId
==
FUNCTION_ARITHM
)
{
// pCtx->param[1].pz = (char*) getScalarFuncSupport(pRuntimeEnv->scalarSup, i);
}
}
#endif
}
for
(
int32_t
i
=
1
;
i
<
numOfOutput
;
++
i
)
{
...
...
@@ -1955,7 +1949,7 @@ static void* destroySqlFunctionCtx(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
for
(
int32_t
i
=
0
;
i
<
numOfOutput
;
++
i
)
{
for
(
int32_t
j
=
0
;
j
<
pCtx
[
i
].
numOfParams
;
++
j
)
{
taosVariantDestroy
(
&
pCtx
[
i
].
param
[
j
]);
taosVariantDestroy
(
&
pCtx
[
i
].
param
[
j
]
.
param
);
}
taosVariantDestroy
(
&
pCtx
[
i
].
tag
);
...
...
source/libs/function/inc/builtinsimpl.h
浏览文件 @
9a038322
...
...
@@ -58,6 +58,9 @@ bool getFirstLastFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
int32_t
firstFunction
(
SqlFunctionCtx
*
pCtx
);
int32_t
lastFunction
(
SqlFunctionCtx
*
pCtx
);
bool
getTopBotFuncEnv
(
SFunctionNode
*
UNUSED_PARAM
(
pFunc
),
SFuncExecEnv
*
pEnv
);
int32_t
topFunction
(
SqlFunctionCtx
*
pCtx
);
#ifdef __cplusplus
}
#endif
...
...
source/libs/function/src/builtins.c
浏览文件 @
9a038322
...
...
@@ -200,7 +200,8 @@ static int32_t translateTbnameColumn(SFunctionNode* pFunc, char* pErrBuf, int32_
}
static
int32_t
translateTop
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
)
{
// todo
SDataType
*
pType
=
&
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
0
))
->
resType
;
pFunc
->
node
.
resType
=
(
SDataType
){.
bytes
=
pType
->
bytes
,
.
type
=
pType
->
type
};
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -499,9 +500,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
type
=
FUNCTION_TYPE_TOP
,
.
classification
=
FUNC_MGT_AGG_FUNC
,
.
translateFunc
=
translateTop
,
.
getEnvFunc
=
get
Minmax
FuncEnv
,
.
initFunc
=
maxF
unctionSetup
,
.
processFunc
=
max
Function
,
.
getEnvFunc
=
get
TopBot
FuncEnv
,
.
initFunc
=
f
unctionSetup
,
.
processFunc
=
top
Function
,
.
finalizeFunc
=
functionFinalize
},
{
...
...
source/libs/function/src/builtinsimpl.c
浏览文件 @
9a038322
...
...
@@ -14,10 +14,11 @@
*/
#include "builtinsimpl.h"
#include
"tpercentile.h"
#include
<libs/nodes/querynodes.h>
#include "querynodes.h"
#include "taggfunction.h"
#include "tdatablock.h"
#include "tpercentile.h"
#define SET_VAL(_info, numOfElem, res) \
do { \
...
...
@@ -738,9 +739,9 @@ int32_t percentileFunction(SqlFunctionCtx *pCtx) {
return
TSDB_CODE_SUCCESS
;
}
// TODO set the correct parameter.
void
percentileFinalize
(
SqlFunctionCtx
*
pCtx
)
{
double
v
=
50
;
//pCtx->param[0].nType == TSDB_DATA_TYPE_INT ? pCtx->param[0].i64 : pCtx->param[0].dKey;
SVariant
*
pVal
=
&
pCtx
->
param
[
1
].
param
;
double
v
=
pVal
->
nType
==
TSDB_DATA_TYPE_INT
?
pVal
->
i
:
pVal
->
d
;
SResultRowEntryInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SPercentileInfo
*
ppInfo
=
(
SPercentileInfo
*
)
GET_ROWCELL_INTERBUF
(
pResInfo
);
...
...
@@ -1180,17 +1181,22 @@ bool getTopBotFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
SColumnNode
*
pColNode
=
(
SColumnNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
0
);
int32_t
bytes
=
pColNode
->
node
.
resType
.
bytes
;
SValueNode
*
pkNode
=
(
SValueNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
1
);
pEnv
->
calcMemSize
=
sizeof
(
STopBotRes
)
+
pkNode
->
datum
.
i
*
bytes
;
return
true
;
}
static
STopBotRes
*
getTopBotOutputInfo
(
SqlFunctionCtx
*
pCtx
)
{
SResultRowEntryInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
return
GET_ROWCELL_INTERBUF
(
pResInfo
);
STopBotRes
*
pRes
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
pRes
->
pItems
=
(
STopBotResItem
*
)((
char
*
)
pRes
+
sizeof
(
STopBotRes
));
return
pRes
;
}
static
void
doAddIntoResult
(
STopBotRes
*
pRes
,
int32_t
maxSize
,
void
*
pData
,
uint16_t
type
,
uint64_t
uid
);
static
void
topFunction
(
SqlFunctionCtx
*
pCtx
)
{
int32_t
topFunction
(
SqlFunctionCtx
*
pCtx
)
{
int32_t
numOfElems
=
0
;
STopBotRes
*
pRes
=
getTopBotOutputInfo
(
pCtx
);
...
...
@@ -1215,11 +1221,12 @@ static void topFunction(SqlFunctionCtx *pCtx) {
numOfElems
++
;
char
*
data
=
colDataGetData
(
pCol
,
i
);
doAddIntoResult
(
pRes
,
pCtx
->
param
[
0
]
.
i
,
data
,
type
,
pInput
->
uid
);
doAddIntoResult
(
pRes
,
pCtx
->
param
[
1
].
param
.
i
,
data
,
type
,
pInput
->
uid
);
}
// treat the result as only one result
SET_VAL
(
GET_RES_INFO
(
pCtx
),
numOfElems
,
1
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
topBotResComparFn
(
const
void
*
p1
,
const
void
*
p2
,
const
void
*
param
)
{
...
...
@@ -1266,16 +1273,20 @@ void doAddIntoResult(STopBotRes *pRes, int32_t maxSize, void *pData, uint16_t ty
pRes
->
num
++
;
taosheapsort
((
void
*
)
pItem
,
sizeof
(
STopBotResItem
),
pRes
->
num
,
(
const
void
*
)
&
type
,
topBotResComparFn
,
false
);
}
else
{
// replace the minimum value in the result
// if ((IS_SIGNED_NUMERIC_TYPE(type) && val.i > pList[0]->v.i) ||
// (IS_UNSIGNED_NUMERIC_TYPE(type) && val.u > pList[0]->v.u) ||
// (IS_FLOAT_TYPE(type) && val.d > pList[0]->v.d)) {
//
// STopBotResItem* pItem = &pItems[0];
// pItem->v = val;
// pItem->uid = uid;
// pItem->tuplePos.pageId = -1; // todo set the corresponding tuple data in the disk-based buffer
//
// taosheapadjust((void *) pItem, sizeof(STopBotResItem), 0, pRes->num - 1, (const void *) &type, topBotResComparFn, NULL, false);
// }
if
((
IS_SIGNED_NUMERIC_TYPE
(
type
)
&&
val
.
i
>
pItems
[
0
].
v
.
i
)
||
(
IS_UNSIGNED_NUMERIC_TYPE
(
type
)
&&
val
.
u
>
pItems
[
0
].
v
.
u
)
||
(
IS_FLOAT_TYPE
(
type
)
&&
val
.
d
>
pItems
[
0
].
v
.
d
))
{
STopBotResItem
*
pItem
=
&
pItems
[
pRes
->
num
];
pItem
->
v
=
val
;
pItem
->
uid
=
uid
;
pItem
->
tuplePos
.
pageId
=
-
1
;
// todo set the corresponding tuple data in the disk-based buffer
taosheapadjust
((
void
*
)
pItem
,
sizeof
(
STopBotResItem
),
0
,
pRes
->
num
-
1
,
(
const
void
*
)
&
type
,
topBotResComparFn
,
NULL
,
false
);
}
}
}
void
topBotFinalize
(
SqlFunctionCtx
*
pCtx
)
{
functionFinalize
(
pCtx
);
}
\ No newline at end of file
source/libs/function/src/taggfunction.c
浏览文件 @
9a038322
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录