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

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


The following commit(s) were added to refs/heads/branch-4.0 by this push:
     new 429bcef5041 [fix](array)array sorting function supports 
multidimensional arrays (#60173) (#60261)
429bcef5041 is described below

commit 429bcef5041e37309fba89a28c6a11c2f205ac2d
Author: Sun Chenyang <[email protected]>
AuthorDate: Wed Jan 28 18:26:10 2026 +0800

    [fix](array)array sorting function supports multidimensional arrays 
(#60173) (#60261)
    
    pick from master #60173
---
 .../functions/scalar/ArrayReverseSort.java            | 16 +++++++++++-----
 .../trees/expressions/functions/scalar/ArraySort.java | 16 +++++++++++-----
 .../expressions/functions/scalar/ArraySortBy.java     | 16 +++++++++++-----
 .../sql-manual/sql-function/test_array_function.out   |  9 +++++++++
 .../sql-function/test_array_function.groovy           | 19 ++++---------------
 5 files changed, 46 insertions(+), 30 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayReverseSort.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayReverseSort.java
index cdfe98429ef..9a3f28499d5 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayReverseSort.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayReverseSort.java
@@ -57,11 +57,17 @@ public class ArrayReverseSort extends ScalarFunction
 
     @Override
     public void checkLegalityBeforeTypeCoercion() {
-        DataType argType = child(0).getDataType();
-        if (argType.isArrayType() && (((ArrayType) 
argType).getItemType().isComplexType()
-                    || ((ArrayType) argType).getItemType().isVariantType()
-                    || ((ArrayType) argType).getItemType().isJsonType())) {
-            throw new AnalysisException("array_reverse_sort does not support 
types: " + argType.toSql());
+        if (children.get(0).getDataType() instanceof ArrayType) {
+            DataType argType = child(0).getDataType();
+            // Find the innermost element type for nested arrays
+            DataType itemType = ((ArrayType) argType).getItemType();
+            while (itemType.isArrayType()) {
+                itemType = ((ArrayType) itemType).getItemType();
+            }
+            if (itemType.isMapType() || itemType.isStructType()
+                    || itemType.isVariantType() || itemType.isJsonType()) {
+                throw new AnalysisException("array_reverse_sort does not 
support types: " + argType.toSql());
+            }
         }
     }
 
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySort.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySort.java
index 33d05241476..daf1330032c 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySort.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySort.java
@@ -57,11 +57,17 @@ public class ArraySort extends ScalarFunction
 
     @Override
     public void checkLegalityBeforeTypeCoercion() {
-        DataType argType = child(0).getDataType();
-        if (argType.isArrayType() && (((ArrayType) 
argType).getItemType().isComplexType()
-                    || ((ArrayType) argType).getItemType().isVariantType()
-                    || ((ArrayType) argType).getItemType().isJsonType())) {
-            throw new AnalysisException("array_sort does not support types: " 
+ argType.toSql());
+        if (children.get(0).getDataType() instanceof ArrayType) {
+            DataType argType = child(0).getDataType();
+            // Find the innermost element type for nested arrays
+            DataType itemType = ((ArrayType) argType).getItemType();
+            while (itemType.isArrayType()) {
+                itemType = ((ArrayType) itemType).getItemType();
+            }
+            if (itemType.isMapType() || itemType.isStructType()
+                    || itemType.isVariantType() || itemType.isJsonType()) {
+                throw new AnalysisException("array_sort does not support 
types: " + argType.toSql());
+            }
         }
     }
 
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySortBy.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySortBy.java
index 9518ed89651..43e1c25aa97 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySortBy.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySortBy.java
@@ -68,11 +68,17 @@ public class ArraySortBy extends ScalarFunction
 
     @Override
     public void checkLegalityBeforeTypeCoercion() {
-        DataType argType = child(0).getDataType();
-        if (argType.isArrayType() && (((ArrayType) 
argType).getItemType().isComplexType()
-                    || ((ArrayType) argType).getItemType().isVariantType()
-                    || ((ArrayType) argType).getItemType().isJsonType())) {
-            throw new AnalysisException("array_reverse_sort does not support 
types: " + argType.toSql());
+        if (children.get(0).getDataType() instanceof ArrayType) {
+            DataType argType = child(0).getDataType();
+            // Find the innermost element type for nested arrays
+            DataType itemType = ((ArrayType) argType).getItemType();
+            while (itemType.isArrayType()) {
+                itemType = ((ArrayType) itemType).getItemType();
+            }
+            if (itemType.isMapType() || itemType.isStructType()
+                    || itemType.isVariantType() || itemType.isJsonType()) {
+                throw new AnalysisException("array_sortby does not support 
types: " + argType.toSql());
+            }
         }
     }
 
diff --git 
a/regression-test/data/doc/sql-manual/sql-function/test_array_function.out 
b/regression-test/data/doc/sql-manual/sql-function/test_array_function.out
index 22bab015a27..ee85529dd24 100644
--- a/regression-test/data/doc/sql-manual/sql-function/test_array_function.out
+++ b/regression-test/data/doc/sql-manual/sql-function/test_array_function.out
@@ -554,3 +554,12 @@ false
 ["::1", "::2", "::3"]
 ["::1", "::2", "::3"]
 
+-- !sql --
+[[1, 2], [3, 4]]
+
+-- !sql --
+[[1, 2], [3, 4]]
+
+-- !sql --
+[[3, 4], [1, 2]]
+
diff --git 
a/regression-test/suites/doc/sql-manual/sql-function/test_array_function.groovy 
b/regression-test/suites/doc/sql-manual/sql-function/test_array_function.groovy
index 3c5cb92ae96..648c021322b 100644
--- 
a/regression-test/suites/doc/sql-manual/sql-function/test_array_function.groovy
+++ 
b/regression-test/suites/doc/sql-manual/sql-function/test_array_function.groovy
@@ -445,21 +445,6 @@ suite("test_array_function_doc", "p0") {
         exception "countequal does not support types: ARRAY<ARRAY<TINYINT>>"
     }
 
-    test {
-        sql """ SELECT ARRAY_SORTBY(array(array(1, 2), array(3, 4)), array(1, 
2)); """
-        exception "array_reverse_sort does not support types: 
ARRAY<ARRAY<TINYINT>>"
-    }
-
-    test {
-        sql """ SELECT ARRAY_SORT(array(array(1, 2), array(3, 4))); """
-        exception "array_sort does not support types: ARRAY<ARRAY<TINYINT>>"
-    }
-
-    test {
-        sql """ SELECT ARRAY_REVERSE_SORT(array(array(1, 2), array(3, 4))); """
-        exception "array_reverse_sort does not support types: 
ARRAY<ARRAY<TINYINT>>"
-    }
-
     qt_sql """ SELECT ARRAY_REMOVE(ARRAY(1, 2, 3, 2, null), 2); """
     qt_sql """ SELECT ARRAY_REMOVE(array_int, 2) from ${tableName}; """
 
@@ -531,4 +516,8 @@ suite("test_array_function_doc", "p0") {
     qt_sql """ SELECT ARRAY_REMOVE(array_datetime, null) from ${tableName}; """
     qt_sql """ SELECT ARRAY_REMOVE(array_ipv4, null) from ${tableName}; """
     qt_sql """ SELECT ARRAY_REMOVE(array_ipv6, null) from ${tableName}; """
+
+    qt_sql """ SELECT ARRAY_SORTBY(x -> x[1], [[1,2],[3,4]]); """
+    qt_sql """ SELECT ARRAY_SORT([[1,2],[3,4]]); """
+    qt_sql """ SELECT ARRAY_REVERSE_SORT([[1,2],[3,4]]); """
 }
\ No newline at end of file


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

Reply via email to