fix: orderby function first hit column
This commit is contained in:
parent
8670d8c962
commit
251585b49c
|
@ -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;
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue