support merge function resType same as original input type

This commit is contained in:
Ganlin Zhao 2022-06-10 21:10:55 +08:00
parent 40f5ff71f8
commit 741d0c5c69
2 changed files with 28 additions and 3 deletions

View File

@ -403,9 +403,9 @@ static int32_t translateTopBotImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
} }
// set result type // Do nothing. We can only access output of partial functions as input,
SDataType* pType = &((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType; // so original input type cannot be obtained, resType will be set same
pFunc->node.resType = (SDataType){.bytes = pType->bytes, .type = pType->type}; // as original function input type after merge function created.
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }

View File

@ -200,6 +200,27 @@ bool fmIsInvertible(int32_t funcId) {
return res; 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) { static int32_t getFuncInfo(SFunctionNode* pFunc) {
char msg[64] = {0}; char msg[64] = {0};
if (NULL != gFunMgtService.pFuncNameHashTable) { if (NULL != gFunMgtService.pFuncNameHashTable) {
@ -274,6 +295,10 @@ static int32_t createMergeFunction(const SFunctionNode* pSrcFunc, const SFunctio
nodesDestroyList(pParameterList); nodesDestroyList(pParameterList);
return TSDB_CODE_OUT_OF_MEMORY; 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); strcpy((*pMergeFunc)->node.aliasName, pSrcFunc->node.aliasName);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }