From d4a540012f9aa8812865911b8995bcd75b9d54dc Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 5 Jan 2022 19:09:50 +0800 Subject: [PATCH] [TD-12614](query): Functions related to timeline should not support inner query group by tbname --- src/client/src/tscSQLParser.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 561f7343ea..af4e2e9c7c 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -2668,6 +2668,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col const char* msg14 = "third parameter algorithm must be 'default' or 't-digest'"; const char* msg15 = "parameter is out of range [1, 1000]"; const char* msg16 = "elapsed duration should be greater than or equal to database precision"; + const char* msg17 = "elapsed/twa should not be used in nested query if inner query has group by clause"; switch (functionId) { case TSDB_FUNC_COUNT: { @@ -2727,7 +2728,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col memset(pExpr->base.aliasName, 0, tListLen(pExpr->base.aliasName)); getColumnName(pItem, pExpr->base.aliasName, pExpr->base.token,sizeof(pExpr->base.aliasName) - 1); - + SColumnList list = createColumnList(1, index.tableIndex, index.columnIndex); if (finalResult) { int32_t numOfOutput = tscNumOfFields(pQueryInfo); @@ -2792,6 +2793,17 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col } } + //for timeline related aggregation function like elapsed and twa, groupby in subquery is not allowed + //as calculation result is meaningless by mixing different childtables(timelines) results. + if ((functionId == TSDB_FUNC_ELAPSED || functionId == TSDB_FUNC_TWA) && pQueryInfo->pUpstream != NULL) { + size_t numOfUpstreams = taosArrayGetSize(pQueryInfo->pUpstream); + for (int32_t i = 0; i < numOfUpstreams; ++i) { + SQueryInfo* pSub = taosArrayGetP(pQueryInfo->pUpstream, i); + if (pSub->groupbyExpr.numOfGroupCols > 0) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg17); + } + } + } STableComInfo info = tscGetTableInfo(pTableMetaInfo->pTableMeta); -- GitLab