Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LemonLiTree committed Oct 18, 2023
1 parent 73299f7 commit fe788ca
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 27 deletions.
3 changes: 2 additions & 1 deletion docs/sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<FunctionSignature> 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
Expand All @@ -72,17 +68,7 @@ public FunctionSignature computeSignature(FunctionSignature signature) {
@Override
public MapAgg withDistinctAndChildren(boolean distinct, List<Expression> 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, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
return visitor.visitMapAgg(this, context);
return new MapAgg(distinct, children.get(0), children.get(1));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
29 changes: 29 additions & 0 deletions regression-test/data/nereids_function_p0/agg_function/agg.out
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

Original file line number Diff line number Diff line change
Expand Up @@ -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'''

}

0 comments on commit fe788ca

Please sign in to comment.