[feature](fe) add function 'BitmapAgg' in nereids (#25508)

This commit is contained in:
Jerry Hu
2023-10-18 14:24:27 +08:00
committed by GitHub
parent 8a8e6edba9
commit 62d06584f1
5 changed files with 107 additions and 0 deletions

View File

@ -20,6 +20,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.Avg;
import org.apache.doris.nereids.trees.expressions.functions.agg.AvgWeighted;
import org.apache.doris.nereids.trees.expressions.functions.agg.BitmapAgg;
import org.apache.doris.nereids.trees.expressions.functions.agg.BitmapIntersect;
import org.apache.doris.nereids.trees.expressions.functions.agg.BitmapUnion;
import org.apache.doris.nereids.trees.expressions.functions.agg.BitmapUnionCount;
@ -82,6 +83,7 @@ public class BuiltinAggregateFunctions implements FunctionHelper {
agg(AnyValue.class, "any", "any_value"),
agg(Avg.class, "avg"),
agg(AvgWeighted.class, "avg_weighted"),
agg(BitmapAgg.class, "bitmap_agg"),
agg(BitmapIntersect.class, "bitmap_intersect"),
agg(BitmapUnion.class, "bitmap_union"),
agg(BitmapUnionCount.class, "bitmap_union_count"),

View File

@ -0,0 +1,66 @@
// 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.types.BigIntType;
import org.apache.doris.nereids.types.BitmapType;
import org.apache.doris.nereids.types.IntegerType;
import org.apache.doris.nereids.types.SmallIntType;
import org.apache.doris.nereids.types.TinyIntType;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import java.util.List;
/**
* AggregateFunction 'bitmap_agg'.
*/
public class BitmapAgg extends AggregateFunction
implements UnaryExpression, ExplicitlyCastableSignature, AlwaysNotNullable {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(BitmapType.INSTANCE).args(TinyIntType.INSTANCE),
FunctionSignature.ret(BitmapType.INSTANCE).args(SmallIntType.INSTANCE),
FunctionSignature.ret(BitmapType.INSTANCE).args(IntegerType.INSTANCE),
FunctionSignature.ret(BitmapType.INSTANCE).args(BigIntType.INSTANCE)
);
public BitmapAgg(Expression arg0) {
super("bitmap_agg", arg0);
}
public BitmapAgg(boolean distinct, Expression arg0) {
super("bitmap_agg", distinct, arg0);
}
@Override
public List<FunctionSignature> getSignatures() {
return SIGNATURES;
}
@Override
public AggregateFunction withDistinctAndChildren(boolean distinct, List<Expression> children) {
Preconditions.checkArgument(children.size() == 1);
return new BitmapAgg(distinct, children.get(0));
}
}

View File

@ -21,6 +21,7 @@ import org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunctio
import org.apache.doris.nereids.trees.expressions.functions.agg.AnyValue;
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;
import org.apache.doris.nereids.trees.expressions.functions.agg.BitmapIntersect;
import org.apache.doris.nereids.trees.expressions.functions.agg.BitmapUnion;
import org.apache.doris.nereids.trees.expressions.functions.agg.BitmapUnionCount;
@ -91,6 +92,10 @@ public interface AggregateFunctionVisitor<R, C> {
return visitAggregateFunction(avgWeighted, context);
}
default R visitBitmapAgg(BitmapAgg bitmapAgg, C context) {
return visitAggregateFunction(bitmapAgg, context);
}
default R visitBitmapIntersect(BitmapIntersect bitmapIntersect, C context) {
return visitAggregateFunction(bitmapIntersect, context);
}