This is an automated email from the ASF dual-hosted git repository.
yiguolei 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 7b384af1a99 [fix](cast) fix wrong result while cast string to float
(#31781) (#31813)
7b384af1a99 is described below
commit 7b384af1a993a729a9752266a7137de40eb37eb5
Author: camby <[email protected]>
AuthorDate: Wed Mar 6 20:50:02 2024 +0800
[fix](cast) fix wrong result while cast string to float (#31781) (#31813)
Issue Number: close #31518
---
.../apache/doris/nereids/trees/expressions/literal/FloatLiteral.java | 2 +-
.../data/nereids_p0/sql_functions/cast_function/test_cast_function.out | 3 +++
.../data/query_p0/sql_functions/cast_function/test_cast_function.out | 3 +++
.../nereids_p0/sql_functions/cast_function/test_cast_function.groovy | 1 +
.../query_p0/sql_functions/cast_function/test_cast_function.groovy | 1 +
5 files changed, 9 insertions(+), 1 deletion(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/FloatLiteral.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/FloatLiteral.java
index b63de24a824..f593743676d 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/FloatLiteral.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/FloatLiteral.java
@@ -48,7 +48,7 @@ public class FloatLiteral extends Literal {
@Override
public LiteralExpr toLegacyLiteral() {
- return new org.apache.doris.analysis.FloatLiteral((double) value,
Type.FLOAT);
+ return new org.apache.doris.analysis.FloatLiteral(getDouble(),
Type.FLOAT);
}
@Override
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 f62e9e86755..1eed1411842 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
@@ -20,6 +20,9 @@
-- !sql --
10000.00001
+-- !sql --
+123.123
+
-- !sql_null_cast_bitmap --
true
diff --git
a/regression-test/data/query_p0/sql_functions/cast_function/test_cast_function.out
b/regression-test/data/query_p0/sql_functions/cast_function/test_cast_function.out
index 8430f51a8b8..8b3214cfa75 100644
---
a/regression-test/data/query_p0/sql_functions/cast_function/test_cast_function.out
+++
b/regression-test/data/query_p0/sql_functions/cast_function/test_cast_function.out
@@ -20,6 +20,9 @@
-- !sql --
10000.00001
+-- !sql --
+123.123
+
-- !select1 --
0 2022-12-01T22:23:24.123 2022-12-01 22:23:24.123 2022-12-01
2022-12-01 2022-12-01 2022-12-01 78.123 78.123 78.12345
78.12345
1 2022-12-01T22:23:24.123 2022-12-01 22:23:24.123456789 2022-12-01
2022-12-01 2022-12-01 2022-12-01 78.123 78.123 78.12345
78.12345
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 9f348449d1e..c601449e31b 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
@@ -25,6 +25,7 @@ suite("test_cast_function") {
qt_sql """ select cast (NULL AS CHAR(1)); """
qt_sql """ select cast ('20190101' AS CHAR(2)); """
qt_sql """ select cast(cast(10000.00001 as double) as string); """
+ qt_sql """ select cast('123.123' as float); """
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);"""
diff --git
a/regression-test/suites/query_p0/sql_functions/cast_function/test_cast_function.groovy
b/regression-test/suites/query_p0/sql_functions/cast_function/test_cast_function.groovy
index fe85ba43dc0..7f4bbe40ebd 100644
---
a/regression-test/suites/query_p0/sql_functions/cast_function/test_cast_function.groovy
+++
b/regression-test/suites/query_p0/sql_functions/cast_function/test_cast_function.groovy
@@ -23,6 +23,7 @@ suite("test_cast_function") {
qt_sql """ select cast (NULL AS CHAR(1)); """
qt_sql """ select cast ('20190101' AS CHAR(2)); """
qt_sql """ select cast(cast(10000.00001 as double) as string); """
+ qt_sql """ select cast('123.123' as float); """
def tableName = "test_cast_function_nullable"
sql "DROP TABLE IF EXISTS ${tableName}"
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]