This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new b2a4cff51bf [fix](nereids)fix nullable property of ForEachCombinator
(#37980)
b2a4cff51bf is described below
commit b2a4cff51bffdd8abd22d26dd6bcf66568a10e17
Author: starocean999 <[email protected]>
AuthorDate: Wed Jul 17 13:48:21 2024 +0800
[fix](nereids)fix nullable property of ForEachCombinator (#37980)
## Proposed changes
pick from master https://github.com/apache/doris/pull/37796
<!--Describe your changes.-->
---
.../functions/combinator/ForEachCombinator.java | 19 ++++++++++++++-----
.../expressions/visitor/AggregateFunctionVisitor.java | 2 +-
.../data/function_p0/test_agg_foreach_notnull.out | 6 ++++++
.../function_p0/test_agg_foreach_notnull.groovy | 4 ++++
4 files changed, 25 insertions(+), 6 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/combinator/ForEachCombinator.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/combinator/ForEachCombinator.java
index c2a50a328a7..a6d011ff0fb 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/combinator/ForEachCombinator.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/combinator/ForEachCombinator.java
@@ -20,9 +20,9 @@ package
org.apache.doris.nereids.trees.expressions.functions.combinator;
import org.apache.doris.catalog.FunctionSignature;
import org.apache.doris.nereids.trees.expressions.Expression;
import
org.apache.doris.nereids.trees.expressions.functions.AggCombinerFunctionBuilder;
-import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable;
import
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
import
org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunction;
+import
org.apache.doris.nereids.trees.expressions.functions.agg.NullableAggregateFunction;
import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.ArrayType;
@@ -36,8 +36,8 @@ import java.util.Objects;
/**
* combinator foreach
*/
-public class ForEachCombinator extends AggregateFunction
- implements UnaryExpression, ExplicitlyCastableSignature,
AlwaysNullable, Combinator {
+public class ForEachCombinator extends NullableAggregateFunction
+ implements UnaryExpression, ExplicitlyCastableSignature, Combinator {
private final AggregateFunction nested;
@@ -45,7 +45,11 @@ public class ForEachCombinator extends AggregateFunction
* constructor of ForEachCombinator
*/
public ForEachCombinator(List<Expression> arguments, AggregateFunction
nested) {
- super(nested.getName() + AggCombinerFunctionBuilder.FOREACH_SUFFIX,
arguments);
+ this(arguments, false, nested);
+ }
+
+ public ForEachCombinator(List<Expression> arguments, boolean
alwaysNullable, AggregateFunction nested) {
+ super(nested.getName() + AggCombinerFunctionBuilder.FOREACH_SUFFIX,
false, alwaysNullable, arguments);
this.nested = Objects.requireNonNull(nested, "nested can not be null");
}
@@ -56,7 +60,7 @@ public class ForEachCombinator extends AggregateFunction
@Override
public ForEachCombinator withChildren(List<Expression> children) {
- return new ForEachCombinator(children, nested);
+ return new ForEachCombinator(children, alwaysNullable, nested);
}
@Override
@@ -88,4 +92,9 @@ public class ForEachCombinator extends AggregateFunction
public AggregateFunction withDistinctAndChildren(boolean distinct,
List<Expression> children) {
throw new UnsupportedOperationException("Unimplemented method
'withDistinctAndChildren'");
}
+
+ @Override
+ public NullableAggregateFunction withAlwaysNullable(boolean
alwaysNullable) {
+ return new ForEachCombinator(children, alwaysNullable, nested);
+ }
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/AggregateFunctionVisitor.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/AggregateFunctionVisitor.java
index 6037d7b7057..21bc0bf924b 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/AggregateFunctionVisitor.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/AggregateFunctionVisitor.java
@@ -322,7 +322,7 @@ public interface AggregateFunctionVisitor<R, C> {
}
default R visitForEachCombinator(ForEachCombinator combinator, C context) {
- return visitAggregateFunction(combinator, context);
+ return visitNullableAggregateFunction(combinator, context);
}
default R visitJavaUdaf(JavaUdaf javaUdaf, C context) {
diff --git a/regression-test/data/function_p0/test_agg_foreach_notnull.out
b/regression-test/data/function_p0/test_agg_foreach_notnull.out
index c7d50a501cb..551074719e5 100644
--- a/regression-test/data/function_p0/test_agg_foreach_notnull.out
+++ b/regression-test/data/function_p0/test_agg_foreach_notnull.out
@@ -1,4 +1,10 @@
-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !select_sum_not_null --
+[1, 2, 3]
+[20]
+[100]
+[null, 2]
+
-- !sql --
[1, 2, 3] [1, 2, 3] [100, 2, 3] [100, 2, 3]
[40.333333333333336, 2, 3] [85.95867768595042, 2, 3]
diff --git a/regression-test/suites/function_p0/test_agg_foreach_notnull.groovy
b/regression-test/suites/function_p0/test_agg_foreach_notnull.groovy
index 91f4ea902dd..a8057f46c84 100644
--- a/regression-test/suites/function_p0/test_agg_foreach_notnull.groovy
+++ b/regression-test/suites/function_p0/test_agg_foreach_notnull.groovy
@@ -61,6 +61,10 @@ suite("test_agg_foreach_not_null") {
(4,[null,2],[[2],null],[null,'c']);
"""
+ qt_select_sum_not_null """
+ select sum_foreach(a) from foreach_table_not_null group by id order by
id;
+ """
+
// this case also test combinator should be case-insensitive
qt_sql """
select min_ForEach(a),
min_by_foreach(a,a),max_foreach(a),max_by_foreach(a,a) ,
avg_foreach(a),avg_weighted_foreach(a,a) from foreach_table_not_null ;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]