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 cdfe98429efe7c..9a3f28499d5ea9 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 @@ private ArrayReverseSort(ScalarFunctionParams functionParams) { @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 6dad49cd9bf38b..2e8b738237ab04 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 @@ -62,9 +62,13 @@ private ArraySort(ScalarFunctionParams functionParams) { public void checkLegalityBeforeTypeCoercion() { if (children.get(0).getDataType() instanceof ArrayType) { DataType argType = child(0).getDataType(); - if (argType.isArrayType() && (((ArrayType) argType).getItemType().isComplexType() - || ((ArrayType) argType).getItemType().isVariantType() - || ((ArrayType) argType).getItemType().isJsonType())) { + // 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 9518ed89651da5..43e1c25aa9799d 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 ArraySortBy withChildren(List children) { @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 22bab015a27a64..ee85529dd24171 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 3c5cb92ae9682a..648c021322b500 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>" } - test { - sql """ SELECT ARRAY_SORTBY(array(array(1, 2), array(3, 4)), array(1, 2)); """ - exception "array_reverse_sort does not support types: ARRAY>" - } - - test { - sql """ SELECT ARRAY_SORT(array(array(1, 2), array(3, 4))); """ - exception "array_sort does not support types: ARRAY>" - } - - test { - sql """ SELECT ARRAY_REVERSE_SORT(array(array(1, 2), array(3, 4))); """ - exception "array_reverse_sort does not support types: ARRAY>" - } - 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