diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index aad871f311..b1b98daa84 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -403,9 +403,9 @@ static int32_t translateTopBotImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - // set result type - SDataType* pType = &((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType; - pFunc->node.resType = (SDataType){.bytes = pType->bytes, .type = pType->type}; + // Do nothing. We can only access output of partial functions as input, + // so original input type cannot be obtained, resType will be set same + // as original function input type after merge function created. } return TSDB_CODE_SUCCESS; } diff --git a/source/libs/function/src/functionMgt.c b/source/libs/function/src/functionMgt.c index f2514f54f1..f4e216d55c 100644 --- a/source/libs/function/src/functionMgt.c +++ b/source/libs/function/src/functionMgt.c @@ -200,6 +200,27 @@ bool fmIsInvertible(int32_t funcId) { return res; } +//function has same input/output type +bool fmIsSameInOutType(int32_t funcId) { + bool res = false; + switch (funcMgtBuiltins[funcId].type) { + case FUNCTION_TYPE_MAX: + case FUNCTION_TYPE_MIN: + case FUNCTION_TYPE_TOP: + case FUNCTION_TYPE_BOTTOM: + case FUNCTION_TYPE_FIRST: + case FUNCTION_TYPE_LAST: + case FUNCTION_TYPE_SAMPLE: + case FUNCTION_TYPE_TAIL: + case FUNCTION_TYPE_UNIQUE: + res = true; + break; + default: + break; + } + return res; +} + static int32_t getFuncInfo(SFunctionNode* pFunc) { char msg[64] = {0}; if (NULL != gFunMgtService.pFuncNameHashTable) { @@ -274,6 +295,10 @@ static int32_t createMergeFunction(const SFunctionNode* pSrcFunc, const SFunctio nodesDestroyList(pParameterList); return TSDB_CODE_OUT_OF_MEMORY; } + //overwrite function restype set by translate function + if (fmIsSameInOutType(funcMgtBuiltins[pSrcFunc->funcId].type)) { + (*pMergeFunc)->node.resType = pSrcFunc->node.resType; + } strcpy((*pMergeFunc)->node.aliasName, pSrcFunc->node.aliasName); return TSDB_CODE_SUCCESS; }