forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix](udf)java udf does not support overloaded evaluate method (apach…
…e#22681) Co-authored-by: morningman <morningman@163.com>
- Loading branch information
1 parent
bd33a16
commit ba9b420
Showing
4 changed files
with
192 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
regression-test/data/javaudf_p0/test_javaudf_multi_evaluate.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
-- This file is automatically generated. You should know what you did if you want to edit this | ||
-- !select_default -- | ||
1 1.11 2 3 | ||
2 \N 3 4 | ||
3 3.33 2 \N | ||
|
||
-- !select -- | ||
2.11 | ||
|
||
-- !select -- | ||
\N | ||
|
||
-- !select -- | ||
5 | ||
|
||
-- !select -- | ||
\N | ||
|
||
-- !select -- | ||
7 | ||
|
||
-- !select -- | ||
\N |
35 changes: 35 additions & 0 deletions
35
regression-test/java-udf-src/src/main/java/org/apache/doris/udf/MultiEvaluateTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// 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 MultiEvaluateTest extends UDF { | ||
|
||
public Float evaluate(Float flo) { | ||
return flo == null ? null : flo + 1; | ||
} | ||
|
||
public Integer evaluate(Integer value) { | ||
return value == null ? null : value + 1; | ||
} | ||
|
||
public Integer evaluate(Integer value1, Integer value2) { | ||
return value1 == null || value2 == null ? null : value1 + value2; | ||
} | ||
|
||
} |
87 changes: 87 additions & 0 deletions
87
regression-test/suites/javaudf_p0/test_javaudf_multi_evaluate.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// 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_multi_evaluate") { | ||
def tableName = "test_javaudf_multi_evaluate" | ||
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 "", | ||
`float_1` FLOAT COMMENT "", | ||
`int_1` INT COMMENT "", | ||
`int_2` INT COMMENT "" | ||
) | ||
DISTRIBUTED BY HASH(user_id) PROPERTIES("replication_num" = "1"); | ||
""" | ||
|
||
|
||
sql """ INSERT INTO ${tableName} (`user_id`,`float_1`,`int_1`,`int_2`) VALUES | ||
(1,1.11,2,3), | ||
(2,null,3,4), | ||
(3,3.33,2,null); | ||
""" | ||
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_multi_evaluate_test(FLOAT) RETURNS FLOAT PROPERTIES ( | ||
"file"="file://${jarPath}", | ||
"symbol"="org.apache.doris.udf.MultiEvaluateTest", | ||
"type"="JAVA_UDF" | ||
); """ | ||
|
||
qt_select """ SELECT java_udf_multi_evaluate_test(float_1) FROM ${tableName} where user_id = 1; """ | ||
qt_select """ SELECT java_udf_multi_evaluate_test(float_1) FROM ${tableName} where user_id = 2; """ | ||
|
||
sql """ CREATE FUNCTION java_udf_multi_evaluate_test(int) RETURNS int PROPERTIES ( | ||
"file"="file://${jarPath}", | ||
"symbol"="org.apache.doris.udf.MultiEvaluateTest", | ||
"type"="JAVA_UDF" | ||
); """ | ||
|
||
qt_select """ SELECT java_udf_multi_evaluate_test(int_2) FROM ${tableName} where user_id = 2; """ | ||
qt_select """ SELECT java_udf_multi_evaluate_test(int_2) FROM ${tableName} where user_id = 3; """ | ||
|
||
sql """ CREATE FUNCTION java_udf_multi_evaluate_test(int,int) RETURNS int PROPERTIES ( | ||
"file"="file://${jarPath}", | ||
"symbol"="org.apache.doris.udf.MultiEvaluateTest", | ||
"type"="JAVA_UDF" | ||
); """ | ||
|
||
qt_select """ SELECT java_udf_multi_evaluate_test(int_1, int_2) FROM ${tableName} where user_id = 2; """ | ||
qt_select """ SELECT java_udf_multi_evaluate_test(int_1, int_2) FROM ${tableName} where user_id = 3; """ | ||
|
||
} finally { | ||
try_sql("DROP FUNCTION IF EXISTS java_udf_multi_evaluate_test(FLOAT);") | ||
try_sql("DROP FUNCTION IF EXISTS java_udf_multi_evaluate_test(int);") | ||
try_sql("DROP FUNCTION IF EXISTS java_udf_multi_evaluate_test(int,int);") | ||
try_sql("DROP TABLE IF EXISTS ${tableName}") | ||
} | ||
} |