diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 67df5ac8e825c2efdd8159c706518a6caa55aa89..891879e6b2d81a1ca0eaefe1182df201dfacdd20 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -1286,6 +1286,17 @@ static int32_t validateStateWindowNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SS return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6); } + size_t size = tscNumOfExprs(pQueryInfo); + for (int32_t i = 0; i < size; ++i) { + SExprInfo* pExpr = tscExprGet(pQueryInfo, i); + assert(pExpr != NULL); + + int32_t functionId = pExpr->base.functionId; + if (functionId == TSDB_FUNC_CSUM || functionId == TSDB_FUNC_MAVG) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6); + } + } + tscColumnListInsert(pQueryInfo->colList, index.columnIndex, pTableMeta->id.uid, pSchema); SColIndex colIndex = { .colIndex = index.columnIndex, .flag = TSDB_COL_NORMAL, .colId = pSchema->colId }; taosArrayPush(pGroupExpr->columnInfo, &colIndex); @@ -7648,8 +7659,8 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd, SQueryInfo* pQu int32_t f = pExpr->base.functionId; if ((f == TSDB_FUNC_PRJ && pExpr->base.numOfParams == 0) || f == TSDB_FUNC_DIFF || f == TSDB_FUNC_SCALAR_EXPR || f == TSDB_FUNC_DERIVATIVE || - f == TSDB_FUNC_CSUM || f == TSDB_FUNC_MAVG || f == TSDB_FUNC_STATE_COUNT || - f == TSDB_FUNC_STATE_DURATION) + f == TSDB_FUNC_CSUM || f == TSDB_FUNC_MAVG || + f == TSDB_FUNC_STATE_COUNT || f == TSDB_FUNC_STATE_DURATION) { isProjectionFunction = true; break; @@ -8649,8 +8660,13 @@ int32_t validateFunctionFromUpstream(SQueryInfo* pQueryInfo, char* msg) { SExprInfo* pExpr = tscExprGet(pQueryInfo, i); int32_t f = pExpr->base.functionId; - if (f == TSDB_FUNC_DERIVATIVE || f == TSDB_FUNC_TWA || f == TSDB_FUNC_IRATE || f == TSDB_FUNC_DIFF || f == TSDB_FUNC_ELAPSED || - f == TSDB_FUNC_STATE_COUNT || f == TSDB_FUNC_STATE_DURATION) { + if (f == TSDB_FUNC_DERIVATIVE || + f == TSDB_FUNC_TWA || + f == TSDB_FUNC_IRATE || + f == TSDB_FUNC_DIFF || + f == TSDB_FUNC_ELAPSED || + f == TSDB_FUNC_STATE_COUNT || + f == TSDB_FUNC_STATE_DURATION) { for (int32_t j = 0; j < upNum; ++j) { SQueryInfo* pUp = taosArrayGetP(pQueryInfo->pUpstream, j); STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pUp, 0); diff --git a/tests/develop-test/2-query/TD-14763.py b/tests/develop-test/2-query/TD-14763.py new file mode 100644 index 0000000000000000000000000000000000000000..e1c82e3ebf90621217899b79d93c6a49286c1cf8 --- /dev/null +++ b/tests/develop-test/2-query/TD-14763.py @@ -0,0 +1,47 @@ +import sys +from util.log import * +from util.cases import * +from util.sql import * +from util.dnodes import tdDnodes +from math import inf + +class TDTestCase: + def caseDescription(self): + ''' + case1: [TD-14763]csum can not be used on state window + ''' + return + + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + self._conn = conn + + def run(self): + print("running {}".format(__file__)) + tdSql.execute("drop database if exists td14763") + tdSql.execute("create database td14763") + tdSql.execute("use td14763") + + tdSql.execute("create table st ( ts timestamp, i int, b bool) tags (t1 int)") + tdSql.execute("create table ct1 using st tags(1)") + tdSql.execute("create table ct2 using st tags(2)") + + for i in range(0, 4000, 2): + b = True if i%3 == 0 else False + tdSql.execute("insert into ct1 values(now + {}a, {}, {})".format(i, i, b)) + tdSql.execute("insert into ct2 values(now + {}a, {}, {})".format(i+1, i+1, b)) + + tdSql.error("select csum(i) from ct1 state_window(b)") + tdSql.error("select csum(i) from (select * from st) state_window(b)") + tdSql.query("select csum(i) from ct1"); + + tdSql.execute('drop database td14763') + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) + diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index 77ab1f3b6b3a8fec48b38caf1e01c23514331fbc..ca3586a95e8bd0896206fa3ee17b8016cf848e7f 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -638,6 +638,7 @@ 6,,pytest,python3 test.py -f alter/alterColMultiTimes.py 6,,develop-test,python3 ./test.py -f 2-query/ts_2016.py 6,,develop-test,python3 ./test.py -f 2-query/escape.py +6,,develop-test,python3 ./test.py -f 2-query/TD-14763.py 5,,system-test,python3 ./test.py -f 4-taosAdapter/taosAdapter_insert.py 5,,system-test,python3 ./test.py -f 2-query/TD-12340-12342.py 5,,system-test,python3 ./test.py -f 2-query/TD-12276.py