From fddf3f16cf93cced260c3adf74ad9797814b5204 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Wed, 22 Mar 2023 19:09:26 +0800 Subject: [PATCH 1/4] fix: udf error check --- source/libs/parser/src/parTranslater.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 11f0a5824a..5fef06fc38 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -6396,14 +6396,16 @@ static int32_t translateCreateFunction(STranslateContext* pCxt, SCreateFunctionS 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 || + 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"); } + if (!pStmt->isAgg && pStmt->bufSize > 0) { + return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, "BUFSIZE can only be used with UDAF"); + } + SCreateFuncReq req = {0}; strcpy(req.name, pStmt->funcName); req.igExists = pStmt->ignoreExists; From e15e40abdf20a58f00c26ebd6fe0eb08213af492 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Thu, 23 Mar 2023 14:15:49 +0800 Subject: [PATCH 2/4] enh: improve error reporting information --- source/libs/parser/src/parInsertSql.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/libs/parser/src/parInsertSql.c b/source/libs/parser/src/parInsertSql.c index 3fbe23592a..5b0b5acf2b 100644 --- a/source/libs/parser/src/parInsertSql.c +++ b/source/libs/parser/src/parInsertSql.c @@ -1492,6 +1492,7 @@ static void resetEnvPreTable(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStm pStmt->pBoundCols = NULL; pStmt->usingTableProcessing = false; pStmt->fileProcessing = false; + pStmt->usingTableName.type = 0; } // input pStmt->pSql: [(field1_name, ...)] [ USING ... ] VALUES ... | FILE ... @@ -1539,6 +1540,10 @@ static int32_t checkTableClauseFirstToken(SInsertParseContext* pCxt, SVnodeModif } } + if (TK_NK_ID != pTbName->type && TK_NK_STRING != pTbName->type) { + return buildSyntaxErrMsg(&pCxt->msg, "table_name is expected", pTbName->z); + } + *pHasData = true; return TSDB_CODE_SUCCESS; } From bbd51918006e9918ec7acacb9b3d6df2420f8f5c Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Thu, 23 Mar 2023 16:32:00 +0800 Subject: [PATCH 3/4] fix: udf error check --- tests/script/tsim/query/udf.sim | 4 ++-- tests/script/tsim/query/udf_with_const.sim | 4 ++-- tests/script/tsim/query/udfpy.sim | 4 ++-- tests/script/tsim/valgrind/checkUdf.sim | 4 ++-- tests/system-test/0-others/udfTest.py | 12 ++++++------ tests/system-test/0-others/udf_cfg1.py | 4 ++-- tests/system-test/0-others/udf_cfg2.py | 12 ++++++------ tests/system-test/0-others/udf_create.py | 12 ++++++------ tests/system-test/0-others/udf_restart_taosd.py | 12 ++++++------ tests/system-test/7-tmq/tmqUdf-multCtb-snapshot0.py | 2 +- tests/system-test/7-tmq/tmqUdf-multCtb-snapshot1.py | 2 +- tests/system-test/7-tmq/tmqUdf.py | 2 +- 12 files changed, 37 insertions(+), 37 deletions(-) diff --git a/tests/script/tsim/query/udf.sim b/tests/script/tsim/query/udf.sim index 66a3d811a1..e539f11531 100644 --- a/tests/script/tsim/query/udf.sim +++ b/tests/script/tsim/query/udf.sim @@ -23,10 +23,10 @@ if $system_content == Windows_NT then return 0; endi if $system_content == Windows_NT then - sql create function bit_and as 'C:\\Windows\\Temp\\bitand.dll' outputtype int bufSize 8; + sql create function bit_and as 'C:\\Windows\\Temp\\bitand.dll' outputtype int; sql create aggregate function l2norm as 'C:\\Windows\\Temp\\l2norm.dll' outputtype double bufSize 8; else - sql create function bit_and as '/tmp/udf/libbitand.so' outputtype int bufSize 8; + sql create function bit_and as '/tmp/udf/libbitand.so' outputtype int; sql create aggregate function l2norm as '/tmp/udf/libl2norm.so' outputtype double bufSize 8; endi diff --git a/tests/script/tsim/query/udf_with_const.sim b/tests/script/tsim/query/udf_with_const.sim index 7a2a3389bd..4a12dd6868 100644 --- a/tests/script/tsim/query/udf_with_const.sim +++ b/tests/script/tsim/query/udf_with_const.sim @@ -23,9 +23,9 @@ if $system_content == Windows_NT then endi if $system_content == Windows_NT then - sql create function gpd as 'C:\\Windows\\Temp\\gpd.dll' outputtype int bufSize 8; + sql create function gpd as 'C:\\Windows\\Temp\\gpd.dll' outputtype int; else - sql create function gpd as '/tmp/udf/libgpd.so' outputtype int bufSize 8; + sql create function gpd as '/tmp/udf/libgpd.so' outputtype int; endi sql show functions; if $rows != 1 then diff --git a/tests/script/tsim/query/udfpy.sim b/tests/script/tsim/query/udfpy.sim index 7a5aa863cf..2340235daa 100644 --- a/tests/script/tsim/query/udfpy.sim +++ b/tests/script/tsim/query/udfpy.sim @@ -29,10 +29,10 @@ if $system_content == Windows_NT then return 0; endi if $system_content == Windows_NT then - sql create function bit_and as 'C:\\Windows\\Temp\\bitand.dll' outputtype int bufSize 8; + sql create function bit_and as 'C:\\Windows\\Temp\\bitand.dll' outputtype int; sql create aggregate function l2norm as 'C:\\Windows\\Temp\\l2norm.dll' outputtype double bufSize 8; else - sql create function bit_and as '/tmp/udf/libbitand.so' outputtype int bufSize 8; + sql create function bit_and as '/tmp/udf/libbitand.so' outputtype int; sql create aggregate function l2norm as '/tmp/udf/libl2norm.so' outputtype double bufSize 8; endi sql create function pybitand as '/tmp/pyudf/pybitand.py' outputtype int language 'python'; diff --git a/tests/script/tsim/valgrind/checkUdf.sim b/tests/script/tsim/valgrind/checkUdf.sim index caf316bd86..dc703e155d 100644 --- a/tests/script/tsim/valgrind/checkUdf.sim +++ b/tests/script/tsim/valgrind/checkUdf.sim @@ -15,10 +15,10 @@ sql insert into t values(now, 1)(now+1s, 2); system_content printf %OS% if $system_content == Windows_NT then - sql create function udf1 as 'C:\\Windows\\Temp\\udf1.dll' outputtype int bufSize 8; + sql create function udf1 as 'C:\\Windows\\Temp\\udf1.dll' outputtype int; sql create aggregate function udf2 as 'C:\\Windows\\Temp\\udf2.dll' outputtype double bufSize 8; else - sql create function udf1 as '/tmp/udf/libudf1.so' outputtype int bufSize 8; + sql create function udf1 as '/tmp/udf/libudf1.so' outputtype int; sql create aggregate function udf2 as '/tmp/udf/libudf2.so' outputtype double bufSize 8; endi sql show functions; diff --git a/tests/system-test/0-others/udfTest.py b/tests/system-test/0-others/udfTest.py index 15253df0c4..da77078208 100644 --- a/tests/system-test/0-others/udfTest.py +++ b/tests/system-test/0-others/udfTest.py @@ -146,7 +146,7 @@ class TDTestCase: for i in range(5): # create scalar functions - tdSql.execute("create function udf1 as '%s' outputtype int bufSize 8;"%self.libudf1) + tdSql.execute("create function udf1 as '%s' outputtype int;"%self.libudf1) # create aggregate functions @@ -171,7 +171,7 @@ class TDTestCase: tdLog.info("drop two udf functions success ") # create scalar functions - tdSql.execute("create function udf1 as '%s' outputtype int bufSize 8;"%self.libudf1) + tdSql.execute("create function udf1 as '%s' outputtype int;"%self.libudf1) # create aggregate functions @@ -562,7 +562,7 @@ class TDTestCase: # create function without buffer tdSql.execute("create aggregate function udf1 as '%s' outputtype int bufSize 8 "%self.libudf1) - tdSql.execute("create function udf2 as '%s' outputtype double bufSize 8"%self.libudf2) + tdSql.execute("create function udf2 as '%s' outputtype double"%self.libudf2) udf1_sqls ,udf2_sqls = self.try_query_sql() for scalar_sql in udf1_sqls: @@ -570,7 +570,7 @@ class TDTestCase: for aggregate_sql in udf2_sqls: tdSql.error(aggregate_sql) - tdSql.execute(" create function db as '%s' outputtype int bufSize 8 "%self.libudf1) + tdSql.execute(" create function db as '%s' outputtype int "%self.libudf1) tdSql.execute(" create aggregate function test as '%s' outputtype int bufSize 8 "%self.libudf1) tdSql.error(" select db(c1) from stb1 ") tdSql.error(" select db(c1,c6), db(c6) from stb1 ") @@ -619,9 +619,9 @@ class TDTestCase: tdLog.info(" create function name is not build_in functions ") tdSql.execute(" drop function udf1 ") tdSql.execute(" drop function udf2 ") - tdSql.error("create function max as '%s' outputtype int bufSize 8"%self.libudf1) + tdSql.error("create function max as '%s' outputtype int "%self.libudf1) tdSql.error("create aggregate function sum as '%s' outputtype double bufSize 8"%self.libudf2) - tdSql.error("create function max as '%s' outputtype int bufSize 8"%self.libudf1) + tdSql.error("create function max as '%s' outputtype int "%self.libudf1) tdSql.error("create aggregate function sum as '%s' outputtype double bufSize 8"%self.libudf2) tdSql.error("create aggregate function tbname as '%s' outputtype double bufSize 8"%self.libudf2) tdSql.error("create aggregate function function as '%s' outputtype double bufSize 8"%self.libudf2) diff --git a/tests/system-test/0-others/udf_cfg1.py b/tests/system-test/0-others/udf_cfg1.py index 35d43ea9b7..913e5fcca1 100644 --- a/tests/system-test/0-others/udf_cfg1.py +++ b/tests/system-test/0-others/udf_cfg1.py @@ -148,7 +148,7 @@ class TDTestCase: for i in range(5): # create scalar functions - tdSql.execute("create function udf1 as '%s' outputtype int bufSize 8;"%self.libudf1) + tdSql.execute("create function udf1 as '%s' outputtype int;"%self.libudf1) # create aggregate functions @@ -173,7 +173,7 @@ class TDTestCase: tdLog.info("drop two udf functions success ") # create scalar functions - tdSql.execute("create function udf1 as '%s' outputtype int bufSize 8;"%self.libudf1) + tdSql.execute("create function udf1 as '%s' outputtype int;"%self.libudf1) # create aggregate functions diff --git a/tests/system-test/0-others/udf_cfg2.py b/tests/system-test/0-others/udf_cfg2.py index 869cb098e2..cc6da81847 100644 --- a/tests/system-test/0-others/udf_cfg2.py +++ b/tests/system-test/0-others/udf_cfg2.py @@ -148,7 +148,7 @@ class TDTestCase: for i in range(5): # create scalar functions - tdSql.execute("create function udf1 as '%s' outputtype int bufSize 8;"%self.libudf1) + tdSql.execute("create function udf1 as '%s' outputtype int;"%self.libudf1) # create aggregate functions @@ -173,7 +173,7 @@ class TDTestCase: tdLog.info("drop two udf functions success ") # create scalar functions - tdSql.execute("create function udf1 as '%s' outputtype int bufSize 8;"%self.libudf1) + tdSql.execute("create function udf1 as '%s' outputtype int;"%self.libudf1) # create aggregate functions @@ -564,7 +564,7 @@ class TDTestCase: # create function without buffer tdSql.execute("create aggregate function udf1 as '%s' outputtype int bufSize 8 "%self.libudf1) - tdSql.execute("create function udf2 as '%s' outputtype double bufSize 8"%self.libudf2) + tdSql.execute("create function udf2 as '%s' outputtype double"%self.libudf2) udf1_sqls ,udf2_sqls = self.try_query_sql() for scalar_sql in udf1_sqls: @@ -572,7 +572,7 @@ class TDTestCase: for aggregate_sql in udf2_sqls: tdSql.error(aggregate_sql) - tdSql.execute(" create function db as '%s' outputtype int bufSize 8 "%self.libudf1) + tdSql.execute(" create function db as '%s' outputtype int "%self.libudf1) tdSql.execute(" create aggregate function test as '%s' outputtype int bufSize 8 "%self.libudf1) tdSql.error(" select db(c1) from stb1 ") tdSql.error(" select db(c1,c6), db(c6) from stb1 ") @@ -621,9 +621,9 @@ class TDTestCase: tdLog.info(" create function name is not build_in functions ") tdSql.execute(" drop function udf1 ") tdSql.execute(" drop function udf2 ") - tdSql.error("create function max as '%s' outputtype int bufSize 8"%self.libudf1) + tdSql.error("create function max as '%s' outputtype int"%self.libudf1) tdSql.error("create aggregate function sum as '%s' outputtype double bufSize 8"%self.libudf2) - tdSql.error("create function max as '%s' outputtype int bufSize 8"%self.libudf1) + tdSql.error("create function max as '%s' outputtype int"%self.libudf1) tdSql.error("create aggregate function sum as '%s' outputtype double bufSize 8"%self.libudf2) tdSql.error("create aggregate function tbname as '%s' outputtype double bufSize 8"%self.libudf2) tdSql.error("create aggregate function function as '%s' outputtype double bufSize 8"%self.libudf2) diff --git a/tests/system-test/0-others/udf_create.py b/tests/system-test/0-others/udf_create.py index 65dad64000..d35688c8da 100644 --- a/tests/system-test/0-others/udf_create.py +++ b/tests/system-test/0-others/udf_create.py @@ -148,7 +148,7 @@ class TDTestCase: for i in range(5): # create scalar functions - tdSql.execute("create function udf1 as '%s' outputtype int bufSize 8;"%self.libudf1) + tdSql.execute("create function udf1 as '%s' outputtype int;"%self.libudf1) # create aggregate functions @@ -173,7 +173,7 @@ class TDTestCase: tdLog.info("drop two udf functions success ") # create scalar functions - tdSql.execute("create function udf1 as '%s' outputtype int bufSize 8;"%self.libudf1) + tdSql.execute("create function udf1 as '%s' outputtype int;"%self.libudf1) # create aggregate functions @@ -574,7 +574,7 @@ class TDTestCase: # create function without buffer tdSql.execute("create aggregate function udf1 as '%s' outputtype int bufSize 8 "%self.libudf1) - tdSql.execute("create function udf2 as '%s' outputtype double bufSize 8"%self.libudf2) + tdSql.execute("create function udf2 as '%s' outputtype double "%self.libudf2) udf1_sqls ,udf2_sqls = self.try_query_sql() for scalar_sql in udf1_sqls: @@ -582,7 +582,7 @@ class TDTestCase: for aggregate_sql in udf2_sqls: tdSql.error(aggregate_sql) - tdSql.execute(" create function db as '%s' outputtype int bufSize 8 "%self.libudf1) + tdSql.execute(" create function db as '%s' outputtype int "%self.libudf1) tdSql.execute(" create aggregate function test as '%s' outputtype int bufSize 8 "%self.libudf1) tdSql.error(" select db(c1) from stb1 ") tdSql.error(" select db(c1,c6), db(c6) from stb1 ") @@ -631,9 +631,9 @@ class TDTestCase: tdLog.info(" create function name is not build_in functions ") tdSql.execute(" drop function udf1 ") tdSql.execute(" drop function udf2 ") - tdSql.error("create function max as '%s' outputtype int bufSize 8"%self.libudf1) + tdSql.error("create function max as '%s' outputtype int"%self.libudf1) tdSql.error("create aggregate function sum as '%s' outputtype double bufSize 8"%self.libudf2) - tdSql.error("create function max as '%s' outputtype int bufSize 8"%self.libudf1) + tdSql.error("create function max as '%s' outputtype int"%self.libudf1) tdSql.error("create aggregate function sum as '%s' outputtype double bufSize 8"%self.libudf2) tdSql.error("create aggregate function tbname as '%s' outputtype double bufSize 8"%self.libudf2) tdSql.error("create aggregate function function as '%s' outputtype double bufSize 8"%self.libudf2) diff --git a/tests/system-test/0-others/udf_restart_taosd.py b/tests/system-test/0-others/udf_restart_taosd.py index dae707520f..a0f70ccd49 100644 --- a/tests/system-test/0-others/udf_restart_taosd.py +++ b/tests/system-test/0-others/udf_restart_taosd.py @@ -145,7 +145,7 @@ class TDTestCase: for i in range(5): # create scalar functions - tdSql.execute("create function udf1 as '%s' outputtype int bufSize 8;"%self.libudf1) + tdSql.execute("create function udf1 as '%s' outputtype int;"%self.libudf1) # create aggregate functions @@ -170,7 +170,7 @@ class TDTestCase: tdLog.info("drop two udf functions success ") # create scalar functions - tdSql.execute("create function udf1 as '%s' outputtype int bufSize 8;"%self.libudf1) + tdSql.execute("create function udf1 as '%s' outputtype int;"%self.libudf1) # create aggregate functions @@ -561,7 +561,7 @@ class TDTestCase: # create function without buffer tdSql.execute("create aggregate function udf1 as '%s' outputtype int bufSize 8 "%self.libudf1) - tdSql.execute("create function udf2 as '%s' outputtype double bufSize 8"%self.libudf2) + tdSql.execute("create function udf2 as '%s' outputtype double"%self.libudf2) udf1_sqls ,udf2_sqls = self.try_query_sql() for scalar_sql in udf1_sqls: @@ -569,7 +569,7 @@ class TDTestCase: for aggregate_sql in udf2_sqls: tdSql.error(aggregate_sql) - tdSql.execute(" create function db as '%s' outputtype int bufSize 8 "%self.libudf1) + tdSql.execute(" create function db as '%s' outputtype int "%self.libudf1) tdSql.execute(" create aggregate function test as '%s' outputtype int bufSize 8 "%self.libudf1) tdSql.error(" select db(c1) from stb1 ") tdSql.error(" select db(c1,c6), db(c6) from stb1 ") @@ -618,9 +618,9 @@ class TDTestCase: tdLog.info(" create function name is not build_in functions ") tdSql.execute(" drop function udf1 ") tdSql.execute(" drop function udf2 ") - tdSql.error("create function max as '%s' outputtype int bufSize 8"%self.libudf1) + tdSql.error("create function max as '%s' outputtype int"%self.libudf1) tdSql.error("create aggregate function sum as '%s' outputtype double bufSize 8"%self.libudf2) - tdSql.error("create function max as '%s' outputtype int bufSize 8"%self.libudf1) + tdSql.error("create function max as '%s' outputtype int"%self.libudf1) tdSql.error("create aggregate function sum as '%s' outputtype double bufSize 8"%self.libudf2) tdSql.error("create aggregate function tbname as '%s' outputtype double bufSize 8"%self.libudf2) tdSql.error("create aggregate function function as '%s' outputtype double bufSize 8"%self.libudf2) diff --git a/tests/system-test/7-tmq/tmqUdf-multCtb-snapshot0.py b/tests/system-test/7-tmq/tmqUdf-multCtb-snapshot0.py index 297429b495..5b17d3f583 100644 --- a/tests/system-test/7-tmq/tmqUdf-multCtb-snapshot0.py +++ b/tests/system-test/7-tmq/tmqUdf-multCtb-snapshot0.py @@ -50,7 +50,7 @@ class TDTestCase: def create_udf_function(self): # create scalar functions - tdSql.execute("create function udf1 as '%s' outputtype int bufSize 8;"%self.libudf1) + tdSql.execute("create function udf1 as '%s' outputtype int;"%self.libudf1) functions = tdSql.getResult("show functions") function_nums = len(functions) diff --git a/tests/system-test/7-tmq/tmqUdf-multCtb-snapshot1.py b/tests/system-test/7-tmq/tmqUdf-multCtb-snapshot1.py index 9c139b50de..0a7bf5e349 100644 --- a/tests/system-test/7-tmq/tmqUdf-multCtb-snapshot1.py +++ b/tests/system-test/7-tmq/tmqUdf-multCtb-snapshot1.py @@ -50,7 +50,7 @@ class TDTestCase: def create_udf_function(self): # create scalar functions - tdSql.execute("create function udf1 as '%s' outputtype int bufSize 8;"%self.libudf1) + tdSql.execute("create function udf1 as '%s' outputtype int;"%self.libudf1) functions = tdSql.getResult("show functions") function_nums = len(functions) diff --git a/tests/system-test/7-tmq/tmqUdf.py b/tests/system-test/7-tmq/tmqUdf.py index 8593fd4f1e..5a0a0481d7 100644 --- a/tests/system-test/7-tmq/tmqUdf.py +++ b/tests/system-test/7-tmq/tmqUdf.py @@ -50,7 +50,7 @@ class TDTestCase: def create_udf_function(self): # create scalar functions - tdSql.execute("create function udf1 as '%s' outputtype int bufSize 8;"%self.libudf1) + tdSql.execute("create function udf1 as '%s' outputtype int;"%self.libudf1) functions = tdSql.getResult("show functions") function_nums = len(functions) From ca2e566319aa634c8dc663e2eb1d64adf50cd4b5 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Thu, 23 Mar 2023 17:56:56 +0800 Subject: [PATCH 4/4] enh: improve error reporting information --- source/libs/parser/src/parInsertSql.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/parser/src/parInsertSql.c b/source/libs/parser/src/parInsertSql.c index 5b0b5acf2b..18d65dd477 100644 --- a/source/libs/parser/src/parInsertSql.c +++ b/source/libs/parser/src/parInsertSql.c @@ -1540,7 +1540,7 @@ static int32_t checkTableClauseFirstToken(SInsertParseContext* pCxt, SVnodeModif } } - if (TK_NK_ID != pTbName->type && TK_NK_STRING != pTbName->type) { + if (TK_NK_ID != pTbName->type && TK_NK_STRING != pTbName->type && TK_NK_QUESTION != pTbName->type) { return buildSyntaxErrMsg(&pCxt->msg, "table_name is expected", pTbName->z); }