From ec07dd2b521bf8305972a0d96e9e30e5b81d2eec Mon Sep 17 00:00:00 2001 From: morrySnow Date: Wed, 14 Aug 2024 17:19:14 +0800 Subject: [PATCH] [opt](Nereids) polish aggregate function signature matching use double to match string - corr - covar - covar_samp - stddev - stddev_samp use largeint to match string - group_bit_and - group_bit_or - group_git_xor use double to match decimalv3 - topn_weighted optimize error message - multi_distinct_sum - multi_distinct_sum0 --- .../functions/agg/AvgWeighted.java | 10 +-- .../expressions/functions/agg/BitmapAgg.java | 8 +- .../functions/agg/CollectList.java | 6 -- .../trees/expressions/functions/agg/Corr.java | 10 +-- .../expressions/functions/agg/Covar.java | 10 +-- .../expressions/functions/agg/CovarSamp.java | 10 +-- .../functions/agg/GroupBitAnd.java | 8 +- .../expressions/functions/agg/GroupBitOr.java | 8 +- .../functions/agg/GroupBitXor.java | 8 +- .../functions/agg/MultiDistinctSum.java | 17 ++--- .../functions/agg/MultiDistinctSum0.java | 17 ++--- .../expressions/functions/agg/Stddev.java | 6 +- .../expressions/functions/agg/StddevSamp.java | 6 +- .../functions/agg/TopNWeighted.java | 73 ++++++++++--------- .../expressions/functions/agg/Variance.java | 6 +- .../functions/agg/VarianceSamp.java | 6 +- .../nereids_function_p0/type_coercion.out | 27 +++++++ .../nereids_function_p0/type_coercion.groovy | 28 +++++++ 18 files changed, 153 insertions(+), 111 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/AvgWeighted.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/AvgWeighted.java index 82127810135249..ea2a293f988041 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/AvgWeighted.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/AvgWeighted.java @@ -43,12 +43,12 @@ public class AvgWeighted extends NullableAggregateFunction public static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE, DoubleType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(TinyIntType.INSTANCE, DoubleType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(SmallIntType.INSTANCE, DoubleType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(IntegerType.INSTANCE, DoubleType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(DecimalV2Type.SYSTEM_DEFAULT, DoubleType.INSTANCE), FunctionSignature.ret(DoubleType.INSTANCE).args(BigIntType.INSTANCE, DoubleType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(FloatType.INSTANCE, DoubleType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(DecimalV2Type.SYSTEM_DEFAULT, DoubleType.INSTANCE) + FunctionSignature.ret(DoubleType.INSTANCE).args(IntegerType.INSTANCE, DoubleType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(SmallIntType.INSTANCE, DoubleType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(TinyIntType.INSTANCE, DoubleType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(FloatType.INSTANCE, DoubleType.INSTANCE) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/BitmapAgg.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/BitmapAgg.java index 5b348b07318469..1d32910e1a9c49 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/BitmapAgg.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/BitmapAgg.java @@ -39,11 +39,11 @@ public class BitmapAgg extends AggregateFunction implements UnaryExpression, ExplicitlyCastableSignature, AlwaysNotNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(BitmapType.INSTANCE).args(TinyIntType.INSTANCE), - FunctionSignature.ret(BitmapType.INSTANCE).args(SmallIntType.INSTANCE), + FunctionSignature.ret(BitmapType.INSTANCE).args(BigIntType.INSTANCE), FunctionSignature.ret(BitmapType.INSTANCE).args(IntegerType.INSTANCE), - FunctionSignature.ret(BitmapType.INSTANCE).args(BigIntType.INSTANCE) - ); + FunctionSignature.ret(BitmapType.INSTANCE).args(SmallIntType.INSTANCE), + FunctionSignature.ret(BitmapType.INSTANCE).args(TinyIntType.INSTANCE) + ); public BitmapAgg(Expression arg0) { super("bitmap_agg", arg0); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/CollectList.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/CollectList.java index 2aef07b4813bb8..470054aa894b5c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/CollectList.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/CollectList.java @@ -73,12 +73,6 @@ public CollectList(boolean distinct, Expression arg0, Expression arg1) { super("collect_list", distinct, arg0, arg1); } - @Override - public FunctionSignature computeSignature(FunctionSignature signature) { - signature = signature.withReturnType(ArrayType.of(getArgumentType(0))); - return super.computeSignature(signature); - } - /** * withDistinctAndChildren. */ diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Corr.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Corr.java index c8f54e2e88f9d4..9cf9c09464e1ff 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Corr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Corr.java @@ -41,12 +41,12 @@ public class Corr extends NullableAggregateFunction implements UnaryExpression, ExplicitlyCastableSignature { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(DoubleType.INSTANCE).args(TinyIntType.INSTANCE, TinyIntType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(SmallIntType.INSTANCE, SmallIntType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(IntegerType.INSTANCE, IntegerType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE, DoubleType.INSTANCE), FunctionSignature.ret(DoubleType.INSTANCE).args(BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(FloatType.INSTANCE, FloatType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE, DoubleType.INSTANCE) + FunctionSignature.ret(DoubleType.INSTANCE).args(IntegerType.INSTANCE, IntegerType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(SmallIntType.INSTANCE, SmallIntType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(TinyIntType.INSTANCE, TinyIntType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(FloatType.INSTANCE, FloatType.INSTANCE) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Covar.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Covar.java index 53cb4f579a1ec7..6d7707dc31f66c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Covar.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Covar.java @@ -41,12 +41,12 @@ public class Covar extends NullableAggregateFunction implements UnaryExpression, ExplicitlyCastableSignature { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(DoubleType.INSTANCE).args(TinyIntType.INSTANCE, TinyIntType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(SmallIntType.INSTANCE, SmallIntType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(IntegerType.INSTANCE, IntegerType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE, DoubleType.INSTANCE), FunctionSignature.ret(DoubleType.INSTANCE).args(BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(FloatType.INSTANCE, FloatType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE, DoubleType.INSTANCE) + FunctionSignature.ret(DoubleType.INSTANCE).args(IntegerType.INSTANCE, IntegerType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(SmallIntType.INSTANCE, SmallIntType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(TinyIntType.INSTANCE, TinyIntType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(FloatType.INSTANCE, FloatType.INSTANCE) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/CovarSamp.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/CovarSamp.java index 9dbf4c20b5021a..a520064e00b9b0 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/CovarSamp.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/CovarSamp.java @@ -41,12 +41,12 @@ public class CovarSamp extends NullableAggregateFunction implements UnaryExpression, ExplicitlyCastableSignature { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(DoubleType.INSTANCE).args(TinyIntType.INSTANCE, TinyIntType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(SmallIntType.INSTANCE, SmallIntType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(IntegerType.INSTANCE, IntegerType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE, DoubleType.INSTANCE), FunctionSignature.ret(DoubleType.INSTANCE).args(BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(FloatType.INSTANCE, FloatType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE, DoubleType.INSTANCE) + FunctionSignature.ret(DoubleType.INSTANCE).args(IntegerType.INSTANCE, IntegerType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(SmallIntType.INSTANCE, SmallIntType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(TinyIntType.INSTANCE, TinyIntType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(FloatType.INSTANCE, FloatType.INSTANCE) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/GroupBitAnd.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/GroupBitAnd.java index c0b420f03b791d..eece53f2a581e6 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/GroupBitAnd.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/GroupBitAnd.java @@ -40,11 +40,11 @@ public class GroupBitAnd extends NullableAggregateFunction implements UnaryExpression, ExplicitlyCastableSignature { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(TinyIntType.INSTANCE).args(TinyIntType.INSTANCE), - FunctionSignature.ret(SmallIntType.INSTANCE).args(SmallIntType.INSTANCE), - FunctionSignature.ret(IntegerType.INSTANCE).args(IntegerType.INSTANCE), + FunctionSignature.ret(LargeIntType.INSTANCE).args(LargeIntType.INSTANCE), FunctionSignature.ret(BigIntType.INSTANCE).args(BigIntType.INSTANCE), - FunctionSignature.ret(LargeIntType.INSTANCE).args(LargeIntType.INSTANCE) + FunctionSignature.ret(IntegerType.INSTANCE).args(IntegerType.INSTANCE), + FunctionSignature.ret(SmallIntType.INSTANCE).args(SmallIntType.INSTANCE), + FunctionSignature.ret(TinyIntType.INSTANCE).args(TinyIntType.INSTANCE) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/GroupBitOr.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/GroupBitOr.java index 4f9ef1669cd413..35ba1597259d9c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/GroupBitOr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/GroupBitOr.java @@ -41,11 +41,11 @@ public class GroupBitOr extends NullableAggregateFunction implements UnaryExpression, ExplicitlyCastableSignature { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(TinyIntType.INSTANCE).args(TinyIntType.INSTANCE), - FunctionSignature.ret(SmallIntType.INSTANCE).args(SmallIntType.INSTANCE), - FunctionSignature.ret(IntegerType.INSTANCE).args(IntegerType.INSTANCE), + FunctionSignature.ret(LargeIntType.INSTANCE).args(LargeIntType.INSTANCE), FunctionSignature.ret(BigIntType.INSTANCE).args(BigIntType.INSTANCE), - FunctionSignature.ret(LargeIntType.INSTANCE).args(LargeIntType.INSTANCE) + FunctionSignature.ret(IntegerType.INSTANCE).args(IntegerType.INSTANCE), + FunctionSignature.ret(SmallIntType.INSTANCE).args(SmallIntType.INSTANCE), + FunctionSignature.ret(TinyIntType.INSTANCE).args(TinyIntType.INSTANCE) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/GroupBitXor.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/GroupBitXor.java index 477ec2ee97aa4a..58953524f28d27 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/GroupBitXor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/GroupBitXor.java @@ -41,11 +41,11 @@ public class GroupBitXor extends NullableAggregateFunction implements UnaryExpression, ExplicitlyCastableSignature { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(TinyIntType.INSTANCE).args(TinyIntType.INSTANCE), - FunctionSignature.ret(SmallIntType.INSTANCE).args(SmallIntType.INSTANCE), - FunctionSignature.ret(IntegerType.INSTANCE).args(IntegerType.INSTANCE), + FunctionSignature.ret(LargeIntType.INSTANCE).args(LargeIntType.INSTANCE), FunctionSignature.ret(BigIntType.INSTANCE).args(BigIntType.INSTANCE), - FunctionSignature.ret(LargeIntType.INSTANCE).args(LargeIntType.INSTANCE) + FunctionSignature.ret(IntegerType.INSTANCE).args(IntegerType.INSTANCE), + FunctionSignature.ret(SmallIntType.INSTANCE).args(SmallIntType.INSTANCE), + FunctionSignature.ret(TinyIntType.INSTANCE).args(TinyIntType.INSTANCE) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum.java index 538734eb1393f2..851b70e66b9ff4 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum.java @@ -24,12 +24,9 @@ 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.BigIntType; -import org.apache.doris.nereids.types.DoubleType; -import org.apache.doris.nereids.types.LargeIntType; +import org.apache.doris.nereids.types.DataType; import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; import java.util.List; @@ -37,12 +34,6 @@ public class MultiDistinctSum extends NullableAggregateFunction implements UnaryExpression, ExplicitlyCastableSignature, ComputePrecisionForSum, MultiDistinction { - public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(BigIntType.INSTANCE).varArgs(BigIntType.INSTANCE), - FunctionSignature.ret(BigIntType.INSTANCE).varArgs(DoubleType.INSTANCE), - FunctionSignature.ret(BigIntType.INSTANCE).varArgs(LargeIntType.INSTANCE) - ); - private final boolean mustUseMultiDistinctAgg; public MultiDistinctSum(Expression arg0) { @@ -65,8 +56,10 @@ private MultiDistinctSum(boolean mustUseMultiDistinctAgg, boolean distinct, @Override public void checkLegalityBeforeTypeCoercion() { - if (child().getDataType().isDateLikeType()) { - throw new AnalysisException("Sum in multi distinct functions do not support Date/Datetime type"); + DataType argType = child().getDataType(); + if ((!argType.isNumericType() && !argType.isBooleanType() && !argType.isNullType()) + || argType.isOnlyMetricType()) { + throw new AnalysisException("sum requires a numeric or boolean parameter: " + this.toSql()); } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum0.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum0.java index 37ecd8f2a3dcd9..628e18e4772ae9 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum0.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum0.java @@ -25,12 +25,9 @@ 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.BigIntType; -import org.apache.doris.nereids.types.DoubleType; -import org.apache.doris.nereids.types.LargeIntType; +import org.apache.doris.nereids.types.DataType; import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; import java.util.List; @@ -38,12 +35,6 @@ public class MultiDistinctSum0 extends AggregateFunction implements UnaryExpression, ExplicitlyCastableSignature, ComputePrecisionForSum, MultiDistinction, AlwaysNotNullable { - public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(BigIntType.INSTANCE).varArgs(BigIntType.INSTANCE), - FunctionSignature.ret(BigIntType.INSTANCE).varArgs(DoubleType.INSTANCE), - FunctionSignature.ret(BigIntType.INSTANCE).varArgs(LargeIntType.INSTANCE) - ); - private final boolean mustUseMultiDistinctAgg; public MultiDistinctSum0(Expression arg0) { @@ -61,8 +52,10 @@ private MultiDistinctSum0(boolean mustUseMultiDistinctAgg, boolean distinct, Exp @Override public void checkLegalityBeforeTypeCoercion() { - if (child().getDataType().isDateLikeType()) { - throw new AnalysisException("Sum0 in multi distinct functions do not support Date/Datetime type"); + DataType argType = child().getDataType(); + if ((!argType.isNumericType() && !argType.isBooleanType() && !argType.isNullType()) + || argType.isOnlyMetricType()) { + throw new AnalysisException("sum0 requires a numeric or boolean parameter: " + this.toSql()); } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Stddev.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Stddev.java index 1f732421940f16..855457acfbae24 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Stddev.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Stddev.java @@ -44,10 +44,10 @@ public class Stddev extends NullableAggregateFunction public static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(TinyIntType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(SmallIntType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(IntegerType.INSTANCE), FunctionSignature.ret(DoubleType.INSTANCE).args(BigIntType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(IntegerType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(SmallIntType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(TinyIntType.INSTANCE), FunctionSignature.ret(DoubleType.INSTANCE).args(FloatType.INSTANCE)); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/StddevSamp.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/StddevSamp.java index 42e909ed0ce8fa..7faa14554de750 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/StddevSamp.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/StddevSamp.java @@ -44,10 +44,10 @@ public class StddevSamp extends NullableAggregateFunction public static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(TinyIntType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(SmallIntType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(IntegerType.INSTANCE), FunctionSignature.ret(DoubleType.INSTANCE).args(BigIntType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(IntegerType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(SmallIntType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(TinyIntType.INSTANCE), FunctionSignature.ret(DoubleType.INSTANCE).args(FloatType.INSTANCE)); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/TopNWeighted.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/TopNWeighted.java index 40ab65ff4b4c79..d073bf193ee6c6 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/TopNWeighted.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/TopNWeighted.java @@ -51,24 +51,25 @@ public class TopNWeighted extends NullableAggregateFunction implements ExplicitlyCastableSignature { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(ArrayType.of(BooleanType.INSTANCE)) - .args(BooleanType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(TinyIntType.INSTANCE)) - .args(TinyIntType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(SmallIntType.INSTANCE)) - .args(SmallIntType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE)) - .args(IntegerType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)) - .args(BigIntType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(LargeIntType.INSTANCE)) - .args(LargeIntType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(FloatType.INSTANCE)) - .args(FloatType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE), + // three arguments FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)) .args(DoubleType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE), FunctionSignature.ret(ArrayType.of(DecimalV2Type.CATALOG_DEFAULT)) .args(DecimalV2Type.CATALOG_DEFAULT, BigIntType.INSTANCE, IntegerType.INSTANCE), + FunctionSignature.ret(ArrayType.of(LargeIntType.INSTANCE)) + .args(LargeIntType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE), + FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)) + .args(BigIntType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE), + FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE)) + .args(IntegerType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE), + FunctionSignature.ret(ArrayType.of(SmallIntType.INSTANCE)) + .args(SmallIntType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE), + FunctionSignature.ret(ArrayType.of(TinyIntType.INSTANCE)) + .args(TinyIntType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE), + FunctionSignature.ret(ArrayType.of(BooleanType.INSTANCE)) + .args(BooleanType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE), + FunctionSignature.ret(ArrayType.of(FloatType.INSTANCE)) + .args(FloatType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE), FunctionSignature.ret(ArrayType.of(DateType.INSTANCE)) .args(DateType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE), FunctionSignature.ret(ArrayType.of(DateTimeType.INSTANCE)) @@ -77,24 +78,14 @@ public class TopNWeighted extends NullableAggregateFunction .args(DateV2Type.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE), FunctionSignature.ret(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)) .args(DateTimeV2Type.SYSTEM_DEFAULT, BigIntType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(CharType.SYSTEM_DEFAULT)) - .args(CharType.SYSTEM_DEFAULT, BigIntType.INSTANCE, IntegerType.INSTANCE), FunctionSignature.ret(ArrayType.of(StringType.INSTANCE)) .args(StringType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(BooleanType.INSTANCE)) - .args(BooleanType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(TinyIntType.INSTANCE)) - .args(TinyIntType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(SmallIntType.INSTANCE)) - .args(SmallIntType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE)) - .args(IntegerType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)) - .args(BigIntType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(LargeIntType.INSTANCE)) - .args(LargeIntType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(FloatType.INSTANCE)) - .args(FloatType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), + FunctionSignature.ret(ArrayType.of(VarcharType.SYSTEM_DEFAULT)) + .args(VarcharType.SYSTEM_DEFAULT, BigIntType.INSTANCE, IntegerType.INSTANCE), + FunctionSignature.ret(ArrayType.of(CharType.SYSTEM_DEFAULT)) + .args(CharType.SYSTEM_DEFAULT, BigIntType.INSTANCE, IntegerType.INSTANCE), + + // four arguments FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)) .args(DoubleType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT) @@ -102,6 +93,20 @@ public class TopNWeighted extends NullableAggregateFunction BigIntType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), + FunctionSignature.ret(ArrayType.of(LargeIntType.INSTANCE)) + .args(LargeIntType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), + FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)) + .args(BigIntType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), + FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE)) + .args(IntegerType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), + FunctionSignature.ret(ArrayType.of(SmallIntType.INSTANCE)) + .args(SmallIntType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), + FunctionSignature.ret(ArrayType.of(TinyIntType.INSTANCE)) + .args(TinyIntType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), + FunctionSignature.ret(ArrayType.of(BooleanType.INSTANCE)) + .args(BooleanType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), + FunctionSignature.ret(ArrayType.of(FloatType.INSTANCE)) + .args(FloatType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), FunctionSignature.ret(ArrayType.of(DateType.INSTANCE)) .args(DateType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), FunctionSignature.ret(ArrayType.of(DateTimeType.INSTANCE)) @@ -113,10 +118,12 @@ public class TopNWeighted extends NullableAggregateFunction BigIntType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(CharType.SYSTEM_DEFAULT)) - .args(CharType.SYSTEM_DEFAULT, BigIntType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), FunctionSignature.ret(ArrayType.of(StringType.INSTANCE)) - .args(StringType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE) + .args(StringType.INSTANCE, BigIntType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), + FunctionSignature.ret(ArrayType.of(VarcharType.SYSTEM_DEFAULT)) + .args(VarcharType.SYSTEM_DEFAULT, BigIntType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), + FunctionSignature.ret(ArrayType.of(CharType.SYSTEM_DEFAULT)) + .args(CharType.SYSTEM_DEFAULT, BigIntType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Variance.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Variance.java index f56bfa6f6b69ce..1b707e52d7b149 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Variance.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Variance.java @@ -44,10 +44,10 @@ public class Variance extends NullableAggregateFunction public static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(TinyIntType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(SmallIntType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(IntegerType.INSTANCE), FunctionSignature.ret(DoubleType.INSTANCE).args(BigIntType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(IntegerType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(SmallIntType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(TinyIntType.INSTANCE), FunctionSignature.ret(DoubleType.INSTANCE).args(FloatType.INSTANCE)); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/VarianceSamp.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/VarianceSamp.java index f7e234c634cd10..3bfc5fe283649a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/VarianceSamp.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/VarianceSamp.java @@ -43,10 +43,10 @@ public class VarianceSamp extends NullableAggregateFunction public static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(TinyIntType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(SmallIntType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(IntegerType.INSTANCE), FunctionSignature.ret(DoubleType.INSTANCE).args(BigIntType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(IntegerType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(SmallIntType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(TinyIntType.INSTANCE), FunctionSignature.ret(DoubleType.INSTANCE).args(FloatType.INSTANCE)); /** diff --git a/regression-test/data/nereids_function_p0/type_coercion.out b/regression-test/data/nereids_function_p0/type_coercion.out index b600040e8f6dc6..49a1fb6167599a 100644 --- a/regression-test/data/nereids_function_p0/type_coercion.out +++ b/regression-test/data/nereids_function_p0/type_coercion.out @@ -35,3 +35,30 @@ -- !nullif -- 13 +-- !topn_weighted -- +\N + +-- !corr -- +-0.502861022996899 + +-- !covar -- +-4.790355708888889E8 + +-- !covar_samp -- +-7.185533563333334E8 + +-- !group_bit_and -- +0 + +-- !group_bit_or -- +65679 + +-- !group_bit_xor -- +65671 + +-- !stddev -- +30866.899145992767 + +-- !stddev_samp -- +37804.07642481606 + diff --git a/regression-test/suites/nereids_function_p0/type_coercion.groovy b/regression-test/suites/nereids_function_p0/type_coercion.groovy index 57b63030adb48e..30c943b9a08d1f 100644 --- a/regression-test/suites/nereids_function_p0/type_coercion.groovy +++ b/regression-test/suites/nereids_function_p0/type_coercion.groovy @@ -16,6 +16,8 @@ // under the License. suite("function_type_coercion") { sql """set enable_fold_constant_by_be=false""" // remove this if array BE return result be fixed. + + // scalar function qt_greatest """select greatest(1, 2222, '333')""" qt_least """select least(5,2000000,'3.0023')""" qt_if """select if (1, 2222, 33)""" @@ -28,4 +30,30 @@ suite("function_type_coercion") { qt_array_cum_sum """select array_cum_sum(array('1', '2', '3000'))""" qt_pmod """select pmod(2, '1.0')""" qt_nullif """SELECT nullif(13, -4851)""" + + // agg function + sql """drop table if exists test_agg_signature""" + + sql """ + create table test_agg_signature ( + id int, + c1 text, + c2 text + ) + properties ( + "replication_num" = "1" + ) + """ + + sql """insert into test_agg_signature values (1, "10", "65537"), (2, "129", "134"), (3, "65548", "3")""" + + qt_topn_weighted """select topn_weighted(12345678.12345678900000000000000000000, null, 2147483648)""" + qt_corr """select corr(c1, c2) from test_agg_signature""" + qt_covar """select covar(c1, c2) from test_agg_signature""" + qt_covar_samp """select covar_samp(c1, c2) from test_agg_signature""" + qt_group_bit_and """select group_bit_and(c1) from test_agg_signature""" + qt_group_bit_or """select group_bit_or(c1) from test_agg_signature""" + qt_group_bit_xor """select group_bit_xor(c1) from test_agg_signature""" + qt_stddev """select stddev(c1) from test_agg_signature""" + qt_stddev_samp """select stddev_samp(c1) from test_agg_signature""" }