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

dataroaring pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-3.0 by this push:
     new 99f4124f251 branch-3.0: [improve](udf) support list/map basic class 
for array/map type #50684 (#50752)
99f4124f251 is described below

commit 99f4124f25174dc1de8f42b576a3307e0fbb121e
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Mon May 12 09:46:54 2025 +0800

    branch-3.0: [improve](udf) support list/map basic class for array/map type 
#50684 (#50752)
    
    Cherry-picked from #50684
    
    Co-authored-by: zhangstar333 <[email protected]>
---
 .../doris/common/jni/utils/JavaUdfDataType.java    |   4 +--
 .../main/java/org/apache/doris/catalog/Type.java   |   8 +++---
 .../data/javaudf_p0/test_javaudf_array.out         | Bin 1725 -> 1891 bytes
 .../data/javaudf_p0/test_javaudf_map.out           | Bin 279 -> 402 bytes
 .../java/org/apache/doris/udf/ArrayListTest.java   |  28 +++++++++++++++++++++
 .../main/java/org/apache/doris/udf/MapsiTest.java  |  28 +++++++++++++++++++++
 .../suites/javaudf_p0/test_javaudf_array.groovy    |   9 +++++++
 .../suites/javaudf_p0/test_javaudf_map.groovy      |  25 ++++++++++++++++++
 8 files changed, 97 insertions(+), 5 deletions(-)

diff --git 
a/fe/be-java-extensions/java-common/src/main/java/org/apache/doris/common/jni/utils/JavaUdfDataType.java
 
b/fe/be-java-extensions/java-common/src/main/java/org/apache/doris/common/jni/utils/JavaUdfDataType.java
index 18bb90ddb99..546b917a2b3 100644
--- 
a/fe/be-java-extensions/java-common/src/main/java/org/apache/doris/common/jni/utils/JavaUdfDataType.java
+++ 
b/fe/be-java-extensions/java-common/src/main/java/org/apache/doris/common/jni/utils/JavaUdfDataType.java
@@ -154,9 +154,9 @@ public class JavaUdfDataType {
         } else if (c == BigDecimal.class) {
             return Sets.newHashSet(JavaUdfDataType.DECIMALV2, 
JavaUdfDataType.DECIMAL32, JavaUdfDataType.DECIMAL64,
                     JavaUdfDataType.DECIMAL128);
-        } else if (c == java.util.ArrayList.class) {
+        } else if (Type.ARRAY_SUPPORTED_JAVA_TYPE.contains(c)) {
             return Sets.newHashSet(JavaUdfDataType.ARRAY_TYPE, 
JavaUdfDataType.STRUCT_TYPE);
-        } else if (c == java.util.HashMap.class) {
+        } else if (Type.MAP_SUPPORTED_JAVA_TYPE.contains(c)) {
             return Sets.newHashSet(JavaUdfDataType.MAP_TYPE);
         }
         return Sets.newHashSet(JavaUdfDataType.INVALID_TYPE);
diff --git a/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java 
b/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java
index 4bb29611d6f..f440ab25f18 100644
--- a/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java
+++ b/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java
@@ -308,6 +308,8 @@ public abstract class Type {
         structSubTypes.add(STRUCT);
     }
 
+    public static final Set<Class> ARRAY_SUPPORTED_JAVA_TYPE = 
Sets.newHashSet(ArrayList.class, List.class);
+    public static final Set<Class> MAP_SUPPORTED_JAVA_TYPE = 
Sets.newHashSet(HashMap.class, Map.class);
     public static final Set<Class> DATE_SUPPORTED_JAVA_TYPE = 
Sets.newHashSet(LocalDate.class, java.util.Date.class,
             org.joda.time.LocalDate.class);
     public static final Set<Class> DATETIME_SUPPORTED_JAVA_TYPE = 
