This is an automated email from the ASF dual-hosted git repository.
gabriellee 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 1c2532b9dc [Bug](udf) Make UDF's type always nullable (#14002)
1c2532b9dc is described below
commit 1c2532b9dcb7f270a48aa348ee844222b54b1270
Author: Gabriel <[email protected]>
AuthorDate: Mon Nov 7 20:51:31 2022 +0800
[Bug](udf) Make UDF's type always nullable (#14002)
---
.../org/apache/doris/catalog/ScalarFunction.java | 1 +
.../data/javaudf_p0/test_javaudf_null.out | 26 ++++++++
.../main/java/org/apache/doris/udf/NullTest.java | 26 ++++++++
.../suites/javaudf_p0/test_javaudf_null.groovy | 70 ++++++++++++++++++++++
4 files changed, 123 insertions(+)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/catalog/ScalarFunction.java
b/fe/fe-core/src/main/java/org/apache/doris/catalog/ScalarFunction.java
index a04cc5aaa3..371c7328f2 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/ScalarFunction.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/ScalarFunction.java
@@ -339,6 +339,7 @@ public class ScalarFunction extends Function {
fn.prepareFnSymbol = prepareFnSymbol;
fn.closeFnSymbol = closeFnSymbol;
fn.setLocation(location);
+ fn.nullableMode = NullableMode.ALWAYS_NULLABLE;
return fn;
}
diff --git a/regression-test/data/javaudf_p0/test_javaudf_null.out
b/regression-test/data/javaudf_p0/test_javaudf_null.out
new file mode 100644
index 0000000000..dc59ed24af
--- /dev/null
+++ b/regression-test/data/javaudf_p0/test_javaudf_null.out
@@ -0,0 +1,26 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !select_default --
+1
+2
+3
+4
+5
+6
+7
+8
+9
+
+-- !select --
+\N
+
+-- !select --
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+
diff --git
a/regression-test/java-udf-src/src/main/java/org/apache/doris/udf/NullTest.java
b/regression-test/java-udf-src/src/main/java/org/apache/doris/udf/NullTest.java
new file mode 100644
index 0000000000..4675fca99b
--- /dev/null
+++
b/regression-test/java-udf-src/src/main/java/org/apache/doris/udf/NullTest.java
@@ -0,0 +1,26 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.udf;
+
+import org.apache.hadoop.hive.ql.exec.UDF;
+
+public class NullTest extends UDF {
+ public Integer evaluate(Integer i) {
+ return null;
+ }
+}
diff --git a/regression-test/suites/javaudf_p0/test_javaudf_null.groovy
b/regression-test/suites/javaudf_p0/test_javaudf_null.groovy
new file mode 100644
index 0000000000..e2699f1b4b
--- /dev/null
+++ b/regression-test/suites/javaudf_p0/test_javaudf_null.groovy
@@ -0,0 +1,70 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+import org.codehaus.groovy.runtime.IOGroovyMethods
+
+import java.nio.charset.StandardCharsets
+import java.nio.file.Files
+import java.nio.file.Paths
+
+suite("test_javaudf_null") {
+ def tableName = "test_javaudf_null"
+ def jarPath =
"""${context.file.parent}/jars/java-udf-case-jar-with-dependencies.jar"""
+
+ log.info("Jar path: ${jarPath}".toString())
+ try {
+ sql """ DROP TABLE IF EXISTS ${tableName} """
+ sql """
+ CREATE TABLE IF NOT EXISTS ${tableName} (
+ `user_id` INT NOT NULL COMMENT ""
+ )
+ DISTRIBUTED BY HASH(user_id) PROPERTIES("replication_num" = "1");
+ """
+ StringBuilder sb = new StringBuilder()
+ int i = 1
+ for (; i < 9; i ++) {
+ sb.append("""
+ (${i}),
+ """)
+ }
+ sb.append("""
+ (${i})
+ """)
+ sql """ INSERT INTO ${tableName} VALUES
+ ${sb.toString()}
+ """
+ qt_select_default """ SELECT * FROM ${tableName} t ORDER BY user_id;
"""
+
+ File path = new File(jarPath)
+ if (!path.exists()) {
+ throw new IllegalStateException("""${jarPath} doesn't exist! """)
+ }
+
+ sql """ CREATE FUNCTION java_udf_null_test(int) RETURNS int PROPERTIES
(
+ "file"="file://${jarPath}",
+ "symbol"="org.apache.doris.udf.NullTest",
+ "type"="JAVA_UDF"
+ ); """
+
+ qt_select """ SELECT java_udf_null_test(1) result; """
+ qt_select """ SELECT java_udf_null_test(user_id) result FROM
${tableName} ORDER BY result; """
+
+ sql """ DROP FUNCTION java_udf_null_test(int); """
+ } finally {
+ try_sql("DROP TABLE IF EXISTS ${tableName}")
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]