From 363194fa9b07079df848e9d2ab27d0164a001be2 Mon Sep 17 00:00:00 2001 From: slzhou Date: Sat, 7 May 2022 21:03:08 +0800 Subject: [PATCH 1/2] feature(udf): enhance test case with null value --- tests/script/tsim/query/udf.sim | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/script/tsim/query/udf.sim b/tests/script/tsim/query/udf.sim index 7e957680a6..f583d91e65 100644 --- a/tests/script/tsim/query/udf.sim +++ b/tests/script/tsim/query/udf.sim @@ -64,6 +64,35 @@ if $data00 != 1.414213562 then return -1 endi +sql insert into t2 values(now+2s, 1, null)(now+3s, null, 2); +sql select udf1(f1, f2) from t2; +print $rows , $data00 , $data10 , $data20 , $data30 +if $rows != 4 then + return -1 +endi +if $data00 != 88 then + return -1 +endi +if $data10 != 88 then + return -1 +endi + +if $data20 != NULL then + return -1 +endi + +if $data30 != NULL then + return -1 +endi + +sql select udf2(f1, f2) from t2; +print $rows, $data00 +if $rows != 1 then + return -1 +endi +if $data00 != 2.645751311 then + return -1 +endi #sql drop function udf1; #sql drop function udf2; system sh/exec.sh -n dnode1 -s stop -x SIGTERM From c5ef2994345428349a9680c1217e14e00c4f778b Mon Sep 17 00:00:00 2001 From: slzhou Date: Sat, 7 May 2022 21:22:43 +0800 Subject: [PATCH 2/2] feature(udf): implement drop function --- source/libs/parser/src/parTranslater.c | 10 ++++++++++ tests/script/tsim/query/udf.sim | 16 ++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index faf920ead0..5ad488e214 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -3127,6 +3127,13 @@ static int32_t translateCreateFunction(STranslateContext* pCxt, SCreateFunctionS return code; } +static int32_t translateDropFunction(STranslateContext* pCxt, SDropFunctionStmt* pStmt) { + SDropFuncReq req = {0}; + strcpy(req.name, pStmt->funcName); + req.igNotExists = pStmt->ignoreNotExists; + return buildCmdMsg(pCxt, TDMT_MND_DROP_FUNC, (FSerializeFunc)tSerializeSDropFuncReq, &req); +} + static int32_t translateGrant(STranslateContext* pCxt, SGrantStmt* pStmt) { SAlterUserReq req = {0}; if (PRIVILEGE_TYPE_TEST_MASK(pStmt->privileges, PRIVILEGE_TYPE_ALL) || @@ -3266,6 +3273,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { case QUERY_NODE_CREATE_FUNCTION_STMT: code = translateCreateFunction(pCxt, (SCreateFunctionStmt*)pNode); break; + case QUERY_NODE_DROP_FUNCTION_STMT: + code = translateDropFunction(pCxt, (SDropFunctionStmt*)pNode); + break; case QUERY_NODE_GRANT_STMT: code = translateGrant(pCxt, (SGrantStmt*)pNode); break; diff --git a/tests/script/tsim/query/udf.sim b/tests/script/tsim/query/udf.sim index f583d91e65..cabb88ea09 100644 --- a/tests/script/tsim/query/udf.sim +++ b/tests/script/tsim/query/udf.sim @@ -93,6 +93,18 @@ endi if $data00 != 2.645751311 then return -1 endi -#sql drop function udf1; -#sql drop function udf2; +sql drop function udf1; +sql show functions; +if $rows != 1 then + return -1 +endi +if $data00 != @udf2@ then + return -1 + endi +sql drop function udf2; +sql show functions; +if $rows != 0 then + return -1 +endi + system sh/exec.sh -n dnode1 -s stop -x SIGTERM