diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index 536fcc7b6b3141749ef8edfce743d39f61e59995..8d3729a632e6cb75ce7d96053ed000e499506097 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -128,7 +128,7 @@ int32_t tscGetDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, i */ bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo); bool tscIsTWAQuery(SQueryInfo* pQueryInfo); -bool tscIsSecondStageQuery(SQueryInfo* pQueryInfo); +bool tscIsSecondStageQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo); bool tscGroupbyColumn(SQueryInfo* pQueryInfo); bool tscIsTopbotQuery(SQueryInfo* pQueryInfo); int32_t tscGetTopbotQueryParam(SQueryInfo* pQueryInfo); @@ -137,7 +137,7 @@ bool tscNonOrderedProjectionQueryOnSTable(SSqlCmd *pCmd, SQueryInfo *pQueryInfo, bool tscOrderedProjectionQueryOnSTable(SSqlCmd *pCmd, SQueryInfo* pQueryInfo, int32_t tableIndex); bool tscIsProjectionQueryOnSTable(SSqlCmd *pCmd, SQueryInfo* pQueryInfo, int32_t tableIndex); -bool tscIsProjectionQuery(SQueryInfo* pQueryInfo); +bool tscIsProjectionQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo); bool tscIsTwoStageSTableQuery(SSqlCmd *pCmd, SQueryInfo* pQueryInfo, int32_t tableIndex); bool tscQueryTags(SQueryInfo* pQueryInfo); diff --git a/src/client/src/tscLocalMerge.c b/src/client/src/tscLocalMerge.c index 9511a10f88e6a2bdb29c55a391862e62d35aa661..1971cdb3638de126b057f38b91bf81cb0402bf62 100644 --- a/src/client/src/tscLocalMerge.c +++ b/src/client/src/tscLocalMerge.c @@ -121,6 +121,8 @@ static void tscInitSqlContext(SSqlCmd *pCmd, SLocalMerger *pReducer, tOrderDescr if (pExpr->functionId == TSDB_FUNC_TAG_DUMMY || pExpr->functionId == TSDB_FUNC_TS_DUMMY) { tagLen += pExpr->resBytes; pTagCtx[n++] = &pReducer->pCtx[i]; + } else if (pExpr->functionId < 0) { + continue; } else if ((aAggs[pExpr->functionId].status & TSDB_FUNCSTATE_SELECTIVITY) != 0) { pCtx = &pReducer->pCtx[i]; } @@ -1321,7 +1323,7 @@ bool genFinalResults(SSqlObj *pSql, SLocalMerger *pLocalMerge, bool noMoreCurren tColModelCompact(pModel, pResBuf, pModel->capacity); - if (tscIsSecondStageQuery(pQueryInfo)) { + if (tscIsSecondStageQuery(pCmd, pQueryInfo)) { doArithmeticCalculate(pQueryInfo, pResBuf, pModel->rowSize, pLocalMerge->finalModel->rowSize); } diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 7ff2e832512f5c7297843cc55ae9c964a9a7067a..ee37975208e319b526e362b6016701cbbb1338fe 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -3112,6 +3112,10 @@ bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) size_t size = tscSqlExprNumOfExprs(pQueryInfo); for (int32_t i = 0; i < size; ++i) { int32_t functionId = tscSqlExprGet(pQueryInfo, i)->functionId; + if (functionId < 0) { + continue; + } + if ((aAggs[functionId].status & TSDB_FUNCSTATE_STABLE) == 0) { invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); return true; @@ -6462,7 +6466,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { } // projection query on super table does not compatible with "group by" syntax - if (tscNonOrderedProjectionQueryOnSTable(pCmd, pQueryInfo, 0)) { + if (tscIsProjectionQuery(pCmd, pQueryInfo)) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); } @@ -6641,8 +6645,17 @@ void tscPrintSelectClause(SSqlObj* pSql, int32_t subClauseIndex) { char tmpBuf[1024] = {0}; int32_t tmpLen = 0; + char *name = NULL; + + if (pExpr->functionId < 0) { + SUdfInfo* pUdfInfo = taosArrayGet(pSql->cmd.pUdfInfo, -1 * pExpr->functionId - 1); + name = pUdfInfo->name; + } else { + name = aAggs[pExpr->functionId].name; + } + tmpLen = - sprintf(tmpBuf, "%s(uid:%" PRId64 ", %d)", aAggs[pExpr->functionId].name, pExpr->uid, pExpr->colInfo.colId); + sprintf(tmpBuf, "%s(uid:%" PRId64 ", %d)", name, pExpr->uid, pExpr->colInfo.colId); if (tmpLen + offset >= totalBufSize - 1) break; @@ -6988,7 +7001,7 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); } - if (!tscIsProjectionQuery(pQueryInfo) && pQueryInfo->interval.interval == 0) { + if (!tscIsProjectionQuery(pCmd, pQueryInfo) && pQueryInfo->interval.interval == 0) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg7); } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 9ebd22d8425682c6483ad60ebc07b76abb0e2d3d..ef2fdb994041c681531d20077a4b3a034c4188c2 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -888,7 +888,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { size_t output = tscNumOfFields(pQueryInfo); - if (tscIsSecondStageQuery(pQueryInfo)) { + if (tscIsSecondStageQuery(pCmd, pQueryInfo)) { pQueryMsg->secondStageOutput = htonl((int32_t) output); SSqlFuncMsg *pSqlFuncExpr1 = (SSqlFuncMsg *)pMsg; diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 2fd0b5e8bd948d4c6022fc8da46ac06bb0099659..abce8ac8ae2c8f2fdf6684eb9a3a760c6bdb5ccb 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -633,7 +633,7 @@ static int32_t tscLaunchRealSubqueries(SSqlObj* pSql) { if ((pExpr->colInfo.colId != PRIMARYKEY_TIMESTAMP_COL_INDEX) || (funcId != TSDB_FUNC_TS && funcId != TSDB_FUNC_TS_DUMMY && funcId != TSDB_FUNC_PRJ)) { - int16_t functionId = tscIsProjectionQuery(pQueryInfo)? TSDB_FUNC_PRJ : TSDB_FUNC_TS; + int16_t functionId = tscIsProjectionQuery(&pNew->cmd, pQueryInfo)? TSDB_FUNC_PRJ : TSDB_FUNC_TS; tscAddFuncInSelectClause(pQueryInfo, 0, functionId, &index, s, TSDB_COL_NORMAL); tscPrintSelectClause(pNew, 0); @@ -3486,7 +3486,7 @@ static UNUSED_FUNC bool tscHasRemainDataInSubqueryResultSet(SSqlObj *pSql) { SQueryInfo *pQueryInfo1 = tscGetQueryInfoDetail(&pSql->pSubs[i]->cmd, 0); if ((pRes1->row >= pRes1->numOfRows && tscHasReachLimitation(pQueryInfo1, pRes1) && - tscIsProjectionQuery(pQueryInfo1)) || (pRes1->numOfRows == 0)) { + tscIsProjectionQuery(&pSql->pSubs[i]->cmd, pQueryInfo1)) || (pRes1->numOfRows == 0)) { hasData = false; break; } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 58f4cb3fef9d4b87792f001d421b1c5b76f0ab2e..b4b4d130f288ec581dd7337ef0beb31106e9579a 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -198,12 +198,21 @@ bool tscOrderedProjectionQueryOnSTable(SSqlCmd *pCmd, SQueryInfo* pQueryInfo, in return pQueryInfo->order.orderColId >= 0; } -bool tscIsProjectionQuery(SQueryInfo* pQueryInfo) { +bool tscIsProjectionQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { size_t size = tscSqlExprNumOfExprs(pQueryInfo); for (int32_t i = 0; i < size; ++i) { int32_t functionId = tscSqlExprGet(pQueryInfo, i)->functionId; + if (functionId < 0) { + SUdfInfo* pUdfInfo = taosArrayGet(pCmd->pUdfInfo, -1 * functionId - 1); + if (pUdfInfo->funcType == TSDB_UDF_TYPE_AGGREGATE) { + return false; + } + + continue; + } + if (functionId != TSDB_FUNC_PRJ && functionId != TSDB_FUNC_TAGPRJ && functionId != TSDB_FUNC_TAG && functionId != TSDB_FUNC_TS && functionId != TSDB_FUNC_ARITHM) { return false; @@ -232,11 +241,7 @@ bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo) { return true; } -bool tscIsSecondStageQuery(SQueryInfo* pQueryInfo) { - if (tscIsProjectionQuery(pQueryInfo)) { - return false; - } - +bool tscIsSecondStageQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { size_t numOfOutput = tscNumOfFields(pQueryInfo); for(int32_t i = 0; i < numOfOutput; ++i) { SExprInfo* pExprInfo = tscFieldInfoGetInternalField(&pQueryInfo->fieldsInfo, i)->pArithExprInfo; @@ -245,6 +250,10 @@ bool tscIsSecondStageQuery(SQueryInfo* pQueryInfo) { } } + if (tscIsProjectionQuery(pCmd, pQueryInfo)) { + return false; + } + return false; } diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index f11a0772c8a6fdf05c1e90789ea05967fe5bcf74..e11459dedea9a79f358e41c334b5ce8c4f4579f3 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -784,9 +784,13 @@ static void doInvokeUdf(SQueryRuntimeEnv *pRuntimeEnv, SQLFunctionCtx *pCtx, int (*(udfNormalFunc)pUdfInfo->funcs[TSDB_UDF_FUNC_NORMAL])((char *)pCtx->pInput + idx * pCtx->inputType, pCtx->inputType, pCtx->inputBytes, pCtx->size, pCtx->ptsList, pCtx->pOutput, (char *)pCtx->ptsOutputBuf, &output, pCtx->outputType, pCtx->outputBytes, &pUdfInfo->init); - // set the output value exist - pCtx->resultInfo->numOfRes += output; - if (output > 0) { + if (pUdfInfo->funcType == TSDB_UDF_TYPE_AGGREGATE) { + pCtx->resultInfo->numOfRes = output; + } else { + pCtx->resultInfo->numOfRes += output; + } + + if (pCtx->resultInfo->numOfRes > 0) { pCtx->resultInfo->hasResult = DATA_SET_FLAG; } diff --git a/tests/script/general/parser/udf_dll.sim b/tests/script/general/parser/udf_dll.sim index 565c2816cb9e5d9ef4c7eac35455f78edffcd038..0f9436762adb645785ddcf9a4abaf4a5be810a34 100644 --- a/tests/script/general/parser/udf_dll.sim +++ b/tests/script/general/parser/udf_dll.sim @@ -393,32 +393,7 @@ if $rows != 28 then return -1 endi -sql select add_one(f1) from tb1 group by f1; -if $rows != 7 then - return -1 -endi - -if $data00 != 2 then - return -1 -endi -if $data10 != 3 then - return -1 -endi -if $data20 != 4 then - return -1 -endi -if $data30 != 5 then - return -1 -endi -if $data40 != 6 then - return -1 -endi -if $data50 != 7 then - return -1 -endi -if $data60 != 8 then - return -1 -endi +sql_error select add_one(f1) from tb1 group by f1; sql select sum_double(f1) from tb1 group by f1; if $rows != 7 then diff --git a/tests/script/general/parser/udf_dll_stable.sim b/tests/script/general/parser/udf_dll_stable.sim new file mode 100644 index 0000000000000000000000000000000000000000..538867784ee32381aeead40dda0fbdd8e2f52776 --- /dev/null +++ b/tests/script/general/parser/udf_dll_stable.sim @@ -0,0 +1,1078 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c walLevel -v 1 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 1 +system sh/exec.sh -n dnode1 -s start +system sh/prepare_udf.sh + +sleep 100 +sql connect +print ======================== dnode1 start + +sql create function add_one as '/tmp/add_one.so' outputtype int; +sql create aggregate function sum_double as '/tmp/sum_double.so' outputtype int; +sql show functions; +if $rows != 2 then + return -1 +endi + +sql create database db; +sql use db; +sql create stable stb1 (ts timestamp, f1 int, f2 bool, f3 binary(10)) tags(id1 int); +sql create table tb1 using stb1 tags(1); +sql insert into tb1 values ('2021-03-23 17:17:19.660', 1, true, 'tb1-1'); +sql insert into tb1 values ('2021-03-23 19:23:28.595', 2, false, 'tb1-2'); +sql insert into tb1 values ('2021-03-23 19:33:39.070', 3, true, 'tb1-3'); +sql insert into tb1 values ('2021-03-23 19:34:37.670', 4, false, 'tb1-4'); +sql insert into tb1 values ('2021-03-24 19:08:06.609', 5, true, 'tb1-5'); +sql insert into tb1 values ('2021-03-24 19:26:38.231', 6, false, 'tb1-6'); +sql insert into tb1 values ('2021-03-25 10:03:17.688', 7, true, 'tb1-7'); +sql create table tb2 using stb1 tags(2); +sql create table tb3 using stb1 tags(3); +sql create table tb4 using stb1 tags(4); +sql create table tb5 using stb1 tags(5); +sql create table tb6 using stb1 tags(6); +sql create table tb7 using stb1 tags(7); +sql create table tb8 using stb1 tags(8); +sql create table tb9 using stb1 tags(9); +sql insert into tb2 values ('2021-03-03 17:17:19.660', 1, true, 'tb2-1'); +sql insert into tb2 values ('2021-03-13 19:23:28.595', 2, false, 'tb2-2'); +sql insert into tb3 values ('2021-03-23 19:33:39.070', 3, true, 'tb3-1'); +sql insert into tb3 values ('2021-03-24 19:34:37.670', 4, false, 'tb3-2'); +sql insert into tb5 values ('2021-03-25 19:08:06.609', 1, true, 'tb5-1'); +sql insert into tb5 values ('2021-04-01 19:26:38.231', 2, false, 'tb5-2'); +sql insert into tb5 values ('2021-04-08 10:03:17.688', 3, true, 'tb5-3'); +sql insert into tb6 values ('2021-04-08 11:03:17.688', 1, true, 'tb6-1'); +sql insert into tb6 values ('2021-04-08 12:03:17.688', 2, true, 'tb6-2'); +sql insert into tb9 values ('2021-04-08 16:03:17.688', 4, true, 'tb9-1'); + +sql select add_one(f1) from tb1; +if $rows != 7 then + return -1 +endi + +if $data00 != 2 then + return -1 +endi +if $data10 != 3 then + return -1 +endi +if $data20 != 4 then + return -1 +endi +if $data30 != 5 then + return -1 +endi +if $data40 != 6 then + return -1 +endi +if $data50 != 7 then + return -1 +endi +if $data60 != 8 then + return -1 +endi + + +sql select sum_double(f1) from tb1; +if $rows != 1 then + return -1 +endi + +if $data00 != 56 then + return -1 +endi + + +sql select ts,add_one(f1),f1 from tb1; +if $rows != 7 then + return -1 +endi + +if $data00 != @21-03-23 17:17:19.660@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data10 != @21-03-23 19:23:28.595@ then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data12 != 2 then + return -1 +endi +if $data20 != @21-03-23 19:33:39.070@ then + return -1 +endi +if $data21 != 4 then + return -1 +endi +if $data22 != 3 then + return -1 +endi +if $data30 != @21-03-23 19:34:37.670@ then + return -1 +endi +if $data31 != 5 then + return -1 +endi +if $data32 != 4 then + return -1 +endi +if $data40 != @21-03-24 19:08:06.609@ then + return -1 +endi +if $data41 != 6 then + return -1 +endi +if $data42 != 5 then + return -1 +endi +if $data50 != @21-03-24 19:26:38.231@ then + return -1 +endi +if $data51 != 7 then + return -1 +endi +if $data52 != 6 then + return -1 +endi +if $data60 != @21-03-25 10:03:17.688@ then + return -1 +endi +if $data61 != 8 then + return -1 +endi +if $data62 != 7 then + return -1 +endi + + + + +sql select add_one(f1),add_one(f1) from tb1; +if $rows != 7 then + return -1 +endi + +if $data00 != 2 then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != 3 then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data20 != 4 then + return -1 +endi +if $data21 != 4 then + return -1 +endi +if $data30 != 5 then + return -1 +endi +if $data31 != 5 then + return -1 +endi +if $data40 != 6 then + return -1 +endi +if $data41 != 6 then + return -1 +endi +if $data50 != 7 then + return -1 +endi +if $data51 != 7 then + return -1 +endi +if $data60 != 8 then + return -1 +endi +if $data61 != 8 then + return -1 +endi + + +sql select add_one(f1)+1 from tb1; +if $rows != 7 then + return -1 +endi + +if $data00 != 3.000000000 then + return -1 +endi +if $data10 != 4.000000000 then + return -1 +endi +if $data20 != 5.000000000 then + return -1 +endi +if $data30 != 6.000000000 then + return -1 +endi +if $data40 != 7.000000000 then + return -1 +endi +if $data50 != 8.000000000 then + return -1 +endi +if $data60 != 9.000000000 then + return -1 +endi + + +sql select sum_double(f1)+1 from tb1; +if $rows != 1 then + return -1 +endi + +if $data00 != 57.000000000 then + return -1 +endi + + +sql select add_one(f1)+1,f1 from tb1; +if $rows != 7 then + return -1 +endi + +if $data00 != 3.000000000 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data10 != 4.000000000 then + return -1 +endi +if $data11 != 2 then + return -1 +endi +if $data20 != 5.000000000 then + return -1 +endi +if $data21 != 3 then + return -1 +endi +if $data30 != 6.000000000 then + return -1 +endi +if $data31 != 4 then + return -1 +endi +if $data40 != 7.000000000 then + return -1 +endi +if $data41 != 5 then + return -1 +endi +if $data50 != 8.000000000 then + return -1 +endi +if $data51 != 6 then + return -1 +endi +if $data60 != 9.000000000 then + return -1 +endi +if $data61 != 7 then + return -1 +endi + + +sql select sum_double(f1) from tb1 interval (10a); +if $rows != 7 then + return -1 +endi + +if $data00 != @21-03-23 17:17:19.660@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-03-23 19:23:28.590@ then + return -1 +endi +if $data11 != 4 then + return -1 +endi +if $data20 != @21-03-23 19:33:39.070@ then + return -1 +endi +if $data21 != 6 then + return -1 +endi +if $data30 != @21-03-23 19:34:37.670@ then + return -1 +endi +if $data31 != 8 then + return -1 +endi +if $data40 != @21-03-24 19:08:06.600@ then + return -1 +endi +if $data41 != 10 then + return -1 +endi +if $data50 != @21-03-24 19:26:38.230@ then + return -1 +endi +if $data51 != 12 then + return -1 +endi +if $data60 != @21-03-25 10:03:17.680@ then + return -1 +endi +if $data61 != 14 then + return -1 +endi + +sql select ts,add_one(f1) from tb1 where ts>="2021-03-23 17:00:00.000" and ts<="2021-03-24 20:00:00.000"; +if $rows != 6 then + return -1 +endi + +if $data00 != @21-03-23 17:17:19.660@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-03-23 19:23:28.595@ then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data20 != @21-03-23 19:33:39.070@ then + return -1 +endi +if $data21 != 4 then + return -1 +endi +if $data30 != @21-03-23 19:34:37.670@ then + return -1 +endi +if $data31 != 5 then + return -1 +endi +if $data40 != @21-03-24 19:08:06.609@ then + return -1 +endi +if $data41 != 6 then + return -1 +endi +if $data50 != @21-03-24 19:26:38.231@ then + return -1 +endi +if $data51 != 7 then + return -1 +endi + +sql select sum_double(f1) from tb1 where ts>="2021-03-23 17:00:00.000" and ts<="2021-03-24 20:00:00.000" interval (1h); +if $rows != 3 then + return -1 +endi + +if $data00 != @21-03-23 17:00:00.000@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-03-23 19:00:00.000@ then + return -1 +endi +if $data11 != 18 then + return -1 +endi +if $data20 != @21-03-24 19:00:00.000@ then + return -1 +endi +if $data21 != 22 then + return -1 +endi + + +sql select sum_double(f1) from tb1 where ts>="2021-03-23 17:00:00.000" and ts<="2021-03-24 20:00:00.000" interval (1h) fill(value,999); +if $rows != 28 then + return -1 +endi + +sql_error select add_one(f1) from tb1 group by f1; + +sql select sum_double(f1) from tb1 group by f1; +if $rows != 7 then + return -1 +endi + +if $data00 != 2 then + return -1 +endi +if $data10 != 4 then + return -1 +endi +if $data20 != 6 then + return -1 +endi +if $data30 != 8 then + return -1 +endi +if $data40 != 10 then + return -1 +endi +if $data50 != 12 then + return -1 +endi +if $data60 != 14 then + return -1 +endi + +sql select sum_double(f1) from tb1 interval (1h) order by ts desc; +if $rows != 4 then + return -1 +endi + +if $data00 != @21-03-25 10:00:00.000@ then + return -1 +endi +if $data01 != 14 then + return -1 +endi +if $data10 != @21-03-24 19:00:00.000@ then + return -1 +endi +if $data11 != 22 then + return -1 +endi +if $data20 != @21-03-23 19:00:00.000@ then + return -1 +endi +if $data21 != 18 then + return -1 +endi +if $data30 != @21-03-23 17:00:00.000@ then + return -1 +endi +if $data31 != 2 then + return -1 +endi + + +sql select add_one(f1) from tb1 limit 2; +if $rows != 2 then + return -1 +endi + +if $data00 != 2 then + return -1 +endi +if $data10 != 3 then + return -1 +endi + + +sql select sum_double(f1) from tb1 interval (1d) limit 2; +if $rows != 2 then + return -1 +endi + +if $data00 != @21-03-23 00:00:00.000@ then + return -1 +endi +if $data01 != 20 then + return -1 +endi +if $data10 != @21-03-24 00:00:00.000@ then + return -1 +endi +if $data11 != 22 then + return -1 +endi + + +sql_error select ts,sum_double(f1),f1 from tb1; +sql_error select add_one(f1),count(f1) from tb1; +sql_error select sum_double(f1),count(f1) from tb1; +sql_error select add_one(f1),top(f1,3) from tb1; +sql_error select add_one(f1) from tb1 interval(10a); + + +sql select add_one(f1) from stb1; +if $rows != 17 then + return -1 +endi + +if $data00 != 2 then + return -1 +endi +if $data10 != 3 then + return -1 +endi +if $data20 != 4 then + return -1 +endi +if $data30 != 5 then + return -1 +endi +if $data40 != 6 then + return -1 +endi +if $data50 != 7 then + return -1 +endi +if $data60 != 8 then + return -1 +endi +if $data70 != 2 then + return -1 +endi +if $data80 != 3 then + return -1 +endi +if $data90 != 4 then + return -1 +endi + + +sql select sum_double(f1) from stb1; +if $rows != 1 then + return -1 +endi + +if $data00 != 102 then + return -1 +endi + + +sql select ts,add_one(f1),f1 from stb1; +if $rows != 17 then + return -1 +endi + +if $data00 != @21-03-23 17:17:19.660@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data10 != @21-03-23 19:23:28.595@ then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data12 != 2 then + return -1 +endi +if $data20 != @21-03-23 19:33:39.070@ then + return -1 +endi +if $data21 != 4 then + return -1 +endi +if $data22 != 3 then + return -1 +endi +if $data30 != @21-03-23 19:34:37.670@ then + return -1 +endi +if $data31 != 5 then + return -1 +endi +if $data32 != 4 then + return -1 +endi +if $data40 != @21-03-24 19:08:06.609@ then + return -1 +endi +if $data41 != 6 then + return -1 +endi +if $data42 != 5 then + return -1 +endi +if $data50 != @21-03-24 19:26:38.231@ then + return -1 +endi +if $data51 != 7 then + return -1 +endi +if $data52 != 6 then + return -1 +endi +if $data60 != @21-03-25 10:03:17.688@ then + return -1 +endi +if $data61 != 8 then + return -1 +endi +if $data62 != 7 then + return -1 +endi + + + + +sql select add_one(f1),add_one(f1) from stb1; +if $rows != 17 then + return -1 +endi + +if $data00 != 2 then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != 3 then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data20 != 4 then + return -1 +endi +if $data21 != 4 then + return -1 +endi +if $data30 != 5 then + return -1 +endi +if $data31 != 5 then + return -1 +endi +if $data40 != 6 then + return -1 +endi +if $data41 != 6 then + return -1 +endi +if $data50 != 7 then + return -1 +endi +if $data51 != 7 then + return -1 +endi +if $data60 != 8 then + return -1 +endi +if $data61 != 8 then + return -1 +endi + + +sql select add_one(f1)+1 from stb1; +if $rows != 17 then + return -1 +endi + +if $data00 != 3.000000000 then + return -1 +endi +if $data10 != 4.000000000 then + return -1 +endi +if $data20 != 5.000000000 then + return -1 +endi +if $data30 != 6.000000000 then + return -1 +endi +if $data40 != 7.000000000 then + return -1 +endi +if $data50 != 8.000000000 then + return -1 +endi +if $data60 != 9.000000000 then + return -1 +endi + + +sql select sum_double(f1)+1 from stb1; +if $rows != 1 then + return -1 +endi + +if $data00 != 103.000000000 then + return -1 +endi + + +sql select add_one(f1)+1,f1 from stb1; +if $rows != 17 then + return -1 +endi + +if $data00 != 3.000000000 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data10 != 4.000000000 then + return -1 +endi +if $data11 != 2 then + return -1 +endi +if $data20 != 5.000000000 then + return -1 +endi +if $data21 != 3 then + return -1 +endi +if $data30 != 6.000000000 then + return -1 +endi +if $data31 != 4 then + return -1 +endi +if $data40 != 7.000000000 then + return -1 +endi +if $data41 != 5 then + return -1 +endi +if $data50 != 8.000000000 then + return -1 +endi +if $data51 != 6 then + return -1 +endi +if $data60 != 9.000000000 then + return -1 +endi +if $data61 != 7 then + return -1 +endi + + +sql select sum_double(f1) from stb1 interval (10a); +if $rows != 16 then + return -1 +endi + +if $data00 != @21-03-03 17:17:19.660@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-03-13 19:23:28.590@ then + return -1 +endi +if $data11 != 4 then + return -1 +endi +if $data20 != @21-03-23 17:17:19.660@ then + return -1 +endi +if $data21 != 2 then + return -1 +endi +if $data30 != @21-03-23 19:23:28.590@ then + return -1 +endi +if $data31 != 4 then + return -1 +endi +if $data40 != @21-03-23 19:33:39.070@ then + return -1 +endi +if $data41 != 12 then + return -1 +endi +if $data50 != @21-03-23 19:34:37.670@ then + return -1 +endi +if $data51 != 8 then + return -1 +endi +if $data60 != @21-03-24 19:08:06.600@ then + return -1 +endi +if $data61 != 10 then + return -1 +endi +if $data70 != @21-03-24 19:26:38.230@ then + return -1 +endi +if $data71 != 12 then + return -1 +endi +if $data80 != @21-03-24 19:34:37.670@ then + return -1 +endi +if $data81 != 8 then + return -1 +endi +if $data90 != @21-03-25 10:03:17.680@ then + return -1 +endi +if $data91 != 14 then + return -1 +endi + + +sql select ts,add_one(f1) from stb1 where ts>="2021-03-23 17:00:00.000" and ts<="2021-03-24 20:00:00.000"; +if $rows != 8 then + return -1 +endi + +if $data00 != @21-03-23 17:17:19.660@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-03-23 19:23:28.595@ then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data20 != @21-03-23 19:33:39.070@ then + return -1 +endi +if $data21 != 4 then + return -1 +endi +if $data30 != @21-03-23 19:34:37.670@ then + return -1 +endi +if $data31 != 5 then + return -1 +endi +if $data40 != @21-03-24 19:08:06.609@ then + return -1 +endi +if $data41 != 6 then + return -1 +endi +if $data50 != @21-03-24 19:26:38.231@ then + return -1 +endi +if $data51 != 7 then + return -1 +endi +if $data60 != @21-03-23 19:33:39.070@ then + return -1 +endi +if $data61 != 4 then + return -1 +endi +if $data70 != @21-03-24 19:34:37.670@ then + return -1 +endi +if $data71 != 5 then + return -1 +endi + +sql select sum_double(f1) from stb1 where ts>="2021-03-23 17:00:00.000" and ts<="2021-03-24 20:00:00.000" interval (1h); +if $rows != 3 then + return -1 +endi + +if $data00 != @21-03-23 17:00:00.000@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-03-23 19:00:00.000@ then + return -1 +endi +if $data11 != 24 then + return -1 +endi +if $data20 != @21-03-24 19:00:00.000@ then + return -1 +endi +if $data21 != 30 then + return -1 +endi + + +sql select sum_double(f1) from stb1 where ts>="2021-03-23 17:00:00.000" and ts<="2021-03-24 20:00:00.000" interval (1h) fill(value,999); +if $rows != 28 then + return -1 +endi +if $data00 != @21-03-23 17:00:00.000@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-03-23 18:00:00.000@ then + return -1 +endi +if $data11 != 999 then + return -1 +endi +if $data20 != @21-03-23 19:00:00.000@ then + return -1 +endi +if $data21 != 24 then + return -1 +endi + +sql_error select add_one(f1) from stb1 group by f1; + +sql select sum_double(f1) from stb1 group by f1; +if $rows != 7 then + return -1 +endi + +if $data00 != 8 then + return -1 +endi +if $data10 != 16 then + return -1 +endi +if $data20 != 18 then + return -1 +endi +if $data30 != 24 then + return -1 +endi +if $data40 != 10 then + return -1 +endi +if $data50 != 12 then + return -1 +endi +if $data60 != 14 then + return -1 +endi + +sql select sum_double(f1) from stb1 interval (1h) order by ts desc; +if $rows != 12 then + return -1 +endi + +if $data00 != @21-04-08 16:00:00.000@ then + return -1 +endi +if $data01 != 8 then + return -1 +endi +if $data10 != @21-04-08 12:00:00.000@ then + return -1 +endi +if $data11 != 4 then + return -1 +endi +if $data20 != @21-04-08 11:00:00.000@ then + return -1 +endi +if $data21 != 2 then + return -1 +endi +if $data30 != @21-04-08 10:00:00.000@ then + return -1 +endi +if $data31 != 6 then + return -1 +endi +if $data40 != @21-04-01 19:00:00.000@ then + return -1 +endi +if $data41 != 4 then + return -1 +endi +if $data50 != @21-03-25 19:00:00.000@ then + return -1 +endi +if $data51 != 2 then + return -1 +endi +if $data60 != @21-03-25 10:00:00.000@ then + return -1 +endi +if $data61 != 14 then + return -1 +endi +if $data70 != @21-03-24 19:00:00.000@ then + return -1 +endi +if $data71 != 30 then + return -1 +endi +if $data80 != @21-03-23 19:00:00.000@ then + return -1 +endi +if $data81 != 24 then + return -1 +endi +if $data90 != @21-03-23 17:00:00.000@ then + return -1 +endi +if $data91 != 2 then + return -1 +endi + + +sql select add_one(f1) from stb1 limit 2; +if $rows != 2 then + return -1 +endi + +if $data00 != 2 then + return -1 +endi +if $data10 != 3 then + return -1 +endi + + +sql select sum_double(f1) from stb1 interval (1d) limit 2; +if $rows != 2 then + return -1 +endi + +if $data00 != @21-03-03 00:00:00.000@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-03-13 00:00:00.000@ then + return -1 +endi +if $data11 != 4 then + return -1 +endi + + +sql_error select ts,sum_double(f1),f1 from stb1; +sql_error select add_one(f1),count(f1) from stb1; +sql_error select sum_double(f1),count(f1) from stb1; +sql_error select add_one(f1),top(f1,3) from stb1; +sql_error select add_one(f1) from stb1 interval(10a); + +system sh/exec.sh -n dnode1 -s stop -x SIGINT + + + + + + diff --git a/tests/script/sh/sum_double.c b/tests/script/sh/sum_double.c index d814228d8a28f8b982673909a90fbcfbb2734d7c..45771eb687b11a4b6d64a2bc226ba204d190c42f 100644 --- a/tests/script/sh/sum_double.c +++ b/tests/script/sh/sum_double.c @@ -10,6 +10,9 @@ typedef struct SUdfInit{ int const_item; /* 0 if result is independent of arguments */ } SUdfInit; +#define TSDB_DATA_INT_NULL 0x80000000L + + void sum_double(char* data, short itype, short ibytes, int numOfRows, long long* ts, char* dataOutput, char* tsOutput, int* numOfOutput, short otype, short obytes, SUdfInit* buf) { int i; @@ -17,14 +20,17 @@ void sum_double(char* data, short itype, short ibytes, int numOfRows, long long* printf("sum_double input data:%p, type:%d, rows:%d, ts:%p,%lld, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, itype, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf); if (itype == 4) { r=*(int *)dataOutput; + *numOfOutput=0; + for(i=0;i 0) { + *numOfOutput=1; + } else { + *numOfOutput=0; + } printf("sum_double_merge, dataoutput:%d, numOfOutput:%d\n", *(int *)dataOutput, *numOfOutput); }