Skip to content

Commit a5de741

Browse files
committed
[opt](Nereids) polish aggregate function signature matching (apache#39352)
pick from master apache#39352 use double to match string - stddev - stddev_samp use largeint to match string - group_bit_and - group_bit_or - group_git_xor optimize error message - multi_distinct_sum
1 parent f0da2ff commit a5de741

File tree

15 files changed

+120
-87
lines changed

15 files changed

+120
-87
lines changed

fe/fe-core/src/main/java/org/apache/doris/analysis/BinaryPredicate.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -760,13 +760,13 @@ private Expr compareLiteral(LiteralExpr first, LiteralExpr second) throws Analys
760760
case EQ_FOR_NULL:
761761
return new BoolLiteral(compareResult == 0);
762762
case GE:
763-
return new BoolLiteral(compareResult == 1 || compareResult == 0);
763+
return new BoolLiteral(compareResult >= 0);
764764
case GT:
765-
return new BoolLiteral(compareResult == 1);
765+
return new BoolLiteral(compareResult > 0);
766766
case LE:
767767
return new BoolLiteral(compareResult == -1 || compareResult == 0);
768768
case LT:
769-
return new BoolLiteral(compareResult == -1);
769+
return new BoolLiteral(compareResult < 0);
770770
case NE:
771771
return new BoolLiteral(compareResult != 0);
772772
default:

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/AvgWeighted.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ public class AvgWeighted extends AggregateFunction
4444

4545
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
4646
FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE, DoubleType.INSTANCE),
47-
FunctionSignature.ret(DoubleType.INSTANCE).args(TinyIntType.INSTANCE, DoubleType.INSTANCE),
48-
FunctionSignature.ret(DoubleType.INSTANCE).args(SmallIntType.INSTANCE, DoubleType.INSTANCE),
49-
FunctionSignature.ret(DoubleType.INSTANCE).args(IntegerType.INSTANCE, DoubleType.INSTANCE),
47+
FunctionSignature.ret(DoubleType.INSTANCE).args(DecimalV2Type.SYSTEM_DEFAULT, DoubleType.INSTANCE),
5048
FunctionSignature.ret(DoubleType.INSTANCE).args(BigIntType.INSTANCE, DoubleType.INSTANCE),
51-
FunctionSignature.ret(DoubleType.INSTANCE).args(FloatType.INSTANCE, DoubleType.INSTANCE),
52-
FunctionSignature.ret(DoubleType.INSTANCE).args(DecimalV2Type.SYSTEM_DEFAULT, DoubleType.INSTANCE)
49+
FunctionSignature.ret(DoubleType.INSTANCE).args(IntegerType.INSTANCE, DoubleType.INSTANCE),
50+
FunctionSignature.ret(DoubleType.INSTANCE).args(SmallIntType.INSTANCE, DoubleType.INSTANCE),
51+
FunctionSignature.ret(DoubleType.INSTANCE).args(TinyIntType.INSTANCE, DoubleType.INSTANCE),
52+
FunctionSignature.ret(DoubleType.INSTANCE).args(FloatType.INSTANCE, DoubleType.INSTANCE)
5353
);
5454

