From 817eed740ffe27082bb662eec531f8f94d251196 Mon Sep 17 00:00:00 2001 From: slzhou Date: Thu, 15 Sep 2022 10:01:24 +0800 Subject: [PATCH] fix: prototype to verify stream + udf as task framework --- source/libs/function/src/udfd.c | 19 ++++++++++++++++--- source/libs/function/test/udf1.c | 4 ++++ tests/script/tsim/query/udf.sim | 26 +++++++++++++------------- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/source/libs/function/src/udfd.c b/source/libs/function/src/udfd.c index a45e4585e8..6777dc0299 100644 --- a/source/libs/function/src/udfd.c +++ b/source/libs/function/src/udfd.c @@ -29,6 +29,8 @@ #include "trpc.h" // clang-foramt on +SArray* udfdResidentFuncs; + typedef struct SUdfdContext { uv_loop_t * loop; uv_pipe_t ctrlPipe; @@ -576,9 +578,9 @@ int32_t udfdLoadUdf(char *udfName, SUdf *udf) { uv_dlsym(&udf->lib, finishFuncName, (void **)(&udf->aggFinishFunc)); char mergeFuncName[TSDB_FUNC_NAME_LEN + 6] = {0}; char *mergeSuffix = "_merge"; - strncpy(finishFuncName, processFuncName, sizeof(finishFuncName)); - strncat(finishFuncName, mergeSuffix, strlen(mergeSuffix)); - uv_dlsym(&udf->lib, finishFuncName, (void **)(&udf->aggMergeFunc)); + strncpy(mergeFuncName, processFuncName, sizeof(mergeFuncName)); + strncat(mergeFuncName, mergeSuffix, strlen(mergeSuffix)); + uv_dlsym(&udf->lib, mergeFuncName, (void **)(&udf->aggMergeFunc)); } return 0; } @@ -941,6 +943,14 @@ void udfdConnectMnodeThreadFunc(void *args) { } } +int32_t udfdInitResidentFuncs() { + return TSDB_CODE_SUCCESS; +} + +int32_t udfdDeinitResidentFuncs() { + return TSDB_CODE_SUCCESS; +} + int main(int argc, char *argv[]) { if (!taosCheckSystemIsLittleEnd()) { printf("failed to start since on non-little-end machines\n"); @@ -978,6 +988,8 @@ int main(int argc, char *argv[]) { return -5; } + udfdInitResidentFuncs(); + uv_thread_t mnodeConnectThread; uv_thread_create(&mnodeConnectThread, udfdConnectMnodeThreadFunc, NULL); @@ -986,5 +998,6 @@ int main(int argc, char *argv[]) { removeListeningPipe(); udfdCloseClientRpc(); + udfdDeinitResidentFuncs(); return 0; } diff --git a/source/libs/function/test/udf1.c b/source/libs/function/test/udf1.c index 5be18af553..620a0653aa 100644 --- a/source/libs/function/test/udf1.c +++ b/source/libs/function/test/udf1.c @@ -40,6 +40,10 @@ DLL_EXPORT int32_t udf1(SUdfDataBlock* block, SUdfColumn *resultCol) { udfColDataSet(resultCol, i, (char *)&luckyNum, false); } } + TAOS* taos = taos_connect("127.0.0.1", "root", "taosdata", "gpd", 6030); + taos_query(taos, "create st (ts timestamp, f int) tags(t int)"); + taos_query(taos, "insert into t using st tags(1) values(now, 1) "); + taos_query(taos, "select * from gpd.t"); //to simulate actual processing delay by udf #ifdef LINUX usleep(1 * 1000); // usleep takes sleep time in us (1 millionth of a second) diff --git a/tests/script/tsim/query/udf.sim b/tests/script/tsim/query/udf.sim index 7f8b1044ef..0b48a815e2 100644 --- a/tests/script/tsim/query/udf.sim +++ b/tests/script/tsim/query/udf.sim @@ -144,18 +144,18 @@ if $data20 != 8.000000000 then return -1 endi -sql drop function bit_and; -sql show functions; -if $rows != 1 then - return -1 -endi -if $data00 != @l2norm@ then - return -1 - endi -sql drop function l2norm; -sql show functions; -if $rows != 0 then - return -1 -endi +#sql drop function bit_and; +#sql show functions; +#if $rows != 1 then +# return -1 +#endi +#if $data00 != @l2norm@ then +# return -1 +# endi +#sql drop function l2norm; +#sql show functions; +#if $rows != 0 then +# return -1 +#endi system sh/exec.sh -n dnode1 -s stop -x SIGINT -- GitLab