This is an automated email from the ASF dual-hosted git repository.
xuyang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 7fbace480e3 [fix](cast) wrong result while cast const to double then
to string (#31657)
7fbace480e3 is described below
commit 7fbace480e343510fe98e2b913825d1140c2be16
Author: camby <[email protected]>
AuthorDate: Tue Mar 5 13:15:25 2024 +0800
[fix](cast) wrong result while cast const to double then to string (#31657)
Issue Number: close #31514
---
fe/fe-core/src/main/java/org/apache/doris/analysis/FloatLiteral.java | 5 +++++
.../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, 13 insertions(+)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/FloatLiteral.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/FloatLiteral.java
index 1fba4edfb90..ef0493d8e0c 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FloatLiteral.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FloatLiteral.java
@@ -137,6 +137,11 @@ public class FloatLiteral extends NumericLiteralExpr {
}
NumberFormat nf = NumberFormat.getInstance();
nf.setGroupingUsed(false);
+ if (type == Type.FLOAT) {
+ nf.setMaximumFractionDigits(7);
+ } else {
+ nf.setMaximumFractionDigits(16);
+ }
return nf.format(value);
}
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 25455036ab1..f62e9e86755 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
@@ -17,6 +17,9 @@
-- !sql --
20
+-- !sql --
+10000.00001
+
-- !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 2958bce0bfd..8430f51a8b8 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
@@ -17,6 +17,9 @@
-- !sql --
20
+-- !sql --
+10000.00001
+
-- !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 954c8562a10..9f348449d1e 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,6 +24,7 @@ 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(cast(10000.00001 as double) as string); """
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 30a9fbae94c..fe85ba43dc0 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
@@ -22,6 +22,7 @@ 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(cast(10000.00001 as double) as string); """
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]