From 3eaa88df302bb7cbbeb4633101e5c22c66d583ec Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Thu, 17 Mar 2022 18:20:54 +0800 Subject: [PATCH] modify value is null in nchar compare --- src/client/src/tscSQLParser.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index c4f093156e..e8c3991aac 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -6852,6 +6852,7 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq const char* msg5 = "only primary timestamp/column in top/bottom function allowed as order column"; const char* msg6 = "only primary timestamp allowed as the second order column"; const char* msg7 = "only primary timestamp/column in groupby clause allowed as order column"; + const char* msg8 = "only column in groupby clause allowed as order column"; const char* msg10 = "not support distinct mixed with order by"; const char* msg11 = "not support order with udf"; const char* msg12 = "order by tags not supported with diff/derivative/csum/mavg/stateCount/stateDuration"; @@ -7064,16 +7065,26 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq if (!validOrder) { return invalidOperationMsg(pMsgBuf, msg7); } + pQueryInfo->groupbyExpr.orderType = pItem->sortOrder; }else if (isTopBottomUniqueQuery(pQueryInfo)) { - int32_t pos = tscExprTopBottomIndex(pQueryInfo); - assert(pos > 0); - SExprInfo* pExpr = tscExprGet(pQueryInfo, pos - 1); - assert(pExpr->base.functionId == TSDB_FUNC_TS); + SArray *columnInfo = pQueryInfo->groupbyExpr.columnInfo; + if (columnInfo != NULL && taosArrayGetSize(columnInfo) > 0) { + SColIndex* pColIndex = taosArrayGet(columnInfo, 0); - pExpr = tscExprGet(pQueryInfo, pos); + if (pColIndex->colIndex != index.columnIndex) { + return invalidOperationMsg(pMsgBuf, msg8); + } + } else { + int32_t pos = tscExprTopBottomIndex(pQueryInfo); + assert(pos > 0); + SExprInfo* pExpr = tscExprGet(pQueryInfo, pos - 1); + assert(pExpr->base.functionId == TSDB_FUNC_TS); - if (pExpr->base.colInfo.colIndex != index.columnIndex && index.columnIndex != PRIMARYKEY_TIMESTAMP_COL_INDEX) { - return invalidOperationMsg(pMsgBuf, msg5); + pExpr = tscExprGet(pQueryInfo, pos); + + if (pExpr->base.colInfo.colIndex != index.columnIndex && index.columnIndex != PRIMARYKEY_TIMESTAMP_COL_INDEX) { + return invalidOperationMsg(pMsgBuf, msg5); + } } pQueryInfo->order.order = pItem->sortOrder; pQueryInfo->order.orderColId = pSchema[index.columnIndex].colId; -- GitLab