未验证 提交 9e595daa 编写于 作者: D dapan1121 提交者: GitHub

Merge pull request #21830 from taosdata/fix/TD-24287

fix: fix userAlias issue when keepColumnName is set to true
...@@ -52,6 +52,7 @@ typedef struct SExprNode { ...@@ -52,6 +52,7 @@ typedef struct SExprNode {
SArray* pAssociation; SArray* pAssociation;
bool orderAlias; bool orderAlias;
bool asAlias; bool asAlias;
bool asParam;
} SExprNode; } SExprNode;
typedef enum EColumnType { typedef enum EColumnType {
......
...@@ -214,6 +214,18 @@ void nodesWalkExprsPostOrder(SNodeList* pList, FNodeWalker walker, void* pContex ...@@ -214,6 +214,18 @@ void nodesWalkExprsPostOrder(SNodeList* pList, FNodeWalker walker, void* pContex
(void)walkExprs(pList, TRAVERSAL_POSTORDER, walker, pContext); (void)walkExprs(pList, TRAVERSAL_POSTORDER, walker, pContext);
} }
static void checkParamIsFunc(SFunctionNode *pFunc) {
int32_t numOfParams = LIST_LENGTH(pFunc->pParameterList);
if (numOfParams > 1) {
for (int32_t i = 0; i < numOfParams; ++i) {
SNode* pPara = nodesListGetNode(pFunc->pParameterList, i);
if (nodeType(pPara) == QUERY_NODE_FUNCTION) {
((SFunctionNode *)pPara)->node.asParam = true;
}
}
}
}
static EDealRes rewriteExprs(SNodeList* pNodeList, ETraversalOrder order, FNodeRewriter rewriter, void* pContext); static EDealRes rewriteExprs(SNodeList* pNodeList, ETraversalOrder order, FNodeRewriter rewriter, void* pContext);
static EDealRes rewriteExpr(SNode** pRawNode, ETraversalOrder order, FNodeRewriter rewriter, void* pContext) { static EDealRes rewriteExpr(SNode** pRawNode, ETraversalOrder order, FNodeRewriter rewriter, void* pContext) {
...@@ -248,9 +260,12 @@ static EDealRes rewriteExpr(SNode** pRawNode, ETraversalOrder order, FNodeRewrit ...@@ -248,9 +260,12 @@ static EDealRes rewriteExpr(SNode** pRawNode, ETraversalOrder order, FNodeRewrit
case QUERY_NODE_LOGIC_CONDITION: case QUERY_NODE_LOGIC_CONDITION:
res = rewriteExprs(((SLogicConditionNode*)pNode)->pParameterList, order, rewriter, pContext); res = rewriteExprs(((SLogicConditionNode*)pNode)->pParameterList, order, rewriter, pContext);
break; break;
case QUERY_NODE_FUNCTION: case QUERY_NODE_FUNCTION: {
res = rewriteExprs(((SFunctionNode*)pNode)->pParameterList, order, rewriter, pContext); SFunctionNode* pFunc = (SFunctionNode*)pNode;
checkParamIsFunc(pFunc);
res = rewriteExprs(pFunc->pParameterList, order, rewriter, pContext);
break; break;
}
case QUERY_NODE_REAL_TABLE: case QUERY_NODE_REAL_TABLE:
case QUERY_NODE_TEMP_TABLE: case QUERY_NODE_TEMP_TABLE:
break; // todo break; // todo
......
...@@ -1760,7 +1760,7 @@ static int32_t translateMultiResFunc(STranslateContext* pCxt, SFunctionNode* pFu ...@@ -1760,7 +1760,7 @@ static int32_t translateMultiResFunc(STranslateContext* pCxt, SFunctionNode* pFu
"%s(*) is only supported in SELECTed list", pFunc->functionName); "%s(*) is only supported in SELECTed list", pFunc->functionName);
} }
} }
if (tsKeepColumnName && 1 == LIST_LENGTH(pFunc->pParameterList) && !pFunc->node.asAlias) { if (tsKeepColumnName && 1 == LIST_LENGTH(pFunc->pParameterList) && !pFunc->node.asAlias && !pFunc->node.asParam) {
strcpy(pFunc->node.userAlias, ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->userAlias); strcpy(pFunc->node.userAlias, ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->userAlias);
strcpy(pFunc->node.aliasName, pFunc->node.userAlias); strcpy(pFunc->node.aliasName, pFunc->node.userAlias);
} }
......
...@@ -4,6 +4,8 @@ from util.cases import * ...@@ -4,6 +4,8 @@ from util.cases import *
from util.gettime import * from util.gettime import *
class TDTestCase: class TDTestCase:
updatecfgDict = {'keepColumnName': 1}
def init(self, conn, logSql, replicaVar=1): def init(self, conn, logSql, replicaVar=1):
self.replicaVar = int(replicaVar) self.replicaVar = int(replicaVar)
tdLog.debug(f"start to excute {__file__}") tdLog.debug(f"start to excute {__file__}")
...@@ -185,8 +187,16 @@ class TDTestCase: ...@@ -185,8 +187,16 @@ class TDTestCase:
elif precision.lower() == 'ns': elif precision.lower() == 'ns':
for i in range(len(self.ts_str)): for i in range(len(self.ts_str)):
tdSql.checkEqual(tdSql.queryResult[i][0],int(((date_time[i])-self.subtractor*1000000000))) tdSql.checkEqual(tdSql.queryResult[i][0],int(((date_time[i])-self.subtractor*1000000000)))
def function_multi_res_param(self):
tdSql.execute(f'drop database if exists {self.dbname}')
tdSql.execute(f'create database {self.dbname}')
tdSql.execute(f'use {self.dbname}')
tdSql.execute(f'create table {self.ntbname} (ts timestamp,c0 int)')
tdSql.execute(f'insert into {self.ntbname} values("2023-01-01 00:00:00",1)')
tdSql.execute(f'insert into {self.ntbname} values("2023-01-01 00:01:00",2)')
tdSql.query(f'select timediff(last(ts), first(ts)) from {self.ntbname}')
tdSql.checkData(0, 0, 60000)
...@@ -194,6 +204,7 @@ class TDTestCase: ...@@ -194,6 +204,7 @@ class TDTestCase:
self.function_check_ntb() self.function_check_ntb()
self.function_check_stb() self.function_check_stb()
self.function_without_param() self.function_without_param()
self.function_multi_res_param()
def stop(self): def stop(self):
tdSql.close() tdSql.close()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册