[cherry-pick](branch-21) fix cast string to int return wrong result (#36788) (#37803)

## Proposed changes
cherry-pick from master:
https://github.com/apache/doris/pull/36788
https://github.com/apache/doris/pull/36505

<!--Describe your changes.-->
This commit is contained in:
zhangstar333
2024-07-15 18:48:49 +08:00
committed by GitHub
parent e5219467dd
commit 03e21dddff
6 changed files with 27 additions and 4 deletions

View File

@ -393,7 +393,7 @@ public class DateTimeExtractAndTransform {
/**
* from_days.
*/
@ExecFunction(name = "from_days", argTypes = {"INT"}, returnType = "DATE")
@ExecFunction(name = "from_days", argTypes = {"INT"}, returnType = "DATEV2")
public static Expression fromDays(IntegerLiteral n) {
// doris treat 0000AD as ordinary year but java LocalDateTime treat it as lunar year.
LocalDateTime res = LocalDateTime.of(0, 1, 1, 0, 0, 0)
@ -401,7 +401,7 @@ public class DateTimeExtractAndTransform {
if (res.isBefore(LocalDateTime.of(0, 3, 1, 0, 0, 0))) {
res = res.plusDays(-1);
}
return DateLiteral.fromJavaDateType(res);
return DateV2Literal.fromJavaDateType(res);
}
@ExecFunction(name = "last_day", argTypes = {"DATE"}, returnType = "DATE")

View File

@ -23,7 +23,7 @@ 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.shape.UnaryExpression;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DateType;
import org.apache.doris.nereids.types.DateV2Type;
import org.apache.doris.nereids.types.IntegerType;
import com.google.common.base.Preconditions;
@ -38,7 +38,7 @@ public class FromDays extends ScalarFunction
implements UnaryExpression, ExplicitlyCastableSignature, AlwaysNullable {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(DateType.INSTANCE).args(IntegerType.INSTANCE)
FunctionSignature.ret(DateV2Type.INSTANCE).args(IntegerType.INSTANCE)
);
/**