morrySnow commented on code in PR #61352: URL: https://github.com/apache/doris/pull/61352#discussion_r2938073573
########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/RegrAvgx.java: ########## @@ -0,0 +1,85 @@ +// 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.catalog.Type; +import org.apache.doris.nereids.exceptions.AnalysisException; +import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable; +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.DataType; +import org.apache.doris.nereids.types.DoubleType; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; + +import java.util.List; + +/** regr_avgx agg function. */ +public class RegrAvgx extends AggregateFunction + implements BinaryExpression, ExplicitlyCastableSignature, AlwaysNullable { + + public static final List<FunctionSignature> SIGNATURES = ImmutableList.of( + FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE, DoubleType.INSTANCE)); + + public RegrAvgx(Expression arg0, Expression arg1) { + this(false, arg0, arg1); + } + + public RegrAvgx(boolean distinct, Expression arg0, Expression arg1) { + super("regr_avgx", distinct, arg0, arg1); + } + + public RegrAvgx(AggregateFunctionParams functionParams) { + super(functionParams); + } + + @Override + public void checkLegalityBeforeTypeCoercion() { + DataType yType = left().getDataType(); + DataType xType = right().getDataType(); + if (yType.isOnlyMetricType() || xType.isOnlyMetricType()) { + throw new AnalysisException(Type.OnlyMetricTypeErrorMsg); + } + if (!yType.isNumericType() && !yType.isNullType()) { + throw new AnalysisException("regr_avgx requires numeric for first parameter: " + toSql()); + } + if (!xType.isNumericType() && !xType.isNullType()) { + throw new AnalysisException("regr_avgx requires numeric for second parameter: " + toSql()); + } Review Comment: maybe we should support string type expr as a parameter ########## fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java: ########## @@ -100,8 +100,16 @@ public boolean isNullResultWithOneNullParamFunctions(String funcName) { public static final String COUNT = "count"; + public static final String REGR_AVGX = "regr_avgx"; Review Comment: remove these useless code -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
