diff --git a/docs/sidebars.json b/docs/sidebars.json index b1ba566c560897..29e01e7455067d 100644 --- a/docs/sidebars.json +++ b/docs/sidebars.json @@ -566,7 +566,8 @@ "sql-manual/sql-functions/aggregate-functions/grouping", "sql-manual/sql-functions/aggregate-functions/grouping-id", "sql-manual/sql-functions/aggregate-functions/count-by-enum", - "sql-manual/sql-functions/aggregate-functions/histogram" + "sql-manual/sql-functions/aggregate-functions/histogram", + "sql-manual/sql-functions/aggregate-functions/map-agg" ] }, { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MapAgg.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MapAgg.java index c65bc97b12bc85..992b6810079b1c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MapAgg.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MapAgg.java @@ -19,45 +19,41 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.AlwaysNotNullable; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; -import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.MapType; import org.apache.doris.nereids.types.coercion.AnyDataType; +import org.apache.doris.nereids.types.coercion.FollowToAnyDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; -import org.apache.doris.nereids.types.coercion.FollowToAnyDataType; import java.util.List; /** * AggregateFunction 'map_agg'. This class is generated by GenerateFunction. */ -public class MapAgg extends NullableAggregateFunction - implements BinaryExpression, ExplicitlyCastableSignature { +public class MapAgg extends AggregateFunction + implements BinaryExpression, ExplicitlyCastableSignature, AlwaysNotNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(MapType.of(new FollowToAnyDataType(0), new FollowToAnyDataType(1))) - .args(AnyDataType.INSTANCE_WITHOUT_INDEX, AnyDataType.INSTANCE_WITHOUT_INDEX) + FunctionSignature.ret(MapType.of(new FollowToAnyDataType(0), new FollowToAnyDataType(1))) + .args(new AnyDataType(0), new AnyDataType(1)) ); - /** + /**FunctionSignature * constructor with 2 arguments. */ public MapAgg(Expression arg0, Expression arg1) { - this(false, false, arg0, arg1); + this(false, arg0, arg1); } /** * constructor with 2 arguments. */ - public MapAgg(boolean distinct, Expression arg0, Expression arg1) { - this(distinct, false, arg0, arg1); - } - - private MapAgg(boolean distinct, boolean alwaysNullable, Expression arg0, Expression arg1) { - super("map_agg", distinct, false, arg0, arg1); + private MapAgg(boolean distinct, Expression arg0, Expression arg1) { + super("map_agg", distinct, arg0, arg1); } @Override @@ -72,17 +68,7 @@ public FunctionSignature computeSignature(FunctionSignature signature) { @Override public MapAgg withDistinctAndChildren(boolean distinct, List children) { Preconditions.checkArgument(children.size() == 2); - return new MapAgg(distinct, alwaysNullable, children.get(0), children.get(1)); - } - - @Override - public MapAgg withAlwaysNullable(boolean alwaysNullable) { - return new MapAgg(distinct, alwaysNullable, children.get(0), children.get(1)); - } - - @Override - public R accept(ExpressionVisitor visitor, C context) { - return visitor.visitMapAgg(this, context); + return new MapAgg(distinct, children.get(0), children.get(1)); } @Override 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 65ff7af8e26ab9..1a4c51aad0345a 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 @@ -286,6 +286,6 @@ default R visitJavaUdaf(JavaUdaf javaUdaf, C context) { } default R visitMapAgg(MapAgg mapAgg, C context) { - return visitNullableAggregateFunction(mapAgg, context); + return visitAggregateFunction(mapAgg, context); } } diff --git a/regression-test/data/nereids_function_p0/agg_function/agg.out b/regression-test/data/nereids_function_p0/agg_function/agg.out index 78573751cb0f4c..f3df5bb9145dc8 100644 --- a/regression-test/data/nereids_function_p0/agg_function/agg.out +++ b/regression-test/data/nereids_function_p0/agg_function/agg.out @@ -5990,3 +5990,32 @@ true -- !max_null -- \N +-- !sql_map_agg -- +\N {} +0 {1:"string1"} +1 {2:"string2"} +2 {3:"string3"} +3 {4:"string1"} +4 {5:"string2"} +5 {6:"string3"} +6 {7:"string1"} +7 {8:"string2"} +8 {9:"string3"} +9 {10:"string1"} +10 {11:"string2"} +11 {12:"string3"} + +-- !sql_map_agg_not_nullable -- +0 {1:"string1"} +1 {2:"string2"} +2 {3:"string3"} +3 {4:"string1"} +4 {5:"string2"} +5 {6:"string3"} +6 {7:"string1"} +7 {8:"string2"} +8 {9:"string3"} +9 {10:"string1"} +10 {11:"string2"} +11 {12:"string3"} + diff --git a/regression-test/suites/nereids_function_p0/agg_function/agg.groovy b/regression-test/suites/nereids_function_p0/agg_function/agg.groovy index 870b66d339280c..98b16857451717 100644 --- a/regression-test/suites/nereids_function_p0/agg_function/agg.groovy +++ b/regression-test/suites/nereids_function_p0/agg_function/agg.groovy @@ -2765,4 +2765,10 @@ suite("nereids_agg_fn") { qt_max_null "select max(null) from fn_test;" + qt_sql_map_agg ''' + select id,map_agg(kint,kstr) from fn_test group by id order by id''' + + qt_sql_map_agg_not_nullable ''' + select id,map_agg(kint,kstr) from fn_test_not_nullable group by id order by id''' + }