From d9580cff5312e97ef96f6d0e5dc97b6caa03261c Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Sun, 17 Apr 2022 17:37:07 +0800 Subject: [PATCH] runudf call scalar --- source/libs/function/test/runUdf.c | 31 +++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/source/libs/function/test/runUdf.c b/source/libs/function/test/runUdf.c index 7afa459c89..7c03ed727e 100644 --- a/source/libs/function/test/runUdf.c +++ b/source/libs/function/test/runUdf.c @@ -5,6 +5,7 @@ #include "uv.h" #include "os.h" #include "tudf.h" +#include "tdatablock.h" int main(int argc, char *argv[]) { startUdfService(); @@ -23,17 +24,25 @@ int main(int argc, char *argv[]) { SEpSet epSet; setupUdf("udf1", &epSet, &handle); - //char state[5000000] = "state"; - //char input[5000000] = "input"; - int dataSize = 500; - int callCount = 2; - if (argc > 1) dataSize = atoi(argv[1]); - if (argc > 2) callCount = atoi(argv[2]); - char *state = taosMemoryMalloc(dataSize); - char *input = taosMemoryMalloc(dataSize); - //todo: call udf - taosMemoryFree(state); - taosMemoryFree(input); + SSDataBlock block = {0}; + SSDataBlock* pBlock = █ + pBlock->pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData)); + pBlock->info.numOfCols = 1; + pBlock->info.rows = 4; + for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) { + SColumnInfoData colInfo = {0}; + colInfo.info.type = TSDB_DATA_TYPE_INT; + colInfo.info.bytes = sizeof(int32_t); + colInfo.info.colId = 1; + for (int32_t j = 0; j < pBlock->info.rows; ++j) { + colDataAppendInt32(&colInfo, j, &j); + } + taosArrayPush(pBlock->pDataBlock, &colInfo); + } + + SSDataBlock output = {0}; + callUdfScalaProcess(handle, pBlock, &output); + teardownUdf(handle); stopUdfService();