5555
/**

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/BitmapAgg.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@
3939
public class BitmapAgg extends AggregateFunction
4040
implements UnaryExpression, ExplicitlyCastableSignature, AlwaysNotNullable {
4141
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
42-
FunctionSignature.ret(BitmapType.INSTANCE).args(TinyIntType.INSTANCE),
43-
FunctionSignature.ret(BitmapType.INSTANCE).args(SmallIntType.INSTANCE),
42+
FunctionSignature.ret(BitmapType.INSTANCE).args(BigIntType.INSTANCE),
4443
FunctionSignature.ret(BitmapType.INSTANCE).args(IntegerType.INSTANCE),
45-
FunctionSignature.ret(BitmapType.INSTANCE).args(BigIntType.INSTANCE)
46-
);
44+
FunctionSignature.ret(BitmapType.INSTANCE).args(SmallIntType.INSTANCE),
45+
FunctionSignature.ret(BitmapType.INSTANCE).args(TinyIntType.INSTANCE)
46+
);
4747

4848
public BitmapAgg(Expression arg0) {
4949
super("bitmap_agg", arg0);

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/CollectList.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,6 @@ public CollectList(boolean distinct, Expression arg) {
8383
super("collect_list", distinct, arg);
8484
}
8585

86-
@Override
87-
public FunctionSignature computeSignature(FunctionSignature signature) {
88-
signature = signature.withReturnType(ArrayType.of(getArgumentType(0)));
89-
return super.computeSignature(signature);
90-
}
91-
9286
/**
9387
* withDistinctAndChildren.
9488
*/

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/GroupBitAnd.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ public class GroupBitAnd extends NullableAggregateFunction
4040
implements UnaryExpression, ExplicitlyCastableSignature {
4141

4242
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
43-
FunctionSignature.ret(TinyIntType.INSTANCE).args(TinyIntType.INSTANCE),
44-
FunctionSignature.ret(SmallIntType.INSTANCE).args(SmallIntType.INSTANCE),
45-
FunctionSignature.ret(IntegerType.INSTANCE).args(IntegerType.INSTANCE),
43+
FunctionSignature.ret(LargeIntType.INSTANCE).args(LargeIntType.INSTANCE),
4644
FunctionSignature.ret(BigIntType.INSTANCE).args(BigIntType.INSTANCE),
47-
FunctionSignature.ret(LargeIntType.INSTANCE).args(LargeIntType.INSTANCE)
45+
FunctionSignature.ret(IntegerType.INSTANCE).args(IntegerType.INSTANCE),
46+
FunctionSignature.ret(SmallIntType.INSTANCE).args(SmallIntType.INSTANCE),
47+
FunctionSignature.ret(TinyIntType.INSTANCE).args(TinyIntType.INSTANCE)
4848
);
4949

5050
/**

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/GroupBitOr.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ public class GroupBitOr extends NullableAggregateFunction
4141
implements UnaryExpression, ExplicitlyCastableSignature {
4242

4343
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
44-
FunctionSignature.ret(TinyIntType.INSTANCE).args(TinyIntType.INSTANCE),
45-
FunctionSignature.ret(SmallIntType.INSTANCE).args(SmallIntType.INSTANCE),
46-
FunctionSignature.ret(IntegerType.INSTANCE).args(IntegerType.INSTANCE),
44+
FunctionSignature.ret(LargeIntType.INSTANCE).args(LargeIntType.INSTANCE),
4745
FunctionSignature.ret(BigIntType.INSTANCE).args(BigIntType.INSTANCE),
48-
FunctionSignature.ret(LargeIntType.INSTANCE).args(LargeIntType.INSTANCE)
46+
FunctionSignature.ret(IntegerType.INSTANCE).args(IntegerType.INSTANCE),
47+
FunctionSignature.ret(SmallIntType.INSTANCE).args(SmallIntType.INSTANCE),
48+
FunctionSignature.ret(TinyIntType.INSTANCE).args(TinyIntType.INSTANCE)
4949
);
5050

5151
/**

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/GroupBitXor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ public class GroupBitXor extends NullableAggregateFunction
4141
implements UnaryExpression, ExplicitlyCastableSignature {
4242

4343
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
44-
FunctionSignature.ret(TinyIntType.INSTANCE).args(TinyIntType.INSTANCE),
45-
FunctionSignature.ret(SmallIntType.INSTANCE).args(SmallIntType.INSTANCE),
46-
FunctionSignature.ret(IntegerType.INSTANCE).args(IntegerType.INSTANCE),
44+
FunctionSignature.ret(LargeIntType.INSTANCE).args(LargeIntType.INSTANCE),
4745
FunctionSignature.ret(BigIntType.INSTANCE).args(BigIntType.INSTANCE),
48-
FunctionSignature.ret(LargeIntType.INSTANCE).args(LargeIntType.INSTANCE)
46+
FunctionSignature.ret(IntegerType.INSTANCE).args(IntegerType.INSTANCE),
47+
FunctionSignature.ret(SmallIntType.INSTANCE).args(SmallIntType.INSTANCE),
48+
FunctionSignature.ret(TinyIntType.INSTANCE).args(TinyIntType.INSTANCE)
4949
);
5050

5151
/**

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,16 @@
2424
import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
2525
import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression;
2626
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
27-
import org.apache.doris.nereids.types.BigIntType;
28-
import org.apache.doris.nereids.types.DoubleType;
29-
import org.apache.doris.nereids.types.LargeIntType;
27+
import org.apache.doris.nereids.types.DataType;
3028

3129
import com.google.common.base.Preconditions;
32-
import com.google.common.collect.ImmutableList;
3330

3431
import java.util.List;
3532

3633
/** MultiDistinctSum */
3734
public class MultiDistinctSum extends NullableAggregateFunction implements UnaryExpression,
3835
ExplicitlyCastableSignature, ComputePrecisionForSum, MultiDistinction {
3936

40-
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
41-
FunctionSignature.ret(BigIntType.INSTANCE).varArgs(BigIntType.INSTANCE),
42-
FunctionSignature.ret(BigIntType.INSTANCE).varArgs(DoubleType.INSTANCE),
43-
FunctionSignature.ret(BigIntType.INSTANCE).varArgs(LargeIntType.INSTANCE)
44-
);
45-
4637
public MultiDistinctSum(Expression arg0) {
4738
super("multi_distinct_sum", true, false, arg0);
4839
}
@@ -57,8 +48,10 @@ public MultiDistinctSum(boolean distinct, boolean alwaysNullable, Expression arg
5748

5849
@Override
5950
public void checkLegalityBeforeTypeCoercion() {
60-
if (child().getDataType().isDateLikeType()) {
61-
throw new AnalysisException("Sum in multi distinct functions do not support Date/Datetime type");
51+
DataType argType = child().getDataType();
52+
if ((!argType.isNumericType() && !argType.isBooleanType() && !argType.isNullType())
53+
|| argType.isOnlyMetricType()) {
54+
throw new AnalysisException("sum requires a numeric or boolean parameter: " + this.toSql());
6255
}
6356
}
6457

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Stddev.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ public class Stddev extends NullableAggregateFunction
4545

4646
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
4747
FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE),
48-
FunctionSignature.ret(DoubleType.INSTANCE).args(TinyIntType.INSTANCE),
49-
FunctionSignature.ret(DoubleType.INSTANCE).args(SmallIntType.INSTANCE),
50-
FunctionSignature.ret(DoubleType.INSTANCE).args(IntegerType.INSTANCE),
5148
FunctionSignature.ret(DoubleType.INSTANCE).args(BigIntType.INSTANCE),
49+
FunctionSignature.ret(DoubleType.INSTANCE).args(IntegerType.INSTANCE),
50+
FunctionSignature.ret(DoubleType.INSTANCE).args(SmallIntType.INSTANCE),
51+
FunctionSignature.ret(DoubleType.INSTANCE).args(TinyIntType.INSTANCE),
5252
FunctionSignature.ret(DoubleType.INSTANCE).args(FloatType.INSTANCE),
5353
FunctionSignature.ret(DecimalV2Type.SYSTEM_DEFAULT).args(DecimalV2Type.SYSTEM_DEFAULT)
5454
);

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/StddevSamp.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ public class StddevSamp extends AggregateFunction
4646

4747
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
4848
FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE),
49-
FunctionSignature.ret(DoubleType.INSTANCE).args(TinyIntType.INSTANCE),
50-
FunctionSignature.ret(DoubleType.INSTANCE).args(SmallIntType.INSTANCE),
51-
FunctionSignature.ret(DoubleType.INSTANCE).args(IntegerType.INSTANCE),
5249
FunctionSignature.ret(DoubleType.INSTANCE).args(BigIntType.INSTANCE),
50+
FunctionSignature.ret(DoubleType.INSTANCE).args(IntegerType.INSTANCE),
51+
FunctionSignature.ret(DoubleType.INSTANCE).args(SmallIntType.INSTANCE),
52+
FunctionSignature.ret(DoubleType.INSTANCE).args(TinyIntType.INSTANCE),
5353
FunctionSignature.ret(DoubleType.INSTANCE).args(FloatType.INSTANCE),
5454
FunctionSignature.ret(DecimalV2Type.SYSTEM_DEFAULT).args(DecimalV2Type.SYSTEM_DEFAULT)
5555
);

0 commit comments

Comments
 (0)