From 3eb1aaf8df1ef421c46e4f731f5b18386e1503fb Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Tue, 2 Nov 2021 10:16:42 +0800 Subject: [PATCH] for agg expr, only support agg1 + agg2 or agg1 + value --- src/client/src/tscSQLParser.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 9a88ff8437..0f8118e720 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -2031,13 +2031,7 @@ static bool willProcessFunctionWithExpr(const tSqlExprItem* pItem) { if (TSDB_FUNC_IS_SCALAR(functionId)) { return true; - } else if (functionId == TSDB_FUNC_SUM || - functionId == TSDB_FUNC_AVG || - functionId == TSDB_FUNC_MAX || - functionId == TSDB_FUNC_MIN) { - return true; } - return false; } @@ -4449,6 +4443,24 @@ static int32_t validateSQLExprTerm(SSqlCmd* pCmd, tSqlExpr* pExpr, if (ret != TSDB_CODE_SUCCESS) { return ret; } + + { + tSqlExpr* leftChild = pExpr->pLeft; + tSqlExpr* rightChild = pExpr->pRight; + // return invalid operation when one child aggregate and the other child scalar or column + if (leftChild->type == SQL_NODE_SQLFUNCTION && !TSDB_FUNC_IS_SCALAR(leftChild->functionId)) { + if ((rightChild->type == SQL_NODE_SQLFUNCTION && TSDB_FUNC_IS_SCALAR(rightChild->functionId)) || + rightChild->type == SQL_NODE_TABLE_COLUMN) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + } + if (rightChild->type == SQL_NODE_SQLFUNCTION && !TSDB_FUNC_IS_SCALAR(rightChild->functionId)) { + if ((leftChild->type == SQL_NODE_SQLFUNCTION && TSDB_FUNC_IS_SCALAR(leftChild->functionId)) || + leftChild->type == SQL_NODE_TABLE_COLUMN) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + } + } if (uidLeft != uidRight && uidLeft != 0 && uidRight != 0) { return TSDB_CODE_TSC_INVALID_OPERATION; -- GitLab