diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java index 5253ff7fde..4aaaf6508d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java @@ -1815,7 +1815,7 @@ public class FunctionCallExpr extends Expr { .toSql()); } } - if (fn.getFunctionName().getFunction().equals("timediff")) { + if (fn.getFunctionName().getFunction().equalsIgnoreCase("timediff")) { fn.getReturnType().getPrimitiveType().setTimeType(); ScalarType left = (ScalarType) argTypes[0]; ScalarType right = (ScalarType) argTypes[1]; @@ -1826,17 +1826,17 @@ public class FunctionCallExpr extends Expr { } } - if (fn.getFunctionName().getFunction().equals("from_microsecond")) { + if (fn.getFunctionName().getFunction().equalsIgnoreCase("from_microsecond")) { Type ret = ScalarType.createDatetimeV2Type(6); fn.setReturnType(ret); } - if (fn.getFunctionName().getFunction().equals("from_millisecond")) { + if (fn.getFunctionName().getFunction().equalsIgnoreCase("from_millisecond")) { Type ret = ScalarType.createDatetimeV2Type(3); fn.setReturnType(ret); } - if (fn.getFunctionName().getFunction().equals("from_second")) { + if (fn.getFunctionName().getFunction().equalsIgnoreCase("from_second")) { Type ret = ScalarType.createDatetimeV2Type(0); fn.setReturnType(ret); } @@ -1863,7 +1863,7 @@ public class FunctionCallExpr extends Expr { } } - if (fn.getFunctionName().getFunction().equals("struct_element")) { + if (fn.getFunctionName().getFunction().equalsIgnoreCase("struct_element")) { if (children.size() < 2) { throw new AnalysisException(fnName.getFunction() + " needs two parameters: " + this.toSql()); } @@ -1888,7 +1888,7 @@ public class FunctionCallExpr extends Expr { } } - if (fn.getFunctionName().getFunction().equals("sha2")) { + if (fn.getFunctionName().getFunction().equalsIgnoreCase("sha2")) { if ((children.size() != 2) || (getChild(1).isConstant() == false) || !(getChild(1) instanceof IntLiteral)) { throw new AnalysisException( @@ -2046,7 +2046,7 @@ public class FunctionCallExpr extends Expr { * SELECT str_to_date("2020-09-01", "%Y-%m-%d %H:%i:%s"); * Return type is DATETIME */ - if (fn.getFunctionName().getFunction().equals("str_to_date")) { + if (fn.getFunctionName().getFunction().equalsIgnoreCase("str_to_date")) { Expr child1Result = getChild(1).getResultValue(false); if (child1Result instanceof StringLiteral) { if (DateLiteral.hasTimePart(child1Result.getStringValue())) { @@ -2085,7 +2085,7 @@ public class FunctionCallExpr extends Expr { // cast(xx as char(N)/varchar(N)) will be handled as substr(cast(xx as char, varchar), 1, N), // but type is varchar(*), we change it to varchar(N); - if (fn.getFunctionName().getFunction().equals("substr") + if (fn.getFunctionName().getFunction().equalsIgnoreCase("substr") && children.size() == 3 && children.get(1) instanceof IntLiteral && children.get(2) instanceof IntLiteral) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Microsecond.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Microsecond.java index 6d3bf51b55..4e610e21be 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Microsecond.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Microsecond.java @@ -24,7 +24,6 @@ import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnD import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeV2Type; -import org.apache.doris.nereids.types.DateV2Type; import org.apache.doris.nereids.types.IntegerType; import com.google.common.base.Preconditions; @@ -39,8 +38,7 @@ public class Microsecond extends ScalarFunction implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT), - FunctionSignature.ret(IntegerType.INSTANCE).args(DateV2Type.INSTANCE) + FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT) ); /** diff --git a/regression-test/data/nereids_p0/sql_functions/datetime_functions/test_date_function.out b/regression-test/data/nereids_p0/sql_functions/datetime_functions/test_date_function.out index 46a6256615..d71b996805 100644 --- a/regression-test/data/nereids_p0/sql_functions/datetime_functions/test_date_function.out +++ b/regression-test/data/nereids_p0/sql_functions/datetime_functions/test_date_function.out @@ -422,6 +422,9 @@ February -- !sql -- 767891 +-- !sql_ms_use_date -- +0 + -- !sql -- 1 2022-08-01 2 2022-08-01 diff --git a/regression-test/suites/nereids_p0/sql_functions/datetime_functions/test_date_function.groovy b/regression-test/suites/nereids_p0/sql_functions/datetime_functions/test_date_function.groovy index 58413e29ce..d1e8fcab80 100644 --- a/regression-test/suites/nereids_p0/sql_functions/datetime_functions/test_date_function.groovy +++ b/regression-test/suites/nereids_p0/sql_functions/datetime_functions/test_date_function.groovy @@ -428,6 +428,7 @@ suite("test_date_function") { sql """ insert into ${tableName} values('1999-01-02 10:11:12.767891') """ qt_sql """ select microsecond(k1) from ${tableName}; """ + qt_sql_ms_use_date "select microsecond(cast(k1 as date)) from ${tableName};" // qt_sql """ select count(*) from (select * from numbers("number" = "200")) tmp1 WHERE 0 <= UNIX_TIMESTAMP(); """