From dfedc1c9e4d6c76e8bfea7b7037dba48b0f05bee Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Wed, 30 Mar 2022 15:52:38 +0800 Subject: [PATCH] set colId of scalar expr to first column column ID so that order by operator function correctly --- src/client/src/tscSQLParser.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 13bcdd7eca..b9627cc297 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -1849,8 +1849,6 @@ static int32_t handleScalarTypeExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32 } } - // expr string is set as the parameter of function - SColumnIndex index = {.tableIndex = tableIndex}; tExprNode* pNode = NULL; SArray* colList = taosArrayInit(10, sizeof(SColIndex)); @@ -1889,9 +1887,20 @@ static int32_t handleScalarTypeExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32 return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); } + //set the columnIndex to first column Index so that column Id + SColumnIndex index = {.tableIndex = tableIndex}; + size_t numOfCols = taosArrayGetSize(colList); + if (numOfCols > 0) { + SColIndex* pIndex = taosArrayGet(colList, 0); + index.columnIndex = pIndex->colIndex; + } SExprInfo* pExpr = tscExprAppend(pQueryInfo, TSDB_FUNC_SCALAR_EXPR, &index, pNode->resultType, pNode->resultBytes, getNewResColId(pCmd), 0, false); + // if there are no columns, set the colId to the result column id + if (numOfCols == 0) { + pExpr->base.colInfo.colId = pExpr->base.resColId; + } char* name = (pItem->aliasName != NULL)? pItem->aliasName:pItem->pNode->exprToken.z; size_t len = MIN(sizeof(pExpr->base.aliasName), pItem->pNode->exprToken.n + 1); -- GitLab