doris自带的java udf demo 用mvn打包后不可用问题

Viewed 40

代码路径:
https://github.com/apache/doris/tree/2.1.6-rc04/samples/doris-demo/java-udf-demo
通过mvn clean package命令打包并上传。
执行以下脚本
CREATE AGGREGATE FUNCTION add_one(int) RETURNS int PROPERTIES (
"file"="file:///opt/apache-doris/custom_lib/java-udf-demo.jar",
"symbol"="org.apache.doris.udf.AddOne",
"always_nullable"="true",
"type"="JAVA_UDF"
);
在Doris2.0.13和2.1.6版本上都以下错误提示:
/* SQL错误(1105):errCode = 2, detailMessage = Class [org.apache.doris.udf.AddOne] or inner class [State] not found in file :file:///opt/apache-doris/custom_lib/java-udf-demo.jar */
请指教,谢谢。

3 Answers

创建function的语法有问题,不需要加 AGGREGATE,示例:

CREATE FUNCTION add_one(int) RETURNS int PROPERTIES (
    "file"="file:///mnt/disk1/huanghaijun/java-udf-demo-jar-with-dependencies.jar",
    "symbol"="org.apache.doris.udf.AddOne",
    "always_nullable"="true",
    "type"="JAVA_UDF"
);
  1. jar tf java-udf-demo.jar 看下有没有 org.apache.doris.udf.AddOne 类
  2. 确保在编写 Java UDF 时,类的包声明与实际文件的路径结构匹配。即类 AddOne 应该在 org.apache.doris.udf 包下

1、jar tf java-udf-demo.jar执行后返回以下列表,包含AddOne.class
META-INF/
META-INF/MANIFEST.MF
org/
org/apache/
org/apache/doris/
org/apache/doris/udf/
META-INF/maven/
META-INF/maven/org.apache.doris/
META-INF/maven/org.apache.doris/java-udf-demo/
org/apache/doris/udf/AddOne.class
org/apache/doris/udf/DateCaseTest.class
META-INF/maven/org.apache.doris/java-udf-demo/pom.xml
META-INF/maven/org.apache.doris/java-udf-demo/pom.properties
2、AddOne.class代码内容如下,
package org.apache.doris.udf;

import org.apache.hadoop.hive.ql.exec.UDF;

public class AddOne extends UDF {
public Integer evaluate(Integer value) {
return value == null ? null : value + 1;
}
}