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

lihaopeng 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 a5b9d61f432 [bug](udf) fix java-udf function const column without 
arguments (#26409)
a5b9d61f432 is described below

commit a5b9d61f432ab8c5ed20579cecdf9550c1aaf927
Author: zhangstar333 <[email protected]>
AuthorDate: Mon Nov 6 10:34:09 2023 +0800

    [bug](udf) fix java-udf function const column without arguments (#26409)
---
 be/src/vec/exprs/vectorized_fn_call.h              |  5 ++-
 .../data/javaudf_p0/test_javaudf_int.out           | 39 ++++++++++++++++++++++
 .../data/javaudf_p0/test_javaudf_no_input.out      | 33 ++++++++++++++++++
 .../suites/javaudf_p0/test_javaudf_int.groovy      | 13 +++++++-
 .../suites/javaudf_p0/test_javaudf_no_input.groovy | 11 ++++++
 5 files changed, 99 insertions(+), 2 deletions(-)

diff --git a/be/src/vec/exprs/vectorized_fn_call.h 
b/be/src/vec/exprs/vectorized_fn_call.h
index b08f83128be..8c9ed6d9395 100644
--- a/be/src/vec/exprs/vectorized_fn_call.h
+++ b/be/src/vec/exprs/vectorized_fn_call.h
@@ -16,6 +16,7 @@
 // under the License.
 
 #pragma once
+#include <gen_cpp/Types_types.h>
 #include <stddef.h>
 
 #include <string>
@@ -53,7 +54,9 @@ public:
     const std::string& expr_name() const override;
     std::string debug_string() const override;
     bool is_constant() const override {
-        if (!_function->is_use_default_implementation_for_constants()) {
+        if (!_function->is_use_default_implementation_for_constants() ||
+            // udf function with no argument, can't sure it's must return 
const column
+            (_fn.binary_type == TFunctionBinaryType::JAVA_UDF && 
_children.empty())) {
             return false;
         }
         return VExpr::is_constant();
diff --git a/regression-test/data/javaudf_p0/test_javaudf_int.out 
b/regression-test/data/javaudf_p0/test_javaudf_int.out
index 561ba219dad..2ff06d4254f 100644
--- a/regression-test/data/javaudf_p0/test_javaudf_int.out
+++ b/regression-test/data/javaudf_p0/test_javaudf_int.out
@@ -86,3 +86,42 @@
 -- !select --
 \N
 
+-- !select_global_1 --
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+
+-- !select_global_2 --
+\N
+
+-- !select_global_3 --
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+
+-- !select_global_4 --
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+
diff --git a/regression-test/data/javaudf_p0/test_javaudf_no_input.out 
b/regression-test/data/javaudf_p0/test_javaudf_no_input.out
index f6fcfc54dae..e575c30743a 100644
--- a/regression-test/data/javaudf_p0/test_javaudf_no_input.out
+++ b/regression-test/data/javaudf_p0/test_javaudf_no_input.out
@@ -21,3 +21,36 @@ no input
 no input
 no input
 
+-- !select2 --
+8
+8
+8
+8
+8
+8
+8
+8
+8
+
+-- !select3 --
+no input
+no input
+no input
+no input
+no input
+no input
+no input
+no input
+no input
+
+-- !select4 --
+8
+8
+8
+8
+8
+8
+8
+8
+8
+
diff --git a/regression-test/suites/javaudf_p0/test_javaudf_int.groovy 
b/regression-test/suites/javaudf_p0/test_javaudf_int.groovy
index a7d2615e86b..a18fbb4d40b 100644
--- a/regression-test/suites/javaudf_p0/test_javaudf_int.groovy
+++ b/regression-test/suites/javaudf_p0/test_javaudf_int.groovy
@@ -111,8 +111,19 @@ suite("test_javaudf_int") {
         qt_select """ SELECT java_udf_largeint_test(largeint_col) result FROM 
${tableName} ORDER BY result; """
         qt_select """ SELECT java_udf_largeint_test(null) result ; """
 
-        
+        sql """ CREATE GLOBAL FUNCTION java_udf_int_test_global(int) RETURNS 
int PROPERTIES (
+            "file"="file://${jarPath}",
+            "symbol"="org.apache.doris.udf.IntTest",
+            "type"="JAVA_UDF"
+        ); """
+
+        qt_select_global_1 """ SELECT java_udf_int_test_global(user_id) result 
FROM ${tableName} ORDER BY result; """
+        qt_select_global_2 """ SELECT java_udf_int_test_global(null) result ; 
"""
+        qt_select_global_3 """ SELECT java_udf_int_test_global(3) result FROM 
${tableName} ORDER BY result; """
+        qt_select_global_4 """ SELECT abs(java_udf_int_test_global(3)) result 
FROM ${tableName} ORDER BY result; """
+
     } finally {
+        try_sql("DROP GLOBAL FUNCTION IF EXISTS 
java_udf_int_test_global(tinyint);")
         try_sql("DROP FUNCTION IF EXISTS java_udf_tinyint_test(tinyint);")
         try_sql("DROP FUNCTION IF EXISTS java_udf_smallint_test(smallint);")
         try_sql("DROP FUNCTION IF EXISTS java_udf_bigint_test(bigint);")
diff --git a/regression-test/suites/javaudf_p0/test_javaudf_no_input.groovy 
b/regression-test/suites/javaudf_p0/test_javaudf_no_input.groovy
index fd3e74e2137..8fade7c7170 100644
--- a/regression-test/suites/javaudf_p0/test_javaudf_no_input.groovy
+++ b/regression-test/suites/javaudf_p0/test_javaudf_no_input.groovy
@@ -66,8 +66,19 @@ suite("test_javaudf_no_input") {
         ); """
 
         qt_select1 """ SELECT no_input_udf() FROM ${tableName}; """
+        qt_select2 """ SELECT length(no_input_udf()) FROM ${tableName}; """
 
+        sql """ CREATE GLOBAL FUNCTION global_no_input_udf() RETURNS String 
PROPERTIES (
+            "file"="file://${jarPath}",
+            "symbol"="org.apache.doris.udf.NoInputTest",
+            "always_nullable"="true",
+            "type"="JAVA_UDF"
+        ); """
+
+        qt_select3 """ SELECT global_no_input_udf() FROM ${tableName}; """
+        qt_select4 """ SELECT length(global_no_input_udf()) FROM ${tableName}; 
"""
     } finally {
+        try_sql("DROP GLOBAL FUNCTION IF EXISTS global_no_input_udf();")
         try_sql("DROP FUNCTION IF EXISTS no_input_udf();")
         try_sql("DROP TABLE IF EXISTS ${tableName}")
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to