[feature](nereids) add function array_agg (#25630)
This commit is contained in:
@ -18,6 +18,7 @@
|
||||
package org.apache.doris.catalog;
|
||||
|
||||
import org.apache.doris.nereids.trees.expressions.functions.agg.AnyValue;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.agg.ArrayAgg;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.agg.Avg;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.agg.AvgWeighted;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.agg.BitmapAgg;
|
||||
@ -82,6 +83,7 @@ import java.util.Set;
|
||||
public class BuiltinAggregateFunctions implements FunctionHelper {
|
||||
public final List<AggregateFunc> aggregateFunctions = ImmutableList.of(
|
||||
agg(AnyValue.class, "any", "any_value"),
|
||||
agg(ArrayAgg.class, "array_agg"),
|
||||
agg(Avg.class, "avg"),
|
||||
agg(AvgWeighted.class, "avg_weighted"),
|
||||
agg(BitmapAgg.class, "bitmap_agg"),
|
||||
|
||||
@ -0,0 +1,67 @@
|
||||
// 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.UnaryExpression;
|
||||
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
|
||||
import org.apache.doris.nereids.types.ArrayType;
|
||||
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 'array_agg'.
|
||||
*/
|
||||
public class ArrayAgg extends AggregateFunction
|
||||
implements UnaryExpression, ExplicitlyCastableSignature, AlwaysNotNullable {
|
||||
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
|
||||
FunctionSignature.ret(ArrayType.of(new FollowToAnyDataType(0))).args(new AnyDataType(0))
|
||||
);
|
||||
|
||||
public ArrayAgg(Expression arg0) {
|
||||
super("array_agg", arg0);
|
||||
}
|
||||
|
||||
public ArrayAgg(boolean distinct, Expression arg0) {
|
||||
super("array_agg", distinct, arg0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregateFunction withDistinctAndChildren(boolean distinct, List<Expression> children) {
|
||||
Preconditions.checkArgument(children.size() == 1);
|
||||
return new ArrayAgg(distinct, children.get(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
|
||||
return visitor.visitArrayAgg(this, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FunctionSignature> getSignatures() {
|
||||
return SIGNATURES;
|
||||
}
|
||||
}
|
||||
@ -19,6 +19,7 @@ package org.apache.doris.nereids.trees.expressions.visitor;
|
||||
|
||||
import org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunction;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.agg.AnyValue;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.agg.ArrayAgg;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.agg.Avg;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.agg.AvgWeighted;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.agg.BitmapAgg;
|
||||
@ -85,6 +86,10 @@ public interface AggregateFunctionVisitor<R, C> {
|
||||
return visitAggregateFunction(anyValue, context);
|
||||
}
|
||||
|
||||
default R visitArrayAgg(ArrayAgg arrayAgg, C context) {
|
||||
return visitAggregateFunction(arrayAgg, context);
|
||||
}
|
||||
|
||||
default R visitAvg(Avg avg, C context) {
|
||||
return visitNullableAggregateFunction(avg, context);
|
||||
}
|
||||
|
||||
@ -6019,3 +6019,32 @@ true
|
||||
10 {11:"string2"}
|
||||
11 {12:"string3"}
|
||||
|
||||
-- !sql_array_agg --
|
||||
\N [NULL]
|
||||
0 [1]
|
||||
1 [2]
|
||||
2 [3]
|
||||
3 [4]
|
||||
4 [5]
|
||||
5 [6]
|
||||
6 [7]
|
||||
7 [8]
|
||||
8 [9]
|
||||
9 [10]
|
||||
10 [11]
|
||||
11 [12]
|
||||
|
||||
-- !sql_array_agg_not_nullable --
|
||||
0 [1]
|
||||
1 [2]
|
||||
2 [3]
|
||||
3 [4]
|
||||
4 [5]
|
||||
5 [6]
|
||||
6 [7]
|
||||
7 [8]
|
||||
8 [9]
|
||||
9 [10]
|
||||
10 [11]
|
||||
11 [12]
|
||||
|
||||
|
||||
@ -2771,4 +2771,10 @@ suite("nereids_agg_fn") {
|
||||
qt_sql_map_agg_not_nullable '''
|
||||
select id,map_agg(kint,kstr) from fn_test_not_nullable group by id order by id'''
|
||||
|
||||
qt_sql_array_agg '''
|
||||
select id,array_agg(kint) from fn_test group by id order by id'''
|
||||
|
||||
qt_sql_array_agg_not_nullable '''
|
||||
select id,array_agg(kint) from fn_test_not_nullable group by id order by id'''
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user