fix: copy expr

This commit is contained in:
factosea 2024-01-12 14:01:35 +08:00
parent 6115d7a67f
commit 19d7579e75
2 changed files with 15 additions and 12 deletions

View File

@ -2742,7 +2742,8 @@ static EDealRes doCheckAggColCoexist(SNode** pNode, void* pContext) {
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
static int32_t reCalSelectFuncNum(SSelectStmt* pSelect) { static int32_t resetSelectFuncNumWithoutDup(SSelectStmt* pSelect) {
if (pSelect->selectFuncNum <= 1) return TSDB_CODE_SUCCESS;
pSelect->selectFuncNum = 0; pSelect->selectFuncNum = 0;
SNodeList* pNodeList = nodesMakeList(); SNodeList* pNodeList = nodesMakeList();
int32_t code = nodesCollectSelectFuncs(pSelect, SQL_CLAUSE_FROM, NULL, fmIsSelectFunc, pNodeList); int32_t code = nodesCollectSelectFuncs(pSelect, SQL_CLAUSE_FROM, NULL, fmIsSelectFunc, pNodeList);
@ -3489,13 +3490,15 @@ static int32_t translateOrderByPosition(STranslateContext* pCxt, SNodeList* pPro
} else if (0 == pos || pos > LIST_LENGTH(pProjectionList)) { } else if (0 == pos || pos > LIST_LENGTH(pProjectionList)) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT); return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT);
} else { } else {
SColumnRefNode* pCol = (SColumnRefNode*)nodesMakeNode(QUERY_NODE_COLUMN_REF); // SColumnRefNode* pCol = (SColumnRefNode*)nodesMakeNode(QUERY_NODE_COLUMN_REF);
if (NULL == pCol) { // if (NULL == pCol) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_OUT_OF_MEMORY); // return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_OUT_OF_MEMORY);
} // }
strcpy(pCol->colName, ((SExprNode*)nodesListGetNode(pProjectionList, pos - 1))->aliasName); // strcpy(pCol->colName, ((SExprNode*)nodesListGetNode(pProjectionList, pos - 1))->aliasName);
((SOrderByExprNode*)pNode)->pExpr = (SNode*)pCol;
nodesDestroyNode(pExpr); // (SExprNode*)nodesListGetNode(pProjectionList, pos - 1);
// ((SOrderByExprNode*)pNode)->pExpr = (SNode*)pCol;
// nodesDestroyNode(pExpr);
} }
} else { } else {
*pOther = true; *pOther = true;
@ -4555,8 +4558,8 @@ static EDealRes replaceOrderByAliasImpl(SNode** pNode, void* pContext) {
return DEAL_RES_ERROR; return DEAL_RES_ERROR;
} }
((SExprNode*)pNew)->orderAlias = true; ((SExprNode*)pNew)->orderAlias = true;
nodesDestroyNode(*pNode); ((SOrderByExprNode*)*pNode)->pExpr = pNew;
*pNode = pNew; nodesDestroyNode(pExpr);
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
} }
@ -4634,7 +4637,7 @@ static int32_t translateSelectFrom(STranslateContext* pCxt, SSelectStmt* pSelect
code = translateOrderBy(pCxt, pSelect); code = translateOrderBy(pCxt, pSelect);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
reCalSelectFuncNum(pSelect); resetSelectFuncNumWithoutDup(pSelect);
code = checkAggColCoexist(pCxt, pSelect); code = checkAggColCoexist(pCxt, pSelect);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {

View File

@ -278,7 +278,7 @@ class TDTestCase:
def queryOrderByAgg(self): def queryOrderByAgg(self):
tdSql.error(f"SELECT * FROM t1 order by last(ts)") tdSql.query(f"SELECT * FROM t1 order by last(ts)")
tdSql.query(f"SELECT last(ts) FROM t1 order by last(ts)") tdSql.query(f"SELECT last(ts) FROM t1 order by last(ts)")