KassieZ commented on code in PR #2273: URL: https://github.com/apache/doris-website/pull/2273#discussion_r2055897200
########## docs/query-data/udf/java-user-defined-function.md: ########## @@ -357,6 +359,37 @@ public class MedianUDAF { +-----------------+ ``` +### Introduction to Java-UDWF Example + +1. The implementation is similar to Java UDAF, but requires an additional reset() method to clear the state. + + ```JAVA + void reset(State state) + ``` + +2. Register and create the Java-UDWF function same as UDAF in Doris. For more syntax details, please refer to [CREATE FUNCTION](../../sql-manual/sql-statements/function/CREATE-FUNCTION). Review Comment: please check the docs relative path correction ########## i18n/zh-CN/docusaurus-plugin-content-docs/current/query-data/udf/java-user-defined-function.md: ########## @@ -348,6 +349,37 @@ public void destroy(State state) { +-----------------+ ``` +### Java-UDWF 实例介绍 + +1. 首先编写对应的 Java UDWF 代码,打包生成 JAR 包,它与 Java UDAF 的代码编写是一致的,仅需要实现额外 reset 的接口,将所有的 state 状态置为初始值: + + ```JAVA + void reset(State state) + ``` + +2. 在 Doris 中注册创建 Java-UDWF 函数,与注册 Java-UDAF 一样。更多语法帮助可参阅 [CREATE FUNCTION](../../sql-manual/sql-statements/function/CREATE-FUNCTION). + + ```sql + CREATE AGGREGATE FUNCTION simple_demo_window(INT) RETURNS INT PROPERTIES ( + "file"="file:///pathTo/java-udaf.jar", + "symbol"="org.apache.doris.udf.SimpleDemo", + "always_nullable"="true", + "type"="JAVA_UDF" + ); + ``` + +3. 使用 Java-UDWF, 可以查询在特定窗口内的计算结果,更多语法可以参考[窗口函数](../window-function.md): + + ```sql + select id, simple_demo_window(id) over(partition by id order by d1 rows between 1 preceding and 1 following) as res from test_table; + +------+------+ + | id | res | + +------+------+ + | 1 | 1 | + | 6 | 6 | + +------+------+ + ``` + ### Java-UDTF 实例介绍 :::tip UDTF 自 Doris 3.0 版本开始支持 Review Comment: UDWF 是否有版本限制 -- 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. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org