Merge pull request #24600 from taosdata/fix/xsren/TD-28447/orderByFuncParamFirstHitColumn
Fix/xsren/td 28447/order by func param first hit column
This commit is contained in:
commit
823981b9b2
|
@ -214,14 +214,15 @@ void nodesWalkExprsPostOrder(SNodeList* pList, FNodeWalker walker, void* pContex
|
|||
(void)walkExprs(pList, TRAVERSAL_POSTORDER, walker, pContext);
|
||||
}
|
||||
|
||||
static void checkParamIsFunc(SFunctionNode *pFunc) {
|
||||
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;
|
||||
}
|
||||
for (int32_t i = 0; i < numOfParams; ++i) {
|
||||
SNode* pPara = nodesListGetNode(pFunc->pParameterList, i);
|
||||
if (numOfParams > 1 && nodeType(pPara) == QUERY_NODE_FUNCTION) {
|
||||
((SFunctionNode*)pPara)->node.asParam = true;
|
||||
}
|
||||
if (nodeType(pPara) == QUERY_NODE_COLUMN) {
|
||||
((SColumnNode*)pPara)->node.asParam = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1323,7 +1323,7 @@ static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode** pCol) {
|
|||
res = translateColumnWithPrefix(pCxt, pCol);
|
||||
} else {
|
||||
bool found = false;
|
||||
if (SQL_CLAUSE_ORDER_BY == pCxt->currClause) {
|
||||
if (SQL_CLAUSE_ORDER_BY == pCxt->currClause && !(*pCol)->node.asParam) {
|
||||
res = translateColumnUseAlias(pCxt, pCol, &found);
|
||||
}
|
||||
if (DEAL_RES_ERROR != res && !found) {
|
||||
|
@ -1333,6 +1333,10 @@ static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode** pCol) {
|
|||
res = translateColumnWithoutPrefix(pCxt, pCol);
|
||||
}
|
||||
}
|
||||
if(SQL_CLAUSE_ORDER_BY == pCxt->currClause && !(*pCol)->node.asParam
|
||||
&& res != DEAL_RES_CONTINUE && res != DEAL_RES_END) {
|
||||
res = translateColumnUseAlias(pCxt, pCol, &found);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -302,6 +302,11 @@ class TDTestCase:
|
|||
|
||||
tdSql.error(f"SELECT last(ts) as t2, ts FROM t1 order by last(t2)")
|
||||
|
||||
tdSql.execute(f"alter local 'keepColumnName' '1'")
|
||||
tdSql.no_error(f"SELECT last(ts), first(ts) FROM t1 order by last(ts)")
|
||||
tdSql.no_error(f"SELECT last(c1), first(c1) FROM t1 order by last(c1)")
|
||||
tdSql.error(f"SELECT last(ts) as t, first(ts) as t FROM t1 order by last(t)")
|
||||
|
||||
def queryOrderByAmbiguousName(self):
|
||||
tdSql.error(sql="select c1 as name, c2 as name, c3 from t1 order by name", expectErrInfo='ambiguous',
|
||||
fullMatched=False)
|
||||
|
|
|
@ -20,9 +20,10 @@ class TDTestCase:
|
|||
tdSql.execute("insert into td_28068.ct4 using td_28068.st (branch, scenario) tags ('3.1', 'scenario2') values (now(), 'query1', 9,10);")
|
||||
|
||||
def run(self):
|
||||
tdSql.error('select last(ts) as ts, last(branch) as branch, last(scenario) as scenario, last(test_case) as test_case from td_28068.st group by branch, scenario order by last(branch);')
|
||||
tdSql.error('select last(ts) as ts, last(branch) as branch1, last(scenario) as scenario, last(test_case) as test_case from td_28068.st group by branch, scenario order by last(branch), last(scenario); ')
|
||||
|
||||
tdSql.query('select last(ts) as ts, last(branch) as branch, last(scenario) as scenario, last(test_case) as test_case from td_28068.st group by branch, scenario order by last(branch);')
|
||||
tdSql.checkRows(4)
|
||||
tdSql.query('select last(ts) as ts, last(branch) as branch1, last(scenario) as scenario, last(test_case) as test_case from td_28068.st group by branch, scenario order by last(branch), last(scenario); ')
|
||||
tdSql.checkRows(4)
|
||||
tdSql.query('select last(ts) as ts, last(branch) as branch1, last(scenario) as scenario, last(test_case) as test_case from td_28068.st group by branch, scenario order by last(branch); ')
|
||||
tdSql.checkRows(4)
|
||||
|
||||
|
|
Loading…
Reference in New Issue