Sets.newHashSet(LocalDateTime.class,
@@ -334,9 +336,9 @@ public abstract class Type {
                     .put(PrimitiveType.DECIMAL32, 
Sets.newHashSet(BigDecimal.class))
                     .put(PrimitiveType.DECIMAL64, 
Sets.newHashSet(BigDecimal.class))
                     .put(PrimitiveType.DECIMAL128, 
Sets.newHashSet(BigDecimal.class))
-                    .put(PrimitiveType.ARRAY, Sets.newHashSet(ArrayList.class))
-                    .put(PrimitiveType.MAP, Sets.newHashSet(HashMap.class))
-                    .put(PrimitiveType.STRUCT, 
Sets.newHashSet(ArrayList.class))
+                    .put(PrimitiveType.ARRAY, ARRAY_SUPPORTED_JAVA_TYPE)
+                    .put(PrimitiveType.MAP, MAP_SUPPORTED_JAVA_TYPE)
+                    .put(PrimitiveType.STRUCT, ARRAY_SUPPORTED_JAVA_TYPE)
                     .build();
 
     public static ArrayList<ScalarType> getIntegerTypes() {
diff --git a/regression-test/data/javaudf_p0/test_javaudf_array.out 
b/regression-test/data/javaudf_p0/test_javaudf_array.out
index 53b926132e4..1c2e8b94d51 100644
Binary files a/regression-test/data/javaudf_p0/test_javaudf_array.out and 
b/regression-test/data/javaudf_p0/test_javaudf_array.out differ
diff --git a/regression-test/data/javaudf_p0/test_javaudf_map.out 
b/regression-test/data/javaudf_p0/test_javaudf_map.out
index 7c7cf58b2f0..7677c30db4e 100644
Binary files a/regression-test/data/javaudf_p0/test_javaudf_map.out and 
b/regression-test/data/javaudf_p0/test_javaudf_map.out differ
diff --git 
a/regression-test/java-udf-src/src/main/java/org/apache/doris/udf/ArrayListTest.java
 
b/regression-test/java-udf-src/src/main/java/org/apache/doris/udf/ArrayListTest.java
new file mode 100644
index 00000000000..ace3ea5d504
--- /dev/null
+++ 
b/regression-test/java-udf-src/src/main/java/org/apache/doris/udf/ArrayListTest.java
@@ -0,0 +1,28 @@
+// 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;
+
+import java.util.List;
+
+public class ArrayListTest extends UDF {
+    public List<String> evaluate(List<String> res) {
+        return res;
+    }
+}
diff --git 
a/regression-test/java-udf-src/src/main/java/org/apache/doris/udf/MapsiTest.java
 
b/regression-test/java-udf-src/src/main/java/org/apache/doris/udf/MapsiTest.java
new file mode 100644
index 00000000000..e1b7813678f
--- /dev/null
+++ 
b/regression-test/java-udf-src/src/main/java/org/apache/doris/udf/MapsiTest.java
@@ -0,0 +1,28 @@
+// 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;
+
+import java.util.*;
+
+public class MapsiTest extends UDF {
+    public Map<String, Integer> evaluate(Map<String, Integer> mp) {
+        return mp;
+    }
+}
diff --git a/regression-test/suites/javaudf_p0/test_javaudf_array.groovy 
b/regression-test/suites/javaudf_p0/test_javaudf_array.groovy
index ee02ca17cc3..0d782c036b4 100644
--- a/regression-test/suites/javaudf_p0/test_javaudf_array.groovy
+++ b/regression-test/suites/javaudf_p0/test_javaudf_array.groovy
@@ -117,6 +117,14 @@ suite("test_javaudf_array") {
         ); """
         qt_select_13 """ SELECT java_udf_array_date_test(array(datev2_col)), 
tinyint_col as result FROM ${tableName} ORDER BY result; """
 
+        sql """ DROP FUNCTION IF EXISTS 
java_udf_array_list_test(array<string>); """
+        sql """ CREATE FUNCTION java_udf_array_list_test(array<string>) 
RETURNS array<string> PROPERTIES (
+            "file"="file://${jarPath}",
+            "symbol"="org.apache.doris.udf.ArrayListTest",
+            "type"="JAVA_UDF"
+        ); """
+        qt_select_14 """ SELECT java_udf_array_list_test(array(string_col)), 
string_col, tinyint_col as result FROM ${tableName} ORDER BY result; """
+
     } finally {
         try_sql("DROP FUNCTION IF EXISTS java_udf_array_int_test(array<int>);")
         try_sql("DROP FUNCTION IF EXISTS 
java_udf_array_return_int_test(array<int>);")
@@ -124,6 +132,7 @@ suite("test_javaudf_array") {
         try_sql("DROP FUNCTION IF EXISTS 
java_udf_array_string_test(array<string>);")
         try_sql("DROP FUNCTION IF EXISTS 
java_udf_array_datatime_test(array<datetime>);")
         try_sql("DROP FUNCTION IF EXISTS 
java_udf_array_date_test(array<date>);")
+        try_sql("DROP FUNCTION IF EXISTS 
java_udf_array_list_test(array<string>);")
         try_sql("DROP TABLE IF EXISTS ${tableName}")
     }
 }
diff --git a/regression-test/suites/javaudf_p0/test_javaudf_map.groovy 
b/regression-test/suites/javaudf_p0/test_javaudf_map.groovy
index 4fe8d97c32b..9a16af30059 100644
--- a/regression-test/suites/javaudf_p0/test_javaudf_map.groovy
+++ b/regression-test/suites/javaudf_p0/test_javaudf_map.groovy
@@ -77,10 +77,35 @@ suite("test_javaudf_map") {
         ); """
 
         qt_select_2 """ select m,udfss(m) from map_ss order by id; """
+
+
+        sql """ CREATE TABLE IF NOT EXISTS map_si (
+              `id` INT(11) NULL COMMENT "",
+              `m` Map<String, int> NULL COMMENT ""
+            ) ENGINE=OLAP
+            DUPLICATE KEY(`id`)
+            DISTRIBUTED BY HASH(`id`) BUCKETS 1
+            PROPERTIES (
+            "replication_allocation" = "tag.location.default: 1",
+            "storage_format" = "V2"
+        ); """
+        sql """ INSERT INTO map_si VALUES(1, {"114":514,"1919":810});         
"""
+        sql """ INSERT INTO map_si VALUES(2, {"a":22,"def":33,"hij":44});   """
+        sql """ DROP FUNCTION IF EXISTS udfsi(Map<String, Int>); """
+
+        sql """ CREATE FUNCTION udfsi(Map<String, Int>) RETURNS Map<String, 
Int> PROPERTIES (
+            "file"="file://${jarPath}",
+            "symbol"="org.apache.doris.udf.MapsiTest",
+            "type"="JAVA_UDF"
+        ); """
+
+        qt_select_3 """ select m,udfsi(m) from map_si order by id; """
     } finally {
         try_sql("DROP FUNCTION IF EXISTS udfii(Map<INT, INT>);")
         try_sql("DROP FUNCTION IF EXISTS udfss(Map<String, String>);")
+        try_sql("DROP FUNCTION IF EXISTS udfsi(Map<String, Int>);")
         try_sql("DROP TABLE IF EXISTS map_ii")
         try_sql("DROP TABLE IF EXISTS map_ss")
+        try_sql("DROP TABLE IF EXISTS map_si")
     }
 }


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

Reply via email to