This is an automated email from the ASF dual-hosted git repository.
kxiao 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 be45d3c4f42 [fix](nereids)cast string to integer type use wrong
datatype's valueOf method #28174 (#28403)
be45d3c4f42 is described below
commit be45d3c4f42638c061f9cb74b34a2e9d76a5a34f
Author: starocean999 <[email protected]>
AuthorDate: Sat Dec 16 19:35:13 2023 +0800
[fix](nereids)cast string to integer type use wrong datatype's valueOf
method #28174 (#28403)
---
.../nereids/trees/expressions/literal/Literal.java | 6 +++---
.../nereids/rules/expression/FoldConstantTest.java | 4 ++--
.../sql_functions/cast_function/test_cast_function.out | 17 +++++++++++++----
.../cast_function/test_cast_function.groovy | 5 ++++-
4 files changed, 22 insertions(+), 10 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/Literal.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/Literal.java
index 2a40d979be6..edd78b811b4 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/Literal.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/Literal.java
@@ -202,11 +202,11 @@ public abstract class Literal extends Expression
implements LeafExpression, Comp
}
}
if (targetType.isTinyIntType()) {
- return Literal.of(Double.valueOf(desc).byteValue());
+ return Literal.of(Byte.valueOf(desc).byteValue());
} else if (targetType.isSmallIntType()) {
- return Literal.of(Double.valueOf(desc).shortValue());
+ return Literal.of(Short.valueOf(desc).shortValue());
} else if (targetType.isIntegerType()) {
- return Literal.of(Double.valueOf(desc).intValue());
+ return Literal.of(Integer.valueOf(desc).intValue());
} else if (targetType.isBigIntType()) {
return Literal.of(Long.valueOf(desc));
} else if (targetType.isLargeIntType()) {
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/FoldConstantTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/FoldConstantTest.java
index 882d1da81a4..da879f5e4f8 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/FoldConstantTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/FoldConstantTest.java
@@ -262,7 +262,7 @@ public class FoldConstantTest extends
ExpressionRewriteTestHelper {
: new DateTimeLiteral(1995, 5, 1, 0, 0, 0);
assertRewrite(e7, e8);
- interval = "interval 3 + 3 / 2 hour + '1991-05-01 10:00:00'";
+ interval = "interval 3 + 3 / 3 hour + '1991-05-01 10:00:00'";
e7 = process((TimestampArithmetic) PARSER.parseExpression(interval));
e8 = Config.enable_date_conversion
? new DateTimeV2Literal(1991, 5, 1, 14, 0, 0)
@@ -276,7 +276,7 @@ public class FoldConstantTest extends
ExpressionRewriteTestHelper {
: new DateTimeLiteral(1991, 5, 1, 10, 2, 0);
assertRewrite(e7, e8);
- interval = "interval 3 / 2 + 1 second + '1991-05-01 10:00:00'";
+ interval = "interval 3 / 3 + 1 second + '1991-05-01 10:00:00'";
e7 = process((TimestampArithmetic) PARSER.parseExpression(interval));
e8 = Config.enable_date_conversion
? new DateTimeV2Literal(1991, 5, 1, 10, 0, 2)
diff --git
a/regression-test/data/nereids_p0/sql_functions/cast_function/test_cast_function.out
b/regression-test/data/nereids_p0/sql_functions/cast_function/test_cast_function.out
index 1f9c69b3664..25455036ab1 100644
---
a/regression-test/data/nereids_p0/sql_functions/cast_function/test_cast_function.out
+++
b/regression-test/data/nereids_p0/sql_functions/cast_function/test_cast_function.out
@@ -6,7 +6,7 @@
11
-- !sql --
-2000-01-01T03:14:17
+\N
-- !sql --
\N
@@ -17,9 +17,18 @@
-- !sql --
20
--- !sql --
-1
-
-- !sql_null_cast_bitmap --
true
+-- !sql_to_tiny --
+\N
+
+-- !sql_to_small --
+\N
+
+-- !sql_to_int --
+\N
+
+-- !sql_to_big --
+\N
+
diff --git
a/regression-test/suites/nereids_p0/sql_functions/cast_function/test_cast_function.groovy
b/regression-test/suites/nereids_p0/sql_functions/cast_function/test_cast_function.groovy
index a1ff8743774..954c8562a10 100644
---
a/regression-test/suites/nereids_p0/sql_functions/cast_function/test_cast_function.groovy
+++
b/regression-test/suites/nereids_p0/sql_functions/cast_function/test_cast_function.groovy
@@ -24,7 +24,10 @@ suite("test_cast_function") {
qt_sql """ select cast ("0.0000031417" as datetime) """
qt_sql """ select cast (NULL AS CHAR(1)); """
qt_sql """ select cast ('20190101' AS CHAR(2)); """
- qt_sql """ select cast ('1.23' AS int); """
qt_sql_null_cast_bitmap """ select cast (case when BITMAP_EMPTY() is NULL
then null else null end as bitmap) is NULL; """
+ qt_sql_to_tiny """ select cast('1212.31' as tinyint);"""
+ qt_sql_to_small """ select cast('1212.31' as smallint);"""
+ qt_sql_to_int """ select cast('1212.31' as int);"""
+ qt_sql_to_big """ select cast('1212.31' as bigint);"""
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]