Kikyou1997 commented on code in PR #11802: URL: https://github.com/apache/doris/pull/11802#discussion_r946857050
########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/Avg.java: ########## @@ -18,25 +18,46 @@ package org.apache.doris.nereids.trees.expressions.functions; import org.apache.doris.nereids.trees.expressions.Expression; -import org.apache.doris.nereids.trees.expressions.UnaryExpression; +import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; +import org.apache.doris.nereids.trees.expressions.typecoercion.ImplicitCastInputTypes; import org.apache.doris.nereids.types.DataType; +import org.apache.doris.nereids.types.DateTimeType; +import org.apache.doris.nereids.types.DateType; +import org.apache.doris.nereids.types.DecimalType; import org.apache.doris.nereids.types.DoubleType; +import org.apache.doris.nereids.types.NumericType; import org.apache.doris.nereids.types.VarcharType; +import org.apache.doris.nereids.types.coercion.AbstractDataType; +import org.apache.doris.nereids.types.coercion.TypeCollection; import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; import java.util.List; /** avg agg function. */ -public class Avg extends AggregateFunction implements UnaryExpression { +public class Avg extends AggregateFunction implements UnaryExpression, ImplicitCastInputTypes { + + private static final List<AbstractDataType> EXPECTED_INPUT_TYPES = ImmutableList.of( + new TypeCollection(NumericType.INSTANCE, DateTimeType.INSTANCE, DateType.INSTANCE) + ); public Avg(Expression child) { super("avg", child); } @Override public DataType getDataType() { - return DoubleType.INSTANCE; + if (child().getDataType() instanceof DecimalType) { + DecimalType childType = (DecimalType) child().getDataType(); + return DecimalType.createDecimalType(childType.getPrecision(), childType.getScale()); Review Comment: why not return child type directly -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org