fix: col type

This commit is contained in:
factosea 2024-11-25 13:56:14 +08:00
parent 22f3c20977
commit c46278a863
2 changed files with 20 additions and 4 deletions

View File

@ -412,6 +412,13 @@ int32_t createFunction(const char* pName, SNodeList* pParameterList, SFunctionNo
return code; return code;
} }
static void resetOutputChangedFunc(SFunctionNode *pFunc, const SFunctionNode* pSrcFunc) {
if (funcMgtBuiltins[pFunc->funcId].type == FUNCTION_TYPE_LAST_MERGE) {
pFunc->node.resType = pSrcFunc->node.resType;
return;
}
}
int32_t createFunctionWithSrcFunc(const char* pName, const SFunctionNode* pSrcFunc, SNodeList* pParameterList, SFunctionNode** ppFunc) { int32_t createFunctionWithSrcFunc(const char* pName, const SFunctionNode* pSrcFunc, SNodeList* pParameterList, SFunctionNode** ppFunc) {
int32_t code = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)ppFunc); int32_t code = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)ppFunc);
if (NULL == *ppFunc) { if (NULL == *ppFunc) {
@ -430,6 +437,7 @@ int32_t createFunctionWithSrcFunc(const char* pName, const SFunctionNode* pSrcFu
*ppFunc = NULL; *ppFunc = NULL;
return code; return code;
} }
resetOutputChangedFunc(*ppFunc, pSrcFunc);
return code; return code;
} }

View File

@ -4258,7 +4258,7 @@ typedef struct SLastRowScanOptSetColDataTypeCxt {
int32_t code; int32_t code;
} SLastRowScanOptSetColDataTypeCxt; } SLastRowScanOptSetColDataTypeCxt;
static EDealRes lastRowScanOptSetColDataType(SNode* pNode, void* pContext) { static EDealRes lastRowScanOptGetColAndSetDataType(SNode* pNode, void* pContext, bool setType) {
if (QUERY_NODE_COLUMN == nodeType(pNode)) { if (QUERY_NODE_COLUMN == nodeType(pNode)) {
SLastRowScanOptSetColDataTypeCxt* pCxt = pContext; SLastRowScanOptSetColDataTypeCxt* pCxt = pContext;
if (pCxt->doAgg) { if (pCxt->doAgg) {
@ -4266,12 +4266,12 @@ static EDealRes lastRowScanOptSetColDataType(SNode* pNode, void* pContext) {
if (TSDB_CODE_SUCCESS != pCxt->code) { if (TSDB_CODE_SUCCESS != pCxt->code) {
return DEAL_RES_ERROR; return DEAL_RES_ERROR;
} }
getLastCacheDataType(&(((SColumnNode*)pNode)->node.resType), pCxt->pkBytes); if (setType) getLastCacheDataType(&(((SColumnNode*)pNode)->node.resType), pCxt->pkBytes);
} else { } else {
SNode* pCol = NULL; SNode* pCol = NULL;
FOREACH(pCol, pCxt->pLastCols) { FOREACH(pCol, pCxt->pLastCols) {
if (nodesEqualNode(pCol, pNode)) { if (nodesEqualNode(pCol, pNode)) {
getLastCacheDataType(&(((SColumnNode*)pNode)->node.resType), pCxt->pkBytes); if (setType) getLastCacheDataType(&(((SColumnNode*)pNode)->node.resType), pCxt->pkBytes);
break; break;
} }
} }
@ -4281,6 +4281,14 @@ static EDealRes lastRowScanOptSetColDataType(SNode* pNode, void* pContext) {
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
static EDealRes lastRowScanOptGetLastCols(SNode* pNode, void* pContext) {
return lastRowScanOptGetColAndSetDataType(pNode, pContext, false);
}
static EDealRes lastRowScanOptSetColDataType(SNode* pNode, void* pContext) {
return lastRowScanOptGetColAndSetDataType(pNode, pContext, true);
}
static void lastRowScanOptSetLastTargets(SNodeList* pTargets, SNodeList* pLastCols, SNodeList* pLastRowCols, bool erase, int32_t pkBytes) { static void lastRowScanOptSetLastTargets(SNodeList* pTargets, SNodeList* pLastCols, SNodeList* pLastRowCols, bool erase, int32_t pkBytes) {
SNode* pTarget = NULL; SNode* pTarget = NULL;
WHERE_EACH(pTarget, pTargets) { WHERE_EACH(pTarget, pTargets) {
@ -4393,7 +4401,7 @@ static int32_t lastRowScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogic
SNode* pParamNode = NULL; SNode* pParamNode = NULL;
if (FUNCTION_TYPE_LAST == funcType) { if (FUNCTION_TYPE_LAST == funcType) {
(void)nodesListErase(pFunc->pParameterList, nodesListGetCell(pFunc->pParameterList, 1)); (void)nodesListErase(pFunc->pParameterList, nodesListGetCell(pFunc->pParameterList, 1));
nodesWalkExpr(nodesListGetNode(pFunc->pParameterList, 0), lastRowScanOptSetColDataType, &cxt); nodesWalkExpr(nodesListGetNode(pFunc->pParameterList, 0), lastRowScanOptGetLastCols, &cxt);
if (TSDB_CODE_SUCCESS != cxt.code) break; if (TSDB_CODE_SUCCESS != cxt.code) break;
} }
FOREACH(pParamNode, pFunc->pParameterList) { FOREACH(pParamNode, pFunc->pParameterList) {