feat: the function manager adds an interface for manually configuring the parameters of the merge function
This commit is contained in:
parent
c0074588d4
commit
04e9996db6
|
@ -24,6 +24,7 @@ extern "C" {
|
||||||
|
|
||||||
typedef int32_t (*FTranslateFunc)(SFunctionNode* pFunc, char* pErrBuf, int32_t len);
|
typedef int32_t (*FTranslateFunc)(SFunctionNode* pFunc, char* pErrBuf, int32_t len);
|
||||||
typedef EFuncDataRequired (*FFuncDataRequired)(SFunctionNode* pFunc, STimeWindow* pTimeWindow);
|
typedef EFuncDataRequired (*FFuncDataRequired)(SFunctionNode* pFunc, STimeWindow* pTimeWindow);
|
||||||
|
typedef int32_t (*FCreateMergeFuncParameters)(SNodeList* pRawParameters, SNode* pPartialRes, SNodeList** pParameters);
|
||||||
|
|
||||||
typedef struct SBuiltinFuncDefinition {
|
typedef struct SBuiltinFuncDefinition {
|
||||||
const char* name;
|
const char* name;
|
||||||
|
@ -40,6 +41,7 @@ typedef struct SBuiltinFuncDefinition {
|
||||||
FExecCombine combineFunc;
|
FExecCombine combineFunc;
|
||||||
const char* pPartialFunc;
|
const char* pPartialFunc;
|
||||||
const char* pMergeFunc;
|
const char* pMergeFunc;
|
||||||
|
FCreateMergeFuncParameters createMergeParaFuc;
|
||||||
} SBuiltinFuncDefinition;
|
} SBuiltinFuncDefinition;
|
||||||
|
|
||||||
extern const SBuiltinFuncDefinition funcMgtBuiltins[];
|
extern const SBuiltinFuncDefinition funcMgtBuiltins[];
|
||||||
|
|
|
@ -51,8 +51,6 @@ extern "C" {
|
||||||
|
|
||||||
#define FUNC_UDF_ID_START 5000
|
#define FUNC_UDF_ID_START 5000
|
||||||
|
|
||||||
extern const int funcMgtUdfNum;
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -419,6 +419,14 @@ static int32_t translateTopBot(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t topCreateMergePara(SNodeList* pRawParameters, SNode* pPartialRes, SNodeList** pParameters) {
|
||||||
|
int32_t code = nodesListMakeAppend(pParameters, pPartialRes);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = nodesListStrictAppend(*pParameters, nodesCloneNode(nodesListGetNode(pRawParameters, 1)));
|
||||||
|
}
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t translateTopBotImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t len, bool isPartial) {
|
static int32_t translateTopBotImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t len, bool isPartial) {
|
||||||
int32_t numOfParams = LIST_LENGTH(pFunc->pParameterList);
|
int32_t numOfParams = LIST_LENGTH(pFunc->pParameterList);
|
||||||
|
|
||||||
|
@ -1728,7 +1736,8 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
.finalizeFunc = topBotFinalize,
|
.finalizeFunc = topBotFinalize,
|
||||||
.combineFunc = topCombine,
|
.combineFunc = topCombine,
|
||||||
.pPartialFunc = "_top_partial",
|
.pPartialFunc = "_top_partial",
|
||||||
.pMergeFunc = "_top_merge"
|
.pMergeFunc = "_top_merge",
|
||||||
|
.createMergeParaFuc = topCreateMergePara
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.name = "_top_partial",
|
.name = "_top_partial",
|
||||||
|
|
|
@ -2360,9 +2360,7 @@ int32_t apercentileCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx)
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t getFirstLastInfoSize(int32_t resBytes) {
|
int32_t getFirstLastInfoSize(int32_t resBytes) { return sizeof(SFirstLastRes) + resBytes + sizeof(int64_t); }
|
||||||
return sizeof(SFirstLastRes) + resBytes + sizeof(int64_t);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool getFirstLastFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
|
bool getFirstLastFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
|
||||||
SColumnNode* pNode = (SColumnNode*)nodesListGetNode(pFunc->pParameterList, 0);
|
SColumnNode* pNode = (SColumnNode*)nodesListGetNode(pFunc->pParameterList, 0);
|
||||||
|
@ -2604,13 +2602,9 @@ static int32_t firstLastFunctionMergeImpl(SqlFunctionCtx *pCtx, bool isFirstQuer
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t firstFunctionMerge(SqlFunctionCtx *pCtx) {
|
int32_t firstFunctionMerge(SqlFunctionCtx* pCtx) { return firstLastFunctionMergeImpl(pCtx, true); }
|
||||||
return firstLastFunctionMergeImpl(pCtx, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t lastFunctionMerge(SqlFunctionCtx *pCtx) {
|
int32_t lastFunctionMerge(SqlFunctionCtx* pCtx) { return firstLastFunctionMergeImpl(pCtx, false); }
|
||||||
return firstLastFunctionMergeImpl(pCtx, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t firstLastFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
int32_t firstLastFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
int32_t slotId = pCtx->pExpr->base.resSchema.slotId;
|
int32_t slotId = pCtx->pExpr->base.resSchema.slotId;
|
||||||
|
|
|
@ -261,14 +261,14 @@ static SFunctionNode* createFunction(const char* pName, SNodeList* pParameterLis
|
||||||
return pFunc;
|
return pFunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SColumnNode* createColumnByFunc(const SFunctionNode* pFunc) {
|
static SNode* createColumnByFunc(const SFunctionNode* pFunc) {
|
||||||
SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN);
|
SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN);
|
||||||
if (NULL == pCol) {
|
if (NULL == pCol) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
strcpy(pCol->colName, pFunc->node.aliasName);
|
strcpy(pCol->colName, pFunc->node.aliasName);
|
||||||
pCol->node.resType = pFunc->node.resType;
|
pCol->node.resType = pFunc->node.resType;
|
||||||
return pCol;
|
return (SNode*)pCol;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fmIsDistExecFunc(int32_t funcId) {
|
bool fmIsDistExecFunc(int32_t funcId) {
|
||||||
|
@ -296,21 +296,45 @@ static int32_t createPartialFunction(const SFunctionNode* pSrcFunc, SFunctionNod
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t createMergeFuncPara(const SFunctionNode* pSrcFunc, const SFunctionNode* pPartialFunc,
|
||||||
|
SNodeList** pParameterList) {
|
||||||
|
SNode* pRes = createColumnByFunc(pPartialFunc);
|
||||||
|
if (NULL != funcMgtBuiltins[pSrcFunc->funcId].createMergeParaFuc) {
|
||||||
|
return funcMgtBuiltins[pSrcFunc->funcId].createMergeParaFuc(pSrcFunc->pParameterList, pRes, pParameterList);
|
||||||
|
} else {
|
||||||
|
return nodesListMakeStrictAppend(pParameterList, pRes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t createMergeFunction(const SFunctionNode* pSrcFunc, const SFunctionNode* pPartialFunc,
|
static int32_t createMergeFunction(const SFunctionNode* pSrcFunc, const SFunctionNode* pPartialFunc,
|
||||||
SFunctionNode** pMergeFunc) {
|
SFunctionNode** pMergeFunc) {
|
||||||
SNodeList* pParameterList = NULL;
|
SNodeList* pParameterList = NULL;
|
||||||
nodesListMakeStrictAppend(&pParameterList, (SNode*)createColumnByFunc(pPartialFunc));
|
SFunctionNode* pFunc = NULL;
|
||||||
*pMergeFunc = createFunction(funcMgtBuiltins[pSrcFunc->funcId].pMergeFunc, pParameterList);
|
|
||||||
if (NULL == *pMergeFunc) {
|
int32_t code = createMergeFuncPara(pSrcFunc, pPartialFunc, &pParameterList);
|
||||||
nodesDestroyList(pParameterList);
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
pFunc = createFunction(funcMgtBuiltins[pSrcFunc->funcId].pMergeFunc, pParameterList);
|
||||||
|
if (NULL == pFunc) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
// overwrite function restype set by translate function
|
// overwrite function restype set by translate function
|
||||||
if (fmIsSameInOutType(pSrcFunc->funcId)) {
|
if (fmIsSameInOutType(pSrcFunc->funcId)) {
|
||||||
(*pMergeFunc)->node.resType = pSrcFunc->node.resType;
|
(*pMergeFunc)->node.resType = pSrcFunc->node.resType;
|
||||||
}
|
}
|
||||||
strcpy((*pMergeFunc)->node.aliasName, pSrcFunc->node.aliasName);
|
strcpy((*pMergeFunc)->node.aliasName, pSrcFunc->node.aliasName);
|
||||||
return TSDB_CODE_SUCCESS;
|
}
|
||||||
|
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
*pMergeFunc = pFunc;
|
||||||
|
} else {
|
||||||
|
pFunc->pParameterList = NULL;
|
||||||
|
nodesDestroyNode((SNode*)pFunc);
|
||||||
|
nodesDestroyList(pParameterList);
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t fmGetDistMethod(const SFunctionNode* pFunc, SFunctionNode** pPartialFunc, SFunctionNode** pMergeFunc) {
|
int32_t fmGetDistMethod(const SFunctionNode* pFunc, SFunctionNode** pPartialFunc, SFunctionNode** pMergeFunc) {
|
||||||
|
|
Loading…
Reference in New Issue