From 2efab798859c7cd1522c0c86c36fe27bf63f527f Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Tue, 9 Nov 2021 17:10:28 +0800 Subject: [PATCH] set output type for no input functions and try to implement select pow(min(f1),2 from d.st --- src/client/src/tscSQLParser.c | 9 ++++++++- src/common/src/texpr.c | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index f2708025c1..12f72ba43f 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -1828,6 +1828,8 @@ static int32_t handleScalarExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t e static int32_t handleAggregateExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t exprIndex, tSqlExprItem* pItem, SColumnList* columnList, bool finalResult) { + const char* msg2 = "invalid arithmetic expression in select clause"; + columnList->num = 0; columnList->ids[0] = (SColumnIndex) {0, 0}; @@ -1862,6 +1864,11 @@ static int32_t handleAggregateExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_ } pInfo->pExpr = pExprInfo; + ret = exprTreeValidateTree(pExprInfo->pExpr); + if (ret != TSDB_CODE_SUCCESS) { + tExprTreeDestroy(pExprInfo->pExpr, NULL); + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); + } SBufferWriter bw = tbufInitWriter(NULL, false); @@ -1879,7 +1886,7 @@ static int32_t handleAggregateExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_ pSqlExpr->param[0].nType = TSDB_DATA_TYPE_BINARY; // tbufCloseWriter(&bw); // TODO there is a memory leak - + tExprTreeDestroy(pInfo->pExpr->pExpr, NULL); return TSDB_CODE_SUCCESS; } diff --git a/src/common/src/texpr.c b/src/common/src/texpr.c index 69e302206a..37244e208a 100644 --- a/src/common/src/texpr.c +++ b/src/common/src/texpr.c @@ -417,8 +417,10 @@ void exprTreeFunctionNodeTraverse(tExprNode *pExpr, int32_t numOfRows, tExprOper uint8_t numChildren = pExpr->_func.numChildren; if (numChildren == 0) { _expr_scalar_function_t scalarFn = getExprScalarFunction(pExpr->_func.functionId); - scalarFn(pExpr->_func.functionId, NULL, 0, output, order); + output->type = pExpr->resultType; + output->bytes = pExpr->resultBytes; output->numOfRows = numOfRows; + scalarFn(pExpr->_func.functionId, NULL, 0, output, order); return; } -- GitLab