Skip to content

Commit

Permalink
[bug](udf) fix java-udf function const column without arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangstar333 committed Nov 3, 2023
1 parent 7730a90 commit 6dddc7b
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 2 deletions.
5 changes: 4 additions & 1 deletion be/src/vec/exprs/vectorized_fn_call.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// under the License.

#pragma once
#include <gen_cpp/Types_types.h>
#include <stddef.h>

#include <string>
Expand Down Expand Up @@ -53,7 +54,9 @@ class VectorizedFnCall : public VExpr {
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();
Expand Down
39 changes: 39 additions & 0 deletions regression-test/data/javaudf_p0/test_javaudf_int.out
Original file line number Diff line number Diff line change
Expand Up @@ -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

33 changes: 33 additions & 0 deletions regression-test/data/javaudf_p0/test_javaudf_no_input.out
Original file line number Diff line number Diff line change
Expand Up @@ -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

13 changes: 12 additions & 1 deletion regression-test/suites/javaudf_p0/test_javaudf_int.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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);")
Expand Down
11 changes: 11 additions & 0 deletions regression-test/suites/javaudf_p0/test_javaudf_no_input.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
}
Expand Down

0 comments on commit 6dddc7b

Please sign in to comment.