This is an automated email from the ASF dual-hosted git repository.
morrysnow pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new 0adf48a84b7 [fix](Nereids) polish function signature search algorithm
(#38497) (#39445)
0adf48a84b7 is described below
commit 0adf48a84b7bece5fbcef73bb223a2617a871633
Author: morrySnow <[email protected]>
AuthorDate: Fri Aug 16 10:54:55 2024 +0800
[fix](Nereids) polish function signature search algorithm (#38497) (#39445)
pick from master #38497 and #39342
use double first
- fmod
- pmod
let return type same as parameter's type
- if
let greatest / least work same as mysql's greatest
---
.../functions/scalar/BitmapFromArray.java | 6 +--
.../expressions/functions/scalar/Coalesce.java | 6 +--
.../trees/expressions/functions/scalar/Fmod.java | 4 +-
.../expressions/functions/scalar/Greatest.java | 47 +++++++++++++------
.../trees/expressions/functions/scalar/If.java | 54 ++--------------------
.../expressions/functions/scalar/LastDay.java | 6 +--
.../trees/expressions/functions/scalar/Least.java | 47 +++++++++++++------
.../expressions/functions/scalar/MinutesDiff.java | 2 +-
.../trees/expressions/functions/scalar/Pmod.java | 42 +++++++++++++++--
.../doris/nereids/util/TypeCoercionUtils.java | 32 ++++++++++++-
.../data/nereids_function_p0/type_coercion.out | 37 +++++++++++++++
.../nereids_function_p0/type_coercion.groovy | 24 ++++++++++
12 files changed, 212 insertions(+), 95 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/BitmapFromArray.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/BitmapFromArray.java
index 00f950d589b..8304e0684a5 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/BitmapFromArray.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/BitmapFromArray.java
@@ -42,10 +42,10 @@ public class BitmapFromArray extends ScalarFunction
implements UnaryExpression, ExplicitlyCastableSignature,
AlwaysNullable {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
-
FunctionSignature.ret(BitmapType.INSTANCE).args(ArrayType.of(TinyIntType.INSTANCE)),
-
FunctionSignature.ret(BitmapType.INSTANCE).args(ArrayType.of(SmallIntType.INSTANCE)),
+
FunctionSignature.ret(BitmapType.INSTANCE).args(ArrayType.of(BigIntType.INSTANCE)),
FunctionSignature.ret(BitmapType.INSTANCE).args(ArrayType.of(IntegerType.INSTANCE)),
-
FunctionSignature.ret(BitmapType.INSTANCE).args(ArrayType.of(BigIntType.INSTANCE))
+
FunctionSignature.ret(BitmapType.INSTANCE).args(ArrayType.of(SmallIntType.INSTANCE)),
+
FunctionSignature.ret(BitmapType.INSTANCE).args(ArrayType.of(TinyIntType.INSTANCE))
);
/**
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Coalesce.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Coalesce.java
index 7dca8a7f2ea..f1d122d0179 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Coalesce.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Coalesce.java
@@ -58,12 +58,12 @@ public class Coalesce extends ScalarFunction
FunctionSignature.ret(IntegerType.INSTANCE).varArgs(IntegerType.INSTANCE),
FunctionSignature.ret(BigIntType.INSTANCE).varArgs(BigIntType.INSTANCE),
FunctionSignature.ret(LargeIntType.INSTANCE).varArgs(LargeIntType.INSTANCE),
-
FunctionSignature.ret(FloatType.INSTANCE).varArgs(FloatType.INSTANCE),
FunctionSignature.ret(DoubleType.INSTANCE).varArgs(DoubleType.INSTANCE),
-
FunctionSignature.ret(DateTimeType.INSTANCE).varArgs(DateTimeType.INSTANCE),
-
FunctionSignature.ret(DateType.INSTANCE).varArgs(DateType.INSTANCE),
+
FunctionSignature.ret(FloatType.INSTANCE).varArgs(FloatType.INSTANCE),
FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).varArgs(DateTimeV2Type.SYSTEM_DEFAULT),
+
FunctionSignature.ret(DateTimeType.INSTANCE).varArgs(DateTimeType.INSTANCE),
FunctionSignature.ret(DateV2Type.INSTANCE).varArgs(DateV2Type.INSTANCE),
+
FunctionSignature.ret(DateType.INSTANCE).varArgs(DateType.INSTANCE),
FunctionSignature.ret(DecimalV3Type.WILDCARD).varArgs(DecimalV3Type.WILDCARD),
FunctionSignature.ret(DecimalV2Type.SYSTEM_DEFAULT).varArgs(DecimalV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(BitmapType.INSTANCE).varArgs(BitmapType.INSTANCE),
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Fmod.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Fmod.java
index 5173903147e..08ee2af55f8 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Fmod.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Fmod.java
@@ -38,8 +38,8 @@ public class Fmod extends ScalarFunction
implements BinaryExpression, ExplicitlyCastableSignature,
AlwaysNullable {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
- FunctionSignature.ret(FloatType.INSTANCE).args(FloatType.INSTANCE,
FloatType.INSTANCE),
-
FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE,
DoubleType.INSTANCE)
+
FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE,
DoubleType.INSTANCE),
+ FunctionSignature.ret(FloatType.INSTANCE).args(FloatType.INSTANCE,
FloatType.INSTANCE)
);
/**
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Greatest.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Greatest.java
index 0cb415c287e..92028076701 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Greatest.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Greatest.java
@@ -23,6 +23,7 @@ import
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSi
import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.BigIntType;
+import org.apache.doris.nereids.types.DataType;
import org.apache.doris.nereids.types.DateTimeType;
import org.apache.doris.nereids.types.DateTimeV2Type;
import org.apache.doris.nereids.types.DateType;
@@ -37,6 +38,7 @@ import org.apache.doris.nereids.types.SmallIntType;
import org.apache.doris.nereids.types.StringType;
import org.apache.doris.nereids.types.TinyIntType;
import org.apache.doris.nereids.types.VarcharType;
+import org.apache.doris.nereids.types.coercion.CharacterType;
import org.apache.doris.nereids.util.ExpressionUtils;
import com.google.common.base.Preconditions;
@@ -51,21 +53,21 @@ public class Greatest extends ScalarFunction
implements ExplicitlyCastableSignature, PropagateNullable {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
-
FunctionSignature.ret(TinyIntType.INSTANCE).varArgs(TinyIntType.INSTANCE),
-
FunctionSignature.ret(SmallIntType.INSTANCE).varArgs(SmallIntType.INSTANCE),
-
FunctionSignature.ret(IntegerType.INSTANCE).varArgs(IntegerType.INSTANCE),
-
FunctionSignature.ret(BigIntType.INSTANCE).varArgs(BigIntType.INSTANCE),
-
FunctionSignature.ret(LargeIntType.INSTANCE).varArgs(LargeIntType.INSTANCE),
-
FunctionSignature.ret(FloatType.INSTANCE).varArgs(FloatType.INSTANCE),
+
FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT).varArgs(VarcharType.SYSTEM_DEFAULT),
+
FunctionSignature.ret(StringType.INSTANCE).varArgs(StringType.INSTANCE),
+
FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).varArgs(DateTimeV2Type.SYSTEM_DEFAULT),
+
FunctionSignature.ret(DateTimeType.INSTANCE).varArgs(DateTimeType.INSTANCE),
+
FunctionSignature.ret(DateV2Type.INSTANCE).varArgs(DateV2Type.INSTANCE),
+
FunctionSignature.ret(DateType.INSTANCE).varArgs(DateType.INSTANCE),
FunctionSignature.ret(DoubleType.INSTANCE).varArgs(DoubleType.INSTANCE),
-
FunctionSignature.ret(DecimalV2Type.SYSTEM_DEFAULT).varArgs(DecimalV2Type.SYSTEM_DEFAULT),
+
FunctionSignature.ret(FloatType.INSTANCE).varArgs(FloatType.INSTANCE),
FunctionSignature.ret(DecimalV3Type.WILDCARD).varArgs(DecimalV3Type.WILDCARD),
-
FunctionSignature.ret(DateType.INSTANCE).varArgs(DateType.INSTANCE),
-
FunctionSignature.ret(DateV2Type.INSTANCE).varArgs(DateV2Type.INSTANCE),
-
FunctionSignature.ret(DateTimeType.INSTANCE).varArgs(DateTimeType.INSTANCE),
-
FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).varArgs(DateTimeV2Type.SYSTEM_DEFAULT),
-
FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT).varArgs(VarcharType.SYSTEM_DEFAULT),
-
FunctionSignature.ret(StringType.INSTANCE).varArgs(StringType.INSTANCE)
+
FunctionSignature.ret(DecimalV2Type.SYSTEM_DEFAULT).varArgs(DecimalV2Type.SYSTEM_DEFAULT),
+
FunctionSignature.ret(LargeIntType.INSTANCE).varArgs(LargeIntType.INSTANCE),
+
FunctionSignature.ret(BigIntType.INSTANCE).varArgs(BigIntType.INSTANCE),
+
FunctionSignature.ret(IntegerType.INSTANCE).varArgs(IntegerType.INSTANCE),
+
FunctionSignature.ret(SmallIntType.INSTANCE).varArgs(SmallIntType.INSTANCE),
+
FunctionSignature.ret(TinyIntType.INSTANCE).varArgs(TinyIntType.INSTANCE)
);
/**
@@ -80,11 +82,28 @@ public class Greatest extends ScalarFunction
*/
@Override
public Greatest withChildren(List<Expression> children) {
- Preconditions.checkArgument(children.size() >= 1);
+ Preconditions.checkArgument(!children.isEmpty());
return new Greatest(children.get(0),
children.subList(1, children.size()).toArray(new
Expression[0]));
}
+ @Override
+ public FunctionSignature searchSignature(List<FunctionSignature>
signatures) {
+ List<DataType> argTypes = getArgumentsTypes();
+ if (argTypes.stream().anyMatch(CharacterType.class::isInstance)) {
+ return
FunctionSignature.ret(StringType.INSTANCE).varArgs(StringType.INSTANCE);
+ } else if
(argTypes.stream().anyMatch(DateTimeV2Type.class::isInstance)) {
+ return
FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).varArgs(DateTimeV2Type.SYSTEM_DEFAULT);
+ } else if (argTypes.stream().anyMatch(DateTimeType.class::isInstance))
{
+ return
FunctionSignature.ret(DateTimeType.INSTANCE).varArgs(DateTimeType.INSTANCE);
+ } else if (argTypes.stream().anyMatch(DateV2Type.class::isInstance)) {
+ return
FunctionSignature.ret(DateV2Type.INSTANCE).varArgs(DateV2Type.INSTANCE);
+ } else if (argTypes.stream().anyMatch(DateType.class::isInstance)) {
+ return
FunctionSignature.ret(DateType.INSTANCE).varArgs(DateType.INSTANCE);
+ }
+ return ExplicitlyCastableSignature.super.searchSignature(signatures);
+ }
+
@Override
public List<FunctionSignature> getSignatures() {
return SIGNATURES;
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/If.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/If.java
index 5d16e3ff8f1..b350b114525 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/If.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/If.java
@@ -20,11 +20,11 @@ package
org.apache.doris.nereids.trees.expressions.functions.scalar;
import org.apache.doris.catalog.FunctionSignature;
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.catalog.Type;
+import org.apache.doris.nereids.analyzer.Unbound;
import org.apache.doris.nereids.trees.expressions.Expression;
import
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
import org.apache.doris.nereids.trees.expressions.shape.TernaryExpression;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
-import org.apache.doris.nereids.types.ArrayType;
import org.apache.doris.nereids.types.BigIntType;
import org.apache.doris.nereids.types.BitmapType;
import org.apache.doris.nereids.types.BooleanType;
@@ -45,6 +45,7 @@ import org.apache.doris.nereids.types.SmallIntType;
import org.apache.doris.nereids.types.StringType;
import org.apache.doris.nereids.types.TinyIntType;
import org.apache.doris.nereids.types.VarcharType;
+import org.apache.doris.nereids.util.TypeCoercionUtils;
import com.google.common.base.Preconditions;
import com.google.common.base.Suppliers;
@@ -95,53 +96,7 @@ public class If extends ScalarFunction
FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT)
.args(BooleanType.INSTANCE, VarcharType.SYSTEM_DEFAULT,
VarcharType.SYSTEM_DEFAULT),
FunctionSignature.ret(StringType.INSTANCE)
- .args(BooleanType.INSTANCE, StringType.INSTANCE,
StringType.INSTANCE),
- FunctionSignature.ret(ArrayType.of(BooleanType.INSTANCE))
- .args(BooleanType.INSTANCE,
ArrayType.of(BooleanType.INSTANCE), ArrayType.of(BooleanType.INSTANCE)),
- FunctionSignature.ret(ArrayType.of(TinyIntType.INSTANCE))
- .args(BooleanType.INSTANCE,
ArrayType.of(TinyIntType.INSTANCE), ArrayType.of(TinyIntType.INSTANCE)),
- FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT)
- .args(BooleanType.INSTANCE,
- ArrayType.of(SmallIntType.INSTANCE),
- ArrayType.of(SmallIntType.INSTANCE)),
- FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE))
- .args(BooleanType.INSTANCE,
ArrayType.of(IntegerType.INSTANCE), ArrayType.of(IntegerType.INSTANCE)),
- FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE))
- .args(BooleanType.INSTANCE,
ArrayType.of(BigIntType.INSTANCE), ArrayType.of(BigIntType.INSTANCE)),
- FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT)
- .args(BooleanType.INSTANCE,
- ArrayType.of(LargeIntType.INSTANCE),
- ArrayType.of(LargeIntType.INSTANCE)),
- FunctionSignature.ret(ArrayType.of(FloatType.INSTANCE))
- .args(BooleanType.INSTANCE,
ArrayType.of(FloatType.INSTANCE), ArrayType.of(FloatType.INSTANCE)),
- FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE))
- .args(BooleanType.INSTANCE,
ArrayType.of(DoubleType.INSTANCE), ArrayType.of(DoubleType.INSTANCE)),
- FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT)
- .args(BooleanType.INSTANCE,
- ArrayType.of(DateTimeType.INSTANCE),
- ArrayType.of(DateTimeType.INSTANCE)),
- FunctionSignature.ret(ArrayType.of(DateType.INSTANCE))
- .args(BooleanType.INSTANCE,
ArrayType.of(DateType.INSTANCE), ArrayType.of(DateType.INSTANCE)),
- FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT)
- .args(BooleanType.INSTANCE,
- ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT),
- ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)),
- FunctionSignature.ret(ArrayType.of(DateV2Type.INSTANCE))
- .args(BooleanType.INSTANCE,
ArrayType.of(DateV2Type.INSTANCE), ArrayType.of(DateV2Type.INSTANCE)),
- FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT)
- .args(BooleanType.INSTANCE,
- ArrayType.of(DecimalV3Type.WILDCARD),
- ArrayType.of(DecimalV3Type.WILDCARD)),
- FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT)
- .args(BooleanType.INSTANCE,
- ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT),
- ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)),
- FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT)
- .args(BooleanType.INSTANCE,
- ArrayType.of(VarcharType.SYSTEM_DEFAULT),
- ArrayType.of(VarcharType.SYSTEM_DEFAULT)),
- FunctionSignature.ret(ArrayType.of(StringType.INSTANCE))
- .args(BooleanType.INSTANCE,
ArrayType.of(StringType.INSTANCE), ArrayType.of(StringType.INSTANCE))
+ .args(BooleanType.INSTANCE, StringType.INSTANCE,
StringType.INSTANCE)
);
private final Supplier<DataType> widerType = Suppliers.memoize(() -> {
@@ -156,7 +111,8 @@ public class If extends ScalarFunction
* constructor with 3 arguments.
*/
public If(Expression arg0, Expression arg1, Expression arg2) {
- super("if", arg0, arg1, arg2);
+ super("if", arg0 instanceof Unbound ? arg0 :
TypeCoercionUtils.castIfNotSameType(arg0, BooleanType.INSTANCE),
+ arg1, arg2);
}
/**
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/LastDay.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/LastDay.java
index d372868a343..bd3783abd9a 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/LastDay.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/LastDay.java
@@ -40,10 +40,10 @@ public class LastDay extends ScalarFunction
implements UnaryExpression, ExplicitlyCastableSignature,
PropagateNullableOnDateLikeV2Args {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
-
FunctionSignature.ret(DateType.INSTANCE).args(DateTimeType.INSTANCE),
- FunctionSignature.ret(DateType.INSTANCE).args(DateType.INSTANCE),
+
FunctionSignature.ret(DateV2Type.INSTANCE).args(DateV2Type.INSTANCE),
FunctionSignature.ret(DateV2Type.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT),
-
FunctionSignature.ret(DateV2Type.INSTANCE).args(DateV2Type.INSTANCE)
+ FunctionSignature.ret(DateType.INSTANCE).args(DateType.INSTANCE),
+
FunctionSignature.ret(DateType.INSTANCE).args(DateTimeType.INSTANCE)
);
/**
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Least.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Least.java
index 39af6626908..e22f9ea115f 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Least.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Least.java
@@ -23,6 +23,7 @@ import
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSi
import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.BigIntType;
+import org.apache.doris.nereids.types.DataType;
import org.apache.doris.nereids.types.DateTimeType;
import org.apache.doris.nereids.types.DateTimeV2Type;
import org.apache.doris.nereids.types.DateType;
@@ -37,6 +38,7 @@ import org.apache.doris.nereids.types.SmallIntType;
import org.apache.doris.nereids.types.StringType;
import org.apache.doris.nereids.types.TinyIntType;
import org.apache.doris.nereids.types.VarcharType;
+import org.apache.doris.nereids.types.coercion.CharacterType;
import org.apache.doris.nereids.util.ExpressionUtils;
import com.google.common.base.Preconditions;
@@ -51,21 +53,21 @@ public class Least extends ScalarFunction
implements ExplicitlyCastableSignature, PropagateNullable {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
-
FunctionSignature.ret(TinyIntType.INSTANCE).varArgs(TinyIntType.INSTANCE),
-
FunctionSignature.ret(SmallIntType.INSTANCE).varArgs(SmallIntType.INSTANCE),
-
FunctionSignature.ret(IntegerType.INSTANCE).varArgs(IntegerType.INSTANCE),
-
FunctionSignature.ret(BigIntType.INSTANCE).varArgs(BigIntType.INSTANCE),
-
FunctionSignature.ret(LargeIntType.INSTANCE).varArgs(LargeIntType.INSTANCE),
-
FunctionSignature.ret(FloatType.INSTANCE).varArgs(FloatType.INSTANCE),
-
FunctionSignature.ret(DoubleType.INSTANCE).varArgs(DoubleType.INSTANCE),
-
FunctionSignature.ret(DateType.INSTANCE).varArgs(DateType.INSTANCE),
-
FunctionSignature.ret(DateV2Type.INSTANCE).varArgs(DateV2Type.INSTANCE),
-
FunctionSignature.ret(DateTimeType.INSTANCE).varArgs(DateTimeType.INSTANCE),
+
FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT).varArgs(VarcharType.SYSTEM_DEFAULT),
+
FunctionSignature.ret(StringType.INSTANCE).varArgs(StringType.INSTANCE),
FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).varArgs(DateTimeV2Type.SYSTEM_DEFAULT),
-
FunctionSignature.ret(DecimalV2Type.SYSTEM_DEFAULT).varArgs(DecimalV2Type.SYSTEM_DEFAULT),
+
FunctionSignature.ret(DateTimeType.INSTANCE).varArgs(DateTimeType.INSTANCE),
+
FunctionSignature.ret(DateV2Type.INSTANCE).varArgs(DateV2Type.INSTANCE),
+
FunctionSignature.ret(DateType.INSTANCE).varArgs(DateType.INSTANCE),
+
FunctionSignature.ret(DoubleType.INSTANCE).varArgs(DoubleType.INSTANCE),
+
FunctionSignature.ret(FloatType.INSTANCE).varArgs(FloatType.INSTANCE),
FunctionSignature.ret(DecimalV3Type.WILDCARD).varArgs(DecimalV3Type.WILDCARD),
-
FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT).varArgs(VarcharType.SYSTEM_DEFAULT),
-
FunctionSignature.ret(StringType.INSTANCE).varArgs(StringType.INSTANCE)
+
FunctionSignature.ret(DecimalV2Type.SYSTEM_DEFAULT).varArgs(DecimalV2Type.SYSTEM_DEFAULT),
+
FunctionSignature.ret(LargeIntType.INSTANCE).varArgs(LargeIntType.INSTANCE),
+
FunctionSignature.ret(BigIntType.INSTANCE).varArgs(BigIntType.INSTANCE),
+
FunctionSignature.ret(IntegerType.INSTANCE).varArgs(IntegerType.INSTANCE),
+
FunctionSignature.ret(SmallIntType.INSTANCE).varArgs(SmallIntType.INSTANCE),
+
FunctionSignature.ret(TinyIntType.INSTANCE).varArgs(TinyIntType.INSTANCE)
);
/**
@@ -80,11 +82,28 @@ public class Least extends ScalarFunction
*/
@Override
public Least withChildren(List<Expression> children) {
- Preconditions.checkArgument(children.size() >= 1);
+ Preconditions.checkArgument(!children.isEmpty());
return new Least(children.get(0),
children.subList(1, children.size()).toArray(new
Expression[0]));
}
+ @Override
+ public FunctionSignature searchSignature(List<FunctionSignature>
signatures) {
+ List<DataType> argTypes = getArgumentsTypes();
+ if (argTypes.stream().anyMatch(CharacterType.class::isInstance)) {
+ return
FunctionSignature.ret(StringType.INSTANCE).varArgs(StringType.INSTANCE);
+ } else if
(argTypes.stream().anyMatch(DateTimeV2Type.class::isInstance)) {
+ return
FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).varArgs(DateTimeV2Type.SYSTEM_DEFAULT);
+ } else if (argTypes.stream().anyMatch(DateTimeType.class::isInstance))
{
+ return
FunctionSignature.ret(DateTimeType.INSTANCE).varArgs(DateTimeType.INSTANCE);
+ } else if (argTypes.stream().anyMatch(DateV2Type.class::isInstance)) {
+ return
FunctionSignature.ret(DateV2Type.INSTANCE).varArgs(DateV2Type.INSTANCE);
+ } else if (argTypes.stream().anyMatch(DateType.class::isInstance)) {
+ return
FunctionSignature.ret(DateType.INSTANCE).varArgs(DateType.INSTANCE);
+ }
+ return ExplicitlyCastableSignature.super.searchSignature(signatures);
+ }
+
@Override
public List<FunctionSignature> getSignatures() {
return SIGNATURES;
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesDiff.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesDiff.java
index 178b6a49331..4d011116334 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesDiff.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesDiff.java
@@ -42,9 +42,9 @@ public class MinutesDiff extends ScalarFunction
private static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(BigIntType.INSTANCE)
.args(DateTimeV2Type.SYSTEM_DEFAULT,
DateTimeV2Type.SYSTEM_DEFAULT),
-
FunctionSignature.ret(BigIntType.INSTANCE).args(DateTimeType.INSTANCE,
DateTimeType.INSTANCE),
FunctionSignature.ret(BigIntType.INSTANCE).args(DateV2Type.INSTANCE,
DateTimeV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(BigIntType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT,
DateV2Type.INSTANCE),
+
FunctionSignature.ret(BigIntType.INSTANCE).args(DateTimeType.INSTANCE,
DateTimeType.INSTANCE),
FunctionSignature.ret(BigIntType.INSTANCE).args(DateV2Type.INSTANCE,
DateV2Type.INSTANCE)
);
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Pmod.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Pmod.java
index 56ba753f1ff..d1f6de080ee 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Pmod.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Pmod.java
@@ -21,10 +21,12 @@ import org.apache.doris.catalog.FunctionSignature;
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.literal.StringLikeLiteral;
import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression;
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.util.TypeCoercionUtils;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
@@ -37,10 +39,10 @@ import java.util.List;
public class Pmod extends ScalarFunction
implements BinaryExpression, ExplicitlyCastableSignature,
AlwaysNullable {
- public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
-
FunctionSignature.ret(BigIntType.INSTANCE).args(BigIntType.INSTANCE,
BigIntType.INSTANCE),
-
FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE,
DoubleType.INSTANCE)
- );
+ public static final FunctionSignature BIGINT_SIGNATURE =
FunctionSignature.ret(BigIntType.INSTANCE)
+ .args(BigIntType.INSTANCE, BigIntType.INSTANCE);
+ public static final FunctionSignature DOUBLE_SIGNATURE =
FunctionSignature.ret(DoubleType.INSTANCE)
+ .args(DoubleType.INSTANCE, DoubleType.INSTANCE);
/**
* constructor with 2 arguments.
@@ -58,9 +60,39 @@ public class Pmod extends ScalarFunction
return new Pmod(children.get(0), children.get(1));
}
+ /**
+ * already override searchSignature and computeSignature, so getSignatures
is useless anymore.
+ *
+ * @return empty list
+ */
@Override
public List<FunctionSignature> getSignatures() {
- return SIGNATURES;
+ return ImmutableList.of();
+ }
+
+ @Override
+ public FunctionSignature computeSignature(FunctionSignature signature) {
+ return signature;
+ }
+
+ @Override
+ public FunctionSignature searchSignature(List<FunctionSignature>
signatures) {
+ boolean leftCouldBeBigInt = false;
+ boolean rightCouldBeBigInt = false;
+ if (getArgument(0) instanceof StringLikeLiteral) {
+ leftCouldBeBigInt = TypeCoercionUtils.characterLiteralTypeCoercion(
+ ((StringLikeLiteral) getArgument(0)).getStringValue(),
BigIntType.INSTANCE).isPresent();
+ }
+ if (getArgument(1) instanceof StringLikeLiteral) {
+ rightCouldBeBigInt =
TypeCoercionUtils.characterLiteralTypeCoercion(
+ ((StringLikeLiteral) getArgument(1)).getStringValue(),
BigIntType.INSTANCE).isPresent();
+ }
+ if ((getArgument(0).getDataType().isIntegerLikeType() ||
leftCouldBeBigInt)
+ && (getArgument(1).getDataType().isIntegerLikeType() ||
rightCouldBeBigInt)) {
+ return BIGINT_SIGNATURE;
+ } else {
+ return DOUBLE_SIGNATURE;
+ }
}
@Override
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java
index f9badd36be7..b986ee1c4be 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java
@@ -348,7 +348,7 @@ public class TypeCoercionUtils {
if ("false".equalsIgnoreCase(value)) {
ret = BooleanLiteral.FALSE;
}
- } else if (dataType instanceof IntegralType) {
+ } else if (dataType instanceof TinyIntType) {
BigInteger bigInt = new BigInteger(value);
if (BigInteger.valueOf(bigInt.byteValue()).equals(bigInt)) {
ret = new TinyIntLiteral(bigInt.byteValue());
@@ -361,6 +361,36 @@ public class TypeCoercionUtils {
} else {
ret = new LargeIntLiteral(bigInt);
}
+ } else if (dataType instanceof SmallIntType) {
+ BigInteger bigInt = new BigInteger(value);
+ if (BigInteger.valueOf(bigInt.shortValue()).equals(bigInt)) {
+ ret = new SmallIntLiteral(bigInt.shortValue());
+ } else if
(BigInteger.valueOf(bigInt.intValue()).equals(bigInt)) {
+ ret = new IntegerLiteral(bigInt.intValue());
+ } else if
(BigInteger.valueOf(bigInt.longValue()).equals(bigInt)) {
+ ret = new BigIntLiteral(bigInt.longValueExact());
+ } else {
+ ret = new LargeIntLiteral(bigInt);
+ }
+ } else if (dataType instanceof IntegerType) {
+ BigInteger bigInt = new BigInteger(value);
+ if (BigInteger.valueOf(bigInt.intValue()).equals(bigInt)) {
+ ret = new IntegerLiteral(bigInt.intValue());
+ } else if
(BigInteger.valueOf(bigInt.longValue()).equals(bigInt)) {
+ ret = new BigIntLiteral(bigInt.longValueExact());
+ } else {
+ ret = new LargeIntLiteral(bigInt);
+ }
+ } else if (dataType instanceof BigIntType) {
+ BigInteger bigInt = new BigInteger(value);
+ if (BigInteger.valueOf(bigInt.longValue()).equals(bigInt)) {
+ ret = new BigIntLiteral(bigInt.longValueExact());
+ } else {
+ ret = new LargeIntLiteral(bigInt);
+ }
+ } else if (dataType instanceof LargeIntType) {
+ BigInteger bigInt = new BigInteger(value);
+ ret = new LargeIntLiteral(bigInt);
} else if (dataType instanceof FloatType) {
ret = new FloatLiteral(Float.parseFloat(value));
} else if (dataType instanceof DoubleType) {
diff --git a/regression-test/data/nereids_function_p0/type_coercion.out
b/regression-test/data/nereids_function_p0/type_coercion.out
new file mode 100644
index 00000000000..b600040e8f6
--- /dev/null
+++ b/regression-test/data/nereids_function_p0/type_coercion.out
@@ -0,0 +1,37 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !greatest --
+333
+
+-- !least --
+2000000
+
+-- !if --
+2222
+
+-- !array_product --
+6000.0
+
+-- !array_avg --
+1001.0
+
+-- !array_pushfront --
+[4444, 1, 2, 3, 555555]
+
+-- !array_pushback --
+[1, 2, 3, 555555, 4444]
+
+-- !array_difference --
+[0, 1, 198]
+
+-- !array_enumerate_uniq --
+[1, 2, 1]
+
+-- !array_cum_sum --
+[1, 3, 3003]
+
+-- !pmod --
+0.0
+
+-- !nullif --
+13
+
diff --git a/regression-test/suites/nereids_function_p0/type_coercion.groovy
b/regression-test/suites/nereids_function_p0/type_coercion.groovy
new file mode 100644
index 00000000000..b48d9437a03
--- /dev/null
+++ b/regression-test/suites/nereids_function_p0/type_coercion.groovy
@@ -0,0 +1,24 @@
+// 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.
+suite("function_type_coercion") {
+ sql """set enable_fold_constant_by_be=false""" // remove this if
array<double> BE return result be fixed.
+ qt_greatest """select greatest(1, 2222, '333')"""
+ qt_least """select least(5,2000000,'3.0023')"""
+ qt_if """select if (1, 2222, 33)"""
+ qt_pmod """select pmod(2, '1.0')"""
+ qt_nullif """SELECT nullif(13, -4851)"""
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]