From b9edd24d3f0838ed26e3a1a1eb0e4f23a1b21549 Mon Sep 17 00:00:00 2001 From: slzhou Date: Tue, 21 Mar 2023 00:38:13 -0800 Subject: [PATCH] fix: create function error for json/decimal/blob/varbinary type --- source/libs/parser/src/parTranslater.c | 9 +++++++++ tests/script/tsim/query/udf.sim | 3 +++ 2 files changed, 12 insertions(+) diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 74b32c638d..6abd9e198c 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -6393,6 +6393,15 @@ static int32_t translateCreateFunction(STranslateContext* pCxt, SCreateFunctionS if (fmIsBuiltinFunc(pStmt->funcName)) { return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_FUNCTION_NAME); } + + if (TSDB_DATA_TYPE_JSON == pStmt->outputDt.type || + TSDB_DATA_TYPE_VARBINARY == pStmt->outputDt.type || + TSDB_DATA_TYPE_DECIMAL == pStmt->outputDt.type || + TSDB_DATA_TYPE_BLOB == pStmt->outputDt.type || + TSDB_DATA_TYPE_MEDIUMBLOB == pStmt->outputDt.type) { + return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, "Unsupported output type for UDF"); + } + SCreateFuncReq req = {0}; strcpy(req.name, pStmt->funcName); req.igExists = pStmt->ignoreExists; diff --git a/tests/script/tsim/query/udf.sim b/tests/script/tsim/query/udf.sim index 0b48a815e2..66a3d811a1 100644 --- a/tests/script/tsim/query/udf.sim +++ b/tests/script/tsim/query/udf.sim @@ -29,6 +29,9 @@ else sql create function bit_and as '/tmp/udf/libbitand.so' outputtype int bufSize 8; sql create aggregate function l2norm as '/tmp/udf/libl2norm.so' outputtype double bufSize 8; endi + +sql_error create function bit_and as '/tmp/udf/libbitand.so' oputtype json; + sql show functions; if $rows != 2 then return -1 -- GitLab