This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch branch-2.1 in repository https://gitbox.apache.org/repos/asf/doris.git
commit 2d6e975d5a81ff460a0972d0133b19d98d8258dd Author: camby <camby...@tencent.com> AuthorDate: Tue Mar 5 18:58:03 2024 +0800 [fix](cast) fix wrong result while cast string to float (#31781) 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 55d9c98e2da..df75bbcfc5c 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 @@ -46,6 +46,6 @@ public class FloatLiteral extends FractionalLiteral { @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); } } 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: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org