morningman commented on a change in pull request #1140: Add SHOW FUNCTION and update docs for UDF URL: https://github.com/apache/incubator-doris/pull/1140#discussion_r283089133
########## File path: docs/documentation/cn/extending-doris/user-defined-function.md ########## @@ -0,0 +1,83 @@ +# USER DEFINED FUNCTION + +用户可以通过UDF机制来扩展Doris的能力。通过这篇文档,用户能够创建自己的UDF。 + +## 编写UDF函数 + +在使用UDF之前,用户需要先在Doris的UDF框架下,编写自己的UDF函数。在`be/src/udf_samples/udf_sample.h|cpp`文件中是一个简单的UDF Demo。 + +编写一个UDF函数需要以下几个步骤 + +### 编写函数 + +创建对应的头文件、CPP文件,在CPP文件中实现你需要的逻辑。CPP文件中的实现函数格式与UDF的对应关系。 + +#### 非可变参数 + +对于非可变参数的UDF,那么两者之间的对应关系很直接。 +比如`INT MyADD(INT, INT)`的UDF就会对应`IntVal AddUdf(FunctionContext* context, const IntVal& arg1, const IntVal& arg2)` + +1. `AddUdf`可以为任意的名字,只要创建UDF的时候指定即可 +2. 实现函数中的第一个参数永远是`FunctionContext*`。实现者可以通过这个结构体获得一些查询相关的内容,以及申请一些需要使用的内存。具体使用的接口可以参考`udf/udf.h`中的定义。 +3. 实现函数中从第二个参数开始需要与UDF的参数一一对应,比如`IntVal`对应`INT`类型。这部分的类型都要使用`const`引用 +4. 返回参数与UDF的参数的类型要相对应 + +#### 可变参数 + +对于可变参数,可以参见一下例子,UDF`String md5sum(String, ...)`对应的 Review comment: 一下 -> 以下 ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
