[feature](Nereids) add map_agg function (#25246)
This commit is contained in:
@ -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"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@ -38,6 +38,7 @@ import org.apache.doris.nereids.trees.expressions.functions.agg.Histogram;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.agg.HllUnion;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.agg.HllUnionAgg;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.agg.IntersectCount;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.agg.MapAgg;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.agg.Max;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.agg.MaxBy;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.agg.Min;
|
||||
@ -101,6 +102,7 @@ public class BuiltinAggregateFunctions implements FunctionHelper {
|
||||
agg(HllUnion.class, "hll_raw_agg", "hll_union"),
|
||||
agg(HllUnionAgg.class, "hll_union_agg"),
|
||||
agg(IntersectCount.class, "intersect_count"),
|
||||
agg(MapAgg.class, "map_agg"),
|
||||
agg(Max.class, "max"),
|
||||
agg(MaxBy.class, "max_by"),
|
||||
agg(Min.class, "min"),
|
||||
|
||||
@ -0,0 +1,72 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package org.apache.doris.nereids.trees.expressions.functions.agg;
|
||||
|
||||
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.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 java.util.List;
|
||||
|
||||
/**
|
||||
* AggregateFunction 'map_agg'. This class is generated by GenerateFunction.
|
||||
*/
|
||||
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(new AnyDataType(0), new AnyDataType(1))
|
||||
);
|
||||
|
||||
/**FunctionSignature
|
||||
* constructor with 2 arguments.
|
||||
*/
|
||||
public MapAgg(Expression arg0, Expression arg1) {
|
||||
this(false, arg0, arg1);
|
||||
}
|
||||
|
||||
/**
|
||||
* constructor with 2 arguments.
|
||||
*/
|
||||
private MapAgg(boolean distinct, Expression arg0, Expression arg1) {
|
||||
super("map_agg", distinct, arg0, arg1);
|
||||
}
|
||||
|
||||
/**
|
||||
* withDistinctAndChildren.
|
||||
*/
|
||||
@Override
|
||||
public MapAgg withDistinctAndChildren(boolean distinct, List<Expression> children) {
|
||||
Preconditions.checkArgument(children.size() == 2);
|
||||
return new MapAgg(distinct, children.get(0), children.get(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FunctionSignature> getSignatures() {
|
||||
return SIGNATURES;
|
||||
}
|
||||
}
|
||||
@ -39,6 +39,7 @@ import org.apache.doris.nereids.trees.expressions.functions.agg.Histogram;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.agg.HllUnion;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.agg.HllUnionAgg;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.agg.IntersectCount;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.agg.MapAgg;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.agg.Max;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.agg.MaxBy;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.agg.Min;
|
||||
@ -176,6 +177,10 @@ public interface AggregateFunctionVisitor<R, C> {
|
||||
return visitAggregateFunction(intersectCount, context);
|
||||
}
|
||||
|
||||
default R visitMapAgg(MapAgg mapAgg, C context) {
|
||||
return visitAggregateFunction(mapAgg, context);
|
||||
}
|
||||
|
||||
default R visitMax(Max max, C context) {
|
||||
return visitNullableAggregateFunction(max, context);
|
||||
}
|
||||
@ -283,4 +288,5 @@ public interface AggregateFunctionVisitor<R, C> {
|
||||
default R visitJavaUdaf(JavaUdaf javaUdaf, C context) {
|
||||
return visitAggregateFunction(javaUdaf, context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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"}
|
||||
|
||||
|
||||
@ -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'''
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user