You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by zy...@apache.org on 2023/06/12 03:48:23 UTC

[doris] branch master updated: [doc](create-function) Update CREATE-FUNCTION.md to remove the usage of c++ (#20654)

This is an automated email from the ASF dual-hosted git repository.

zykkk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new a02a2f4163 [doc](create-function) Update CREATE-FUNCTION.md to remove the usage of c++ (#20654)
a02a2f4163 is described below

commit a02a2f4163c69c9e4272ed8c6742e6415ebac77e
Author: Hong Liu <84...@qq.com>
AuthorDate: Mon Jun 12 11:48:14 2023 +0800

    [doc](create-function) Update CREATE-FUNCTION.md to remove the usage of c++ (#20654)
---
 .../Create/CREATE-FUNCTION.md                      | 100 +++++++--------------
 .../Create/CREATE-FUNCTION.md                      |  77 ++++------------
 2 files changed, 50 insertions(+), 127 deletions(-)

diff --git a/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-FUNCTION.md b/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-FUNCTION.md
index e61b87d35c..e619870d65 100644
--- a/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-FUNCTION.md
+++ b/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-FUNCTION.md
@@ -64,7 +64,7 @@ Parameter Description:
 
 - `arg_type`: The parameter type of the function, which is the same as the type defined when creating the table. Variable-length parameters can be represented by `, ...`. If it is a variable-length type, the type of the variable-length parameter is the same as that of the last non-variable-length parameter.
 
-   **NOTE**: `ALIAS FUNCTION` does not support variable-length arguments and must have at least one argument.
+  **NOTE**: `ALIAS FUNCTION` does not support variable-length arguments and must have at least one argument.
 
 - `ret_type`: Required for creating new functions. If you are aliasing an existing function, you do not need to fill in this parameter.
 
@@ -77,92 +77,54 @@ Parameter Description:
 
 - `origin_function`: used to represent the original function corresponding to the alias function.
 
-- `properties`: Used to set properties related to aggregate functions and scalar functions. The properties that can be set include:
 
-  - `object_file`: The URL path of the custom function dynamic library. Currently, only HTTP/HTTPS protocol is supported. This path needs to remain valid for the entire life cycle of the function. This option is required
+- `properties`: Used to set function-related properties, the properties that can be set include:
 
-  - `symbol`: The function signature of the scalar function, which is used to find the function entry from the dynamic library. This option is required for scalar functions
+    - `file`: Indicates the jar package containing the user UDF. In a multi-machine environment, you can also use http to download the jar package. This parameter is mandatory.
 
-  - `init_fn`: The initialization function signature of the aggregate function. Required for aggregate functions
+    - `symbol`: Indicates the name of the class containing the UDF class. This parameter must be set
 
-  - `update_fn`: update function signature of aggregate function. Required for aggregate functions
+    - `type`: Indicates the UDF call type, the default is Native, and JAVA_UDF is passed when using Java UDF.
 
-  - `merge_fn`: Merge function signature of aggregate function. Required for aggregate functions
+    - `always_nullable`: Indicates whether NULL values may appear in the UDF return result, is an optional parameter, and the default value is true.
 
-  - `serialize_fn`: Serialize function signature of aggregate function. Optional for aggregate functions, if not specified, the default serialization function will be used
-
-  - `finalize_fn`: The function signature of the aggregate function to get the final result. Optional for aggregate functions, if not specified, the default get-result function will be used
-
-  - `md5`: The MD5 value of the function dynamic link library, which is used to verify whether the downloaded content is correct. This option is optional
-
-  - `prepare_fn`: The function signature of the prepare function of the custom function, which is used to find the prepare function entry from the dynamic library. This option is optional for custom functions
-
-  - `close_fn`: The function signature of the close function of the custom function, which is used to find the close function entry from the dynamic library. This option is optional for custom functions
 
 ### Example
 
-1. Create a custom scalar function
-
-   ```sql
-   CREATE FUNCTION my_add(INT, INT) RETURNS INT PROPERTIES (
-   "symbol" = "_ZN9doris_udf6AddUdfEPNS_15FunctionContextERKNS_6IntValES4_",
-   "object_file" = "http://host:port/libmyadd.so"
-   );
-   ````
-
-2. Create a custom scalar function with prepare/close functions
-
-   ```sql
-   CREATE FUNCTION my_add(INT, INT) RETURNS INT PROPERTIES (
-   "symbol" = "_ZN9doris_udf6AddUdfEPNS_15FunctionContextERKNS_6IntValES4_",
-   "prepare_fn" = "_ZN9doris_udf14AddUdf_prepareEPNS_15FunctionContextENS0_18FunctionStateScopeE",
-   "close_fn" = "_ZN9doris_udf12AddUdf_closeEPNS_15FunctionContextENS0_18FunctionStateScopeE",
-   "object_file" = "http://host:port/libmyadd.so"
-   );
-   ````
-
-3. Create a custom aggregate function
+1. Create a custom UDF function
 
     ```sql
-   CREATE AGGREGATE FUNCTION my_count (BIGINT) RETURNS BIGINT PROPERTIES (
-            "init_fn"="_ZN9doris_udf9CountInitEPNS_15FunctionContextEPNS_9BigIntValE",
-            "update_fn"="_ZN9doris_udf11CountUpdateEPNS_15FunctionContextERKNS_6IntValEPNS_9BigIntValE",
-            "merge_fn"="_ZN9doris_udf10CountMergeEPNS_15FunctionContextERKNS_9BigIntValEPS2_",
-            "finalize_fn"="_ZN9doris_udf13CountFinalizeEPNS_15FunctionContextERKNS_9BigIntValE",
-            "object_file"="http://host:port/libudasample.so"
-   );
-   ````
-
-
-4. Create a scalar function with variable length arguments
+    CREATE FUNCTION java_udf_add_one(int) RETURNS int PROPERTIES (
+        "file"="file:///path/to/java-udf-demo-jar-with-dependencies.jar",
+        "symbol"="org.apache.doris.udf.AddOne",
+        "always_nullable"="true",
+        "type"="JAVA_UDF"
+    );
+    ```
 
-   ```sql
-   CREATE FUNCTION strconcat(varchar, ...) RETURNS varchar properties (
-   "symbol" = "_ZN9doris_udf6StrConcatUdfEPNS_15FunctionContextERKNS_6IntValES4_",
-   "object_file" = "http://host:port/libmyStrConcat.so"
-   );
-   ````
 
-5. Create a custom alias function
+2. Create a custom UDAF function
 
-   ```sql
-   CREATE ALIAS FUNCTION id_masking(INT) WITH PARAMETER(id) AS CONCAT(LEFT(id, 3), '****', RIGHT(id, 4));
-   ````
+    ```sql
+    CREATE AGGREGATE FUNCTION simple_sum(INT) RETURNS INT PROPERTIES (
+        "file"="file:///pathTo/java-udaf.jar",
+        "symbol"="org.apache.doris.udf.demo.SimpleDemo",
+        "always_nullable"="true",
+        "type"="JAVA_UDF"
+    );
+    ```
 
-6. Create a global custom scalar function
+3. Create a custom alias function
 
-   ```sql
-   CREATE GLOBAL FUNCTION my_add(INT, INT) RETURNS INT PROPERTIES (
-   "symbol" = "_ZN9doris_udf6AddUdfEPNS_15FunctionContextERKNS_6IntValES4_",
-   "object_file" = "http://host:port/libmyadd.so"
-   );
-   ````
+    ```sql
+    CREATE ALIAS FUNCTION id_masking(INT) WITH PARAMETER(id) AS CONCAT(LEFT(id, 3), '****', RIGHT(id, 4));
+    ```
 
-7. Create a global custom alias function
+4. Create a global custom alias function
 
-   ```sql
-   CREATE GLOBAL ALIAS FUNCTION id_masking(INT) WITH PARAMETER(id) AS CONCAT(LEFT(id, 3), '****', RIGHT(id, 4));
-   ```` 
+    ```sql
+    CREATE GLOBAL ALIAS FUNCTION id_masking(INT) WITH PARAMETER(id) AS CONCAT(LEFT(id, 3), '****', RIGHT(id, 4));
+    ```
 
 ### Keywords
 
diff --git a/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-FUNCTION.md b/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-FUNCTION.md
index 76baac98fd..60498dfeb8 100644
--- a/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-FUNCTION.md
+++ b/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-FUNCTION.md
@@ -77,88 +77,49 @@ CREATE [GLOBAL] [AGGREGATE] [ALIAS] FUNCTION function_name
 
 -  `origin_function`:用于表示别名函数对应的原始函数。
 
-- `properties`: 用于设定聚合函数和标量函数相关属性,能够设置的属性包括:	
+- `properties`: 用于设定函数相关属性,能够设置的属性包括:	
 
-  - `object_file`: 自定义函数动态库的URL路径,当前只支持 HTTP/HTTPS 协议,此路径需要在函数整个生命周期内保持有效。此选项为必选项
+  - `file`: 表示的包含用户UDF的jar包,当在多机环境时,也可以使用http的方式下载jar包。这个参数是必须设定的。
 
-  - `symbol`: 标量函数的函数签名,用于从动态库里面找到函数入口。此选项对于标量函数是必选项
+  - `symbol`: 表示的是包含UDF类的类名。这个参数是必须设定的
 
-  - `init_fn`: 聚合函数的初始化函数签名。对于聚合函数是必选项
+  - `type`: 表示的 UDF 调用类型,默认为 Native,使用 Java UDF时传 JAVA_UDF。
 
-  - `update_fn`: 聚合函数的更新函数签名。对于聚合函数是必选项
+  - `always_nullable`:表示的 UDF 返回结果中是否有可能出现NULL值,是可选参数,默认值为true。
 
-  - `merge_fn`: 聚合函数的合并函数签名。对于聚合函数是必选项
-
-  - `serialize_fn`: 聚合函数的序列化函数签名。对于聚合函数是可选项,如果没有指定,那么将会使用默认的序列化函数
-
-  - `finalize_fn`: 聚合函数获取最后结果的函数签名。对于聚合函数是可选项,如果没有指定,将会使用默认的获取结果函数
-
-  - `md5`: 函数动态链接库的MD5值,用于校验下载的内容是否正确。此选项是可选项
-
-  - `prepare_fn`: 自定义函数的prepare函数的函数签名,用于从动态库里面找到prepare函数入口。此选项对于自定义函数是可选项
-
-  - `close_fn`: 自定义函数的close函数的函数签名,用于从动态库里面找到close函数入口。此选项对于自定义函数是可选项     
 
 ### Example
 
-1. 创建一个自定义标量函数
-
-   ```sql
-   CREATE FUNCTION my_add(INT, INT) RETURNS INT PROPERTIES (
-   	"symbol" = "_ZN9doris_udf6AddUdfEPNS_15FunctionContextERKNS_6IntValES4_",
-   	"object_file" = "http://host:port/libmyadd.so"
-   );
-   ```
-
-2. 创建一个有prepare/close函数的自定义标量函数
+1. 创建一个自定义UDF函数
 
    ```sql
-   CREATE FUNCTION my_add(INT, INT) RETURNS INT PROPERTIES (
-   	"symbol" = "_ZN9doris_udf6AddUdfEPNS_15FunctionContextERKNS_6IntValES4_",
-   	"prepare_fn" = 	"_ZN9doris_udf14AddUdf_prepareEPNS_15FunctionContextENS0_18FunctionStateScopeE",
-   	"close_fn" = "_ZN9doris_udf12AddUdf_closeEPNS_15FunctionContextENS0_18FunctionStateScopeE",
-   	"object_file" = "http://host:port/libmyadd.so"
-   );
-   ```
-
-3. 创建一个自定义聚合函数
-
-    ```sql
-   CREATE AGGREGATE FUNCTION my_count (BIGINT) RETURNS BIGINT PROPERTIES (
-            "init_fn"="_ZN9doris_udf9CountInitEPNS_15FunctionContextEPNS_9BigIntValE",
-            "update_fn"="_ZN9doris_udf11CountUpdateEPNS_15FunctionContextERKNS_6IntValEPNS_9BigIntValE",
-            "merge_fn"="_ZN9doris_udf10CountMergeEPNS_15FunctionContextERKNS_9BigIntValEPS2_",
-            "finalize_fn"="_ZN9doris_udf13CountFinalizeEPNS_15FunctionContextERKNS_9BigIntValE",
-            "object_file"="http://host:port/libudasample.so"
+   CREATE FUNCTION java_udf_add_one(int) RETURNS int PROPERTIES (
+       "file"="file:///path/to/java-udf-demo-jar-with-dependencies.jar",
+       "symbol"="org.apache.doris.udf.AddOne",
+       "always_nullable"="true",
+       "type"="JAVA_UDF"
    );
    ```
 
 
-4. 创建一个变长参数的标量函数
+2. 创建一个自定义UDAF函数
 
    ```sql
-   CREATE FUNCTION strconcat(varchar, ...) RETURNS varchar properties (
-   	"symbol" = "_ZN9doris_udf6StrConcatUdfEPNS_15FunctionContextERKNS_6IntValES4_",
-   	"object_file" = "http://host:port/libmyStrConcat.so"
+   CREATE AGGREGATE FUNCTION simple_sum(INT) RETURNS INT PROPERTIES (
+       "file"="file:///pathTo/java-udaf.jar",
+       "symbol"="org.apache.doris.udf.demo.SimpleDemo",
+       "always_nullable"="true",
+       "type"="JAVA_UDF"
    );
    ```
 
-5. 创建一个自定义别名函数
+3. 创建一个自定义别名函数
 
    ```sql
    CREATE ALIAS FUNCTION id_masking(INT) WITH PARAMETER(id)  AS CONCAT(LEFT(id, 3), '****', RIGHT(id, 4));
    ```
 
-6. 创建一个全局自定义标量函数
-
-   ```sql
-   CREATE GLOBAL FUNCTION my_add(INT, INT) RETURNS INT PROPERTIES (
-   "symbol" = "_ZN9doris_udf6AddUdfEPNS_15FunctionContextERKNS_6IntValES4_",
-   "object_file" = "http://host:port/libmyadd.so"
-   );
-   ````
-
-7. 创建一个全局自定义别名函数
+4. 创建一个全局自定义别名函数
 
    ```sql
    CREATE GLOBAL ALIAS FUNCTION id_masking(INT) WITH PARAMETER(id) AS CONCAT(LEFT(id, 3), '****', RIGHT(id, 4));


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org