From 8e5cd5e6b0e1bdeb56152e42cfe07ff8130b47fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Mar=C3=ADn?= Date: Fri, 12 Jan 2024 10:45:36 +0000 Subject: [PATCH 1/3] Try a different approach --- src/Interpreters/convertFieldToType.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Interpreters/convertFieldToType.cpp b/src/Interpreters/convertFieldToType.cpp index 4e38103ac1f2..c3b8405659ab 100644 --- a/src/Interpreters/convertFieldToType.cpp +++ b/src/Interpreters/convertFieldToType.cpp @@ -492,10 +492,11 @@ Field convertFieldToTypeImpl(const Field & src, const IDataType & type, const ID if (src.getType() == Field::Types::String) { /// Promote data type to avoid overflows. Note that overflows in the largest data type are still possible. + /// But don't promote Float32, since we want to keep the exact same value const IDataType * type_to_parse = &type; DataTypePtr holder; - if (type.canBePromoted()) + if (type.canBePromoted() && !which_type.isFloat32()) { holder = type.promoteNumericType(); type_to_parse = holder.get(); From f95254bde6a7b04eba4fc16370d4716a7fe18870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Mar=C3=ADn?= Date: Fri, 12 Jan 2024 14:43:17 +0000 Subject: [PATCH 2/3] Add test --- tests/queries/0_stateless/02966_float32_promotion.reference | 1 + tests/queries/0_stateless/02966_float32_promotion.sql | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 tests/queries/0_stateless/02966_float32_promotion.reference create mode 100644 tests/queries/0_stateless/02966_float32_promotion.sql diff --git a/tests/queries/0_stateless/02966_float32_promotion.reference b/tests/queries/0_stateless/02966_float32_promotion.reference new file mode 100644 index 000000000000..086e9795679d --- /dev/null +++ b/tests/queries/0_stateless/02966_float32_promotion.reference @@ -0,0 +1 @@ +49.9 diff --git a/tests/queries/0_stateless/02966_float32_promotion.sql b/tests/queries/0_stateless/02966_float32_promotion.sql new file mode 100644 index 000000000000..26aad6311c57 --- /dev/null +++ b/tests/queries/0_stateless/02966_float32_promotion.sql @@ -0,0 +1,5 @@ +-- https://github.com/ClickHouse/ClickHouse/issues/58680 +CREATE OR REPLACE TABLE f32_table (my_field Float32) ENGINE=Memory(); +INSERT INTO f32_table values ('49.9'); +SELECT * FROM f32_table where my_field = '49.9'; +DROP TABLE f32_table; \ No newline at end of file From 8049d3560d8f76522f08ffe684ccf849150a6e33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Mar=C3=ADn?= Date: Sat, 13 Jan 2024 12:56:14 +0100 Subject: [PATCH 3/3] Update 02966_float32_promotion.sql --- tests/queries/0_stateless/02966_float32_promotion.sql | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/queries/0_stateless/02966_float32_promotion.sql b/tests/queries/0_stateless/02966_float32_promotion.sql index 26aad6311c57..df687ca53388 100644 --- a/tests/queries/0_stateless/02966_float32_promotion.sql +++ b/tests/queries/0_stateless/02966_float32_promotion.sql @@ -1,5 +1,6 @@ -- https://github.com/ClickHouse/ClickHouse/issues/58680 -CREATE OR REPLACE TABLE f32_table (my_field Float32) ENGINE=Memory(); +DROP TABLE IF EXISTS f32_table; +CREATE TABLE f32_table (my_field Float32) ENGINE=Memory(); INSERT INTO f32_table values ('49.9'); SELECT * FROM f32_table where my_field = '49.9'; -DROP TABLE f32_table; \ No newline at end of file +DROP TABLE f32_table;