Skip to content

Commit

Permalink
feat: register fe
Browse files Browse the repository at this point in the history
  • Loading branch information
joker-star-l committed Aug 22, 2024
1 parent 598f099 commit c23f9a3
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1985,7 +1985,8 @@ && collectChildReturnTypes()[0].isDecimalV3()) {

if ((fnName.getFunction().equalsIgnoreCase("money_format") || fnName.getFunction()
.equalsIgnoreCase("histogram")
|| fnName.getFunction().equalsIgnoreCase("hist"))
|| fnName.getFunction().equalsIgnoreCase("hist")
|| fnName.getFunction().equalsIgnoreCase("linear_histogram"))
&& children.get(0).getType().isDecimalV3() && args[ix].isDecimalV3()) {
continue;
} else if ((fnName.getFunction().equalsIgnoreCase("array_min") || fnName.getFunction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class AggregateFunction extends Function {
FunctionSet.ORTHOGONAL_BITMAP_EXPR_CALCULATE_COUNT, FunctionSet.ORTHOGONAL_BITMAP_EXPR_CALCULATE,
FunctionSet.INTERSECT_COUNT, FunctionSet.ORTHOGONAL_BITMAP_UNION_COUNT, FunctionSet.COUNT,
"approx_count_distinct", "ndv", FunctionSet.BITMAP_UNION_INT, FunctionSet.BITMAP_UNION_COUNT,
"ndv_no_finalize", "percentile_array", "histogram",
"ndv_no_finalize", "percentile_array", "histogram", FunctionSet.LINEAR_HISTOGRAM,
FunctionSet.SEQUENCE_COUNT, FunctionSet.MAP_AGG, FunctionSet.BITMAP_AGG, FunctionSet.ARRAY_AGG,
FunctionSet.COLLECT_LIST, FunctionSet.COLLECT_SET, FunctionSet.GROUP_ARRAY_INTERSECT,
FunctionSet.SUM0, FunctionSet.MULTI_DISTINCT_SUM0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
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.LinearHistogram;
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;
Expand Down Expand Up @@ -112,6 +113,7 @@ public class BuiltinAggregateFunctions implements FunctionHelper {
agg(GroupBitmapXor.class, "group_bitmap_xor"),
agg(GroupConcat.class, "group_concat"),
agg(Histogram.class, "hist", "histogram"),
agg(LinearHistogram.class, "linear_histogram"),
agg(HllUnion.class, "hll_raw_agg", "hll_union"),
agg(HllUnionAgg.class, "hll_union_agg"),
agg(IntersectCount.class, "intersect_count"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ public boolean isNullResultWithOneNullParamFunctions(String funcName) {
public static final String COLLECT_LIST = "collect_list";
public static final String COLLECT_SET = "collect_set";
public static final String HISTOGRAM = "histogram";
public static final String LINEAR_HISTOGRAM = "linear_histogram";
public static final String HIST = "hist";
public static final String MAP_AGG = "map_agg";

Expand Down Expand Up @@ -1499,6 +1500,14 @@ private void initAggregateBuiltins() {
Type.VARCHAR, t,
"", "", "", "", "", true, false, true, true));

// linear histogram
addBuiltin(AggregateFunction.createBuiltin(LINEAR_HISTOGRAM,
Lists.<Type>newArrayList(t, Type.DOUBLE), Type.VARCHAR, t,
"", "", "", "", "", true, false, true, true));
addBuiltin(AggregateFunction.createBuiltin(LINEAR_HISTOGRAM,
Lists.<Type>newArrayList(t, Type.DOUBLE, Type.DOUBLE), Type.VARCHAR, t,
"", "", "", "", "", true, false, true, true));

// group array
addBuiltin(AggregateFunction.createBuiltin(GROUP_UNIQ_ARRAY, Lists.newArrayList(t), new ArrayType(t), t,
"", "", "", "", "", true, false, true, true));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// 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.FunctionSet;
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.functions.SearchSignature;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DoubleType;
import org.apache.doris.nereids.types.VarcharType;
import org.apache.doris.nereids.types.coercion.AnyDataType;
import org.apache.doris.nereids.types.coercion.PrimitiveType;

import com.google.common.collect.ImmutableList;

import java.util.List;

/**
* AggregateFunction 'linear_histogram'.
*/
public class LinearHistogram extends AggregateFunction implements ExplicitlyCastableSignature, AlwaysNotNullable {

public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT)
.args(AnyDataType.INSTANCE_WITHOUT_INDEX, DoubleType.INSTANCE),
FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT)
.args(AnyDataType.INSTANCE_WITHOUT_INDEX, DoubleType.INSTANCE, DoubleType.INSTANCE)
);

private LinearHistogram(boolean distinct, List<Expression> args) {
super(FunctionSet.LINEAR_HISTOGRAM, distinct, args);
}

public LinearHistogram(Expression arg0, Expression arg1) {
super(FunctionSet.LINEAR_HISTOGRAM, arg0, arg1);
}

public LinearHistogram(Expression arg0, Expression arg1, Expression arg2) {
super(FunctionSet.LINEAR_HISTOGRAM, arg0, arg1, arg2);
}

public LinearHistogram(boolean distinct, Expression arg0, Expression arg1) {
super(FunctionSet.LINEAR_HISTOGRAM, distinct, arg0, arg1);
}

public LinearHistogram(boolean distinct, Expression arg0, Expression arg1, Expression arg2) {
super(FunctionSet.LINEAR_HISTOGRAM, distinct, arg0, arg1, arg2);
}

@Override
public void checkLegalityBeforeTypeCoercion() {
if (!(child(0).getDataType() instanceof PrimitiveType)) {
SearchSignature.throwCanNotFoundFunctionException(this.getName(), getArguments());
}
}

@Override
public AggregateFunction withDistinctAndChildren(boolean distinct, List<Expression> children) {
return new LinearHistogram(distinct, children);
}

@Override
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
return visitor.visitLinearHistogram(this, context);
}

@Override
public List<FunctionSignature> getSignatures() {
return SIGNATURES;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
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.LinearHistogram;
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;
Expand Down Expand Up @@ -198,6 +199,10 @@ default R visitHistogram(Histogram histogram, C context) {
return visitAggregateFunction(histogram, context);
}

default R visitLinearHistogram(LinearHistogram linearHistogram, C context) {
return visitAggregateFunction(linearHistogram, context);
}

default R visitHllUnion(HllUnion hllUnion, C context) {
return visitAggregateFunction(hllUnion, context);
}
Expand Down

0 comments on commit c23f9a3

Please sign in to comment.