This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.1 by this push:
new 3ea3cd03120 branch-4.1: [fix](function) Validate array_sort lambda
arity #64825 (#64861)
3ea3cd03120 is described below
commit 3ea3cd03120bc92330c5a9aee9146ff61b1c185b
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Fri Jun 26 11:19:21 2026 +0800
branch-4.1: [fix](function) Validate array_sort lambda arity #64825 (#64861)
Cherry-picked from #64825
Co-authored-by: morrySnow <[email protected]>
---
.../nereids/trees/expressions/functions/scalar/ArraySort.java | 7 +++++++
.../nereids/rules/analysis/CheckExpressionLegalityTest.java | 10 ++++++++++
.../suites/nereids_function_p0/scalar_function/Array2.groovy | 4 ++++
3 files changed, 21 insertions(+)
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 3a905016da0..9ab248bc673 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
@@ -72,6 +72,13 @@ public class ArraySort extends ScalarFunction
throw new AnalysisException("array_sort does not support
types: " + argType.toSql());
}
}
+ if (getArgument(0) instanceof Lambda) {
+ Lambda lambda = (Lambda) getArgument(0);
+ if (lambda.getLambdaArgumentNames().size() != 2) {
+ throw new AnalysisException("When using lambda as the
parameter of array_sort,"
+ + " the lambda must be a binary comparator lambda.");
+ }
+ }
}
/**
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/CheckExpressionLegalityTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/CheckExpressionLegalityTest.java
index c70f3844e59..447156afb38 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/CheckExpressionLegalityTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/CheckExpressionLegalityTest.java
@@ -60,6 +60,16 @@ public class CheckExpressionLegalityTest implements
MemoPatternMatchSupported {
});
}
+ @Test
+ public void testArraySortLambdaArgumentCount() {
+ ConnectContext connectContext = MemoTestUtils.createConnectContext();
+ ExceptionChecker.expectThrowsWithMsg(AnalysisException.class,
+ "the lambda must be a binary comparator lambda", () -> {
+ PlanChecker.from(connectContext)
+ .analyze("select array_sort(x -> x, [1, 2, 3])");
+ });
+ }
+
@Test
public void testCountDistinctBitmap() {
ConnectContext connectContext = MemoTestUtils.createConnectContext();
diff --git
a/regression-test/suites/nereids_function_p0/scalar_function/Array2.groovy
b/regression-test/suites/nereids_function_p0/scalar_function/Array2.groovy
index eaa648e6c45..4a6b890c04a 100644
--- a/regression-test/suites/nereids_function_p0/scalar_function/Array2.groovy
+++ b/regression-test/suites/nereids_function_p0/scalar_function/Array2.groovy
@@ -45,6 +45,10 @@ suite("nereids_scalar_fn_Array2") {
IF(IPV4_STRING_TO_NUM_OR_NULL(x) =
IPV4_STRING_TO_NUM_OR_NULL(y), 0, 1)),
['192.168.0.3', '192.168.0.1',
'192.168.0.2'])"""
order_qt_sql_array_sort_8 """SELECT array_sort((x, y) -> IF(x < y, 1, IF(x
= y, 0, -1)), [3, -2.1, 5.34, 1.2, 2.2])"""
+ test {
+ sql """SELECT array_sort(x -> x, [3, 2, 1])"""
+ exception "the lambda must be a binary comparator lambda"
+ }
order_qt_sql_array_sort_Tinyint """SELECT array_sort((x, y) -> CASE WHEN x
IS NULL THEN -1
WHEN y IS NULL THEN 1
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]