[enhancement](Nereids) consider string literal coercion when search function signature (#17175)

This commit is contained in:
morrySnow
2023-02-28 17:59:52 +08:00
committed by GitHub
parent 727853017c
commit dd4bd3f360
3 changed files with 17 additions and 10 deletions

View File

@ -20,8 +20,10 @@ package org.apache.doris.nereids.trees.expressions.functions;
import org.apache.doris.catalog.FunctionSignature;
import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.literal.Literal;
import org.apache.doris.nereids.types.DataType;
import org.apache.doris.nereids.types.coercion.AbstractDataType;
import org.apache.doris.nereids.util.TypeCoercionUtils;
import com.google.common.collect.Lists;
@ -125,7 +127,14 @@ public class SearchSignature {
int arity = arguments.size();
for (int i = 0; i < arity; i++) {
AbstractDataType sigArgType = sig.getArgType(i);
AbstractDataType realType = arguments.get(i).getDataType();
DataType realType = arguments.get(i).getDataType();
// we need to try to do string literal coercion when search signature.
// for example, FUNC_A has two signature FUNC_A(datetime) and FUNC_A(string)
// if SQL block is `FUNC_A('2020-02-02 00:00:00')`, we should return signature FUNC_A(datetime).
if (arguments.get(i).isLiteral() && realType.isStringLikeType() && sigArgType instanceof DataType) {
realType = TypeCoercionUtils.characterLiteralTypeCoercion(((Literal) arguments.get(i)).getStringValue(),
(DataType) sigArgType).orElse(arguments.get(i)).getDataType();
}
if (!typePredicate.apply(sigArgType, realType)) {
return false;
}

View File

@ -48,6 +48,7 @@ public interface RequireTrivialTypes {
// todo: add JsonBType
ImmutableList<DataType> trivialTypes = ImmutableList.of(
BooleanType.INSTANCE,
TinyIntType.INSTANCE,
SmallIntType.INSTANCE,
IntegerType.INSTANCE,
@ -56,18 +57,15 @@ public interface RequireTrivialTypes {
FloatType.INSTANCE,
DoubleType.INSTANCE,
DecimalV2Type.SYSTEM_DEFAULT,
DecimalV3Type.DEFAULT_DECIMAL32,
DecimalV3Type.DEFAULT_DECIMAL64,
DecimalV3Type.DEFAULT_DECIMAL128,
BooleanType.INSTANCE,
VarcharType.INSTANCE,
StringType.INSTANCE,
CharType.INSTANCE,
DecimalV3Type.SYSTEM_DEFAULT,
DateType.INSTANCE,
DateTimeType.INSTANCE,
DateV2Type.INSTANCE,
DateTimeV2Type.SYSTEM_DEFAULT,
TimeType.INSTANCE,
TimeV2Type.INSTANCE
TimeV2Type.INSTANCE,
CharType.SYSTEM_DEFAULT,
VarcharType.SYSTEM_DEFAULT,
StringType.INSTANCE
);
}

View File

@ -298,7 +298,7 @@ public class TypeCoercionUtils {
* characterLiteralTypeCoercion.
*/
@Developing
private static Optional<Expression> characterLiteralTypeCoercion(String value, DataType dataType) {
public static Optional<Expression> characterLiteralTypeCoercion(String value, DataType dataType) {
Expression ret = null;
try {
if (dataType instanceof BooleanType) {