This is an automated email from the ASF dual-hosted git repository. morrysnow pushed a commit to branch 2.1_39352 in repository https://gitbox.apache.org/repos/asf/doris.git
commit 0e696c7aec8bb8ab8a9fb6eec21d74e91d44dfba Author: morrySnow <[email protected]> AuthorDate: Thu Aug 15 20:44:53 2024 +0800 [opt](Nereids) polish aggregate function signature matching (#39352) pick from master #39352 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 --- .../expressions/functions/agg/AvgWeighted.java | 10 +-- .../trees/expressions/functions/agg/BitmapAgg.java | 8 +-- .../expressions/functions/agg/CollectList.java | 6 -- .../trees/expressions/functions/agg/Corr.java | 10 +-- .../trees/expressions/functions/agg/Covar.java | 10 +-- .../trees/expressions/functions/agg/CovarSamp.java | 10 +-- .../expressions/functions/agg/GroupBitAnd.java | 8 +-- .../expressions/functions/agg/GroupBitOr.java | 8 +-- .../expressions/functions/agg/GroupBitXor.java | 8 +-- .../functions/agg/MultiDistinctSum.java | 17 ++--- .../functions/agg/MultiDistinctSum0.java | 17 ++--- .../trees/expressions/functions/agg/Stddev.java | 6 +- .../expressions/functions/agg/StddevSamp.java | 6 +- .../expressions/functions/agg/TopNWeighted.java | 73 ++++++++++++---------- .../trees/expressions/functions/agg/Variance.java | 6 +- .../expressions/functions/agg/VarianceSamp.java | 6 +- .../data/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 e2054878d9c..c2a79257c3b 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 @@ -44,12 +44,12 @@ public class AvgWeighted extends AggregateFunction public static final List<FunctionSignature> 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 5b348b07318..1d32910e1a9 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 @@ import java.util.List; 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(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 2aef07b4813..470054aa894 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 class CollectList extends AggregateFunction 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 b88b54d1378..6cdbeaf913a 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 @@ -42,12 +42,12 @@ public class Corr extends AggregateFunction implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullable { public static final List<FunctionSignature> 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 12096f547c8..2bebde3b4ed 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 @@ -42,12 +42,12 @@ public class Covar extends AggregateFunction implements UnaryExpression, ExplicitlyCastableSignature, AlwaysNullable { public static final List<FunctionSignature> 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 310ce2ca211..2693d7636f0 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 @@ -42,12 +42,12 @@ public class CovarSamp extends AggregateFunction implements UnaryExpression, ExplicitlyCastableSignature, AlwaysNullable { public static final List<FunctionSignature> 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 c0b420f03b7..eece53f2a58 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<FunctionSignature> 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 4f9ef1669cd..35ba1597259 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<FunctionSignature> 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 477ec2ee97a..58953524f28 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<FunctionSignature> 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 538734eb139..851b70e66b9 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.ComputePrecisionForS 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 @@ import java.util.List; public class MultiDistinctSum extends NullableAggregateFunction implements UnaryExpression, ExplicitlyCastableSignature, ComputePrecisionForSum, MultiDistinction { - public static final List<FunctionSignature> 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 @@ public class MultiDistinctSum extends NullableAggregateFunction implements Unary @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 37ecd8f2a3d..628e18e4772 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.ComputePrecisionForS 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 @@ import java.util.List; public class MultiDistinctSum0 extends AggregateFunction implements UnaryExpression, ExplicitlyCastableSignature, ComputePrecisionForSum, MultiDistinction, AlwaysNotNullable { - public static final List<FunctionSignature> 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 @@ public class MultiDistinctSum0 extends AggregateFunction implements UnaryExpress @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 1f732421940..855457acfba 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<FunctionSignature> 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 b64a4e425b1..9ba4c8f5317 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 @@ -45,10 +45,10 @@ public class StddevSamp extends AggregateFunction public static final List<FunctionSignature> 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 c9e28f57753..d3f6efef996 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 @@ -52,24 +52,25 @@ public class TopNWeighted extends AggregateFunction implements ExplicitlyCastableSignature, PropagateNullable { public static final List<FunctionSignature> 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)) @@ -78,24 +79,14 @@ public class TopNWeighted extends AggregateFunction .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) @@ -103,6 +94,20 @@ public class TopNWeighted extends AggregateFunction 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)) @@ -114,10 +119,12 @@ public class TopNWeighted extends AggregateFunction 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 f56bfa6f6b6..1b707e52d7b 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<FunctionSignature> 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 637646ed856..c971756d261 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 @@ -44,10 +44,10 @@ public class VarianceSamp extends AggregateFunction public static final List<FunctionSignature> 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 b600040e8f6..49a1fb61675 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 57b63030adb..30c943b9a08 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<double> 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""" } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
