This is an automated email from the ASF dual-hosted git repository.

morningman 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 71872cd37e8 [branch-2.0][improvement](serde) Handle NaN values in 
number for MySQL result write (#33230)
71872cd37e8 is described below

commit 71872cd37e84349c4c7bfb2380b882817f9a86be
Author: zy-kkk <zhongy...@gmail.com>
AuthorDate: Thu Apr 4 08:15:57 2024 +0800

    [branch-2.0][improvement](serde) Handle NaN values in number for MySQL 
result write (#33230)
    
    pick #33227
---
 .../data_types/serde/data_type_number_serde.cpp    | 14 +++++++++--
 .../data/datatype_p0/double/test_double_nan.out    |  7 ++++++
 .../data/datatype_p0/float/test_float_nan.out      |  7 ++++++
 .../data/nereids_function_p0/scalar_function/A.out | 16 ++++++-------
 .../datatype_p0/double/test_double_nan.groovy      | 28 ++++++++++++++++++++++
 .../suites/datatype_p0/float/test_float_nan.groovy | 28 ++++++++++++++++++++++
 6 files changed, 90 insertions(+), 10 deletions(-)

diff --git a/be/src/vec/data_types/serde/data_type_number_serde.cpp 
b/be/src/vec/data_types/serde/data_type_number_serde.cpp
index af885dc8cc5..10a4c7b0105 100644
--- a/be/src/vec/data_types/serde/data_type_number_serde.cpp
+++ b/be/src/vec/data_types/serde/data_type_number_serde.cpp
@@ -212,9 +212,19 @@ Status 
DataTypeNumberSerDe<T>::_write_column_to_mysql(const IColumn& column,
     } else if constexpr (std::is_same_v<T, Int128>) {
         buf_ret = result.push_largeint(data[col_index]);
     } else if constexpr (std::is_same_v<T, float>) {
-        buf_ret = result.push_float(data[col_index]);
+        if (std::isnan(data[col_index])) {
+            // Handle NaN for float, we should push null value
+            buf_ret = result.push_null();
+        } else {
+            buf_ret = result.push_float(data[col_index]);
+        }
     } else if constexpr (std::is_same_v<T, double>) {
-        buf_ret = result.push_double(data[col_index]);
+        if (std::isnan(data[col_index])) {
+            // Handle NaN for double, we should push null value
+            buf_ret = result.push_null();
+        } else {
+            buf_ret = result.push_double(data[col_index]);
+        }
     }
     if (UNLIKELY(buf_ret != 0)) {
         return Status::InternalError("pack mysql buffer failed.");
diff --git a/regression-test/data/datatype_p0/double/test_double_nan.out 
b/regression-test/data/datatype_p0/double/test_double_nan.out
new file mode 100644
index 00000000000..327a147e2db
--- /dev/null
+++ b/regression-test/data/datatype_p0/double/test_double_nan.out
@@ -0,0 +1,7 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !select --
+1      \N
+
+-- !select --
+\N
+
diff --git a/regression-test/data/datatype_p0/float/test_float_nan.out 
b/regression-test/data/datatype_p0/float/test_float_nan.out
new file mode 100644
index 00000000000..327a147e2db
--- /dev/null
+++ b/regression-test/data/datatype_p0/float/test_float_nan.out
@@ -0,0 +1,7 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !select --
+1      \N
+
+-- !select --
+\N
+
diff --git a/regression-test/data/nereids_function_p0/scalar_function/A.out 
b/regression-test/data/nereids_function_p0/scalar_function/A.out
index 13d9bcccb6e..24dac44e3e5 100644
--- a/regression-test/data/nereids_function_p0/scalar_function/A.out
+++ b/regression-test/data/nereids_function_p0/scalar_function/A.out
@@ -243,8 +243,8 @@
 0.6435011087932843
 0.45102681179626236
 0.0
-nan
-nan
+\N
+\N
 
 -- !sql_acos_Double_notnull --
 1.4706289056333368
@@ -257,8 +257,8 @@ nan
 0.6435011087932843
 0.45102681179626236
 0.0
-nan
-nan
+\N
+\N
 
 -- !sql_append_trailing_char_if_absent_Varchar_Varchar --
 \N
@@ -388,8 +388,8 @@ nan
 0.9272952180016123
 1.1197695149986342
 1.5707963267948966
-nan
-nan
+\N
+\N
 
 -- !sql_asin_Double_notnull --
 0.1001674211615598
@@ -402,8 +402,8 @@ nan
 0.9272952180016123
 1.1197695149986342
 1.5707963267948966
-nan
-nan
+\N
+\N
 
 -- !sql_atan_Double --
 \N
diff --git a/regression-test/suites/datatype_p0/double/test_double_nan.groovy 
b/regression-test/suites/datatype_p0/double/test_double_nan.groovy
new file mode 100644
index 00000000000..b193b0132db
--- /dev/null
+++ b/regression-test/suites/datatype_p0/double/test_double_nan.groovy
@@ -0,0 +1,28 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_double_nan", "datatype_p0") {
+    def tableName = "tbl_test_double_nan"
+    sql "DROP TABLE IF EXISTS ${tableName}"
+    sql "CREATE  TABLE if NOT EXISTS ${tableName} (k int, value double) 
DUPLICATE KEY(k) DISTRIBUTED BY HASH (k) BUCKETS 1 PROPERTIES 
('replication_num' = '1');"
+    sql """insert into ${tableName} select 1, sqrt(-1);"""
+
+    qt_select "select * from ${tableName} order by 1;"
+    qt_select "select sqrt(-1);"
+
+    sql "DROP TABLE IF EXISTS ${tableName}"
+}
\ No newline at end of file
diff --git a/regression-test/suites/datatype_p0/float/test_float_nan.groovy 
b/regression-test/suites/datatype_p0/float/test_float_nan.groovy
new file mode 100644
index 00000000000..18958b27cf2
--- /dev/null
+++ b/regression-test/suites/datatype_p0/float/test_float_nan.groovy
@@ -0,0 +1,28 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_float_nan", "datatype_p0") {
+    def tableName = "tbl_test_float_nan"
+    sql "DROP TABLE IF EXISTS ${tableName}"
+    sql "CREATE  TABLE if NOT EXISTS ${tableName} (k int, value float) 
DUPLICATE KEY(k) DISTRIBUTED BY HASH (k) BUCKETS 1 PROPERTIES 
('replication_num' = '1');"
+    sql """insert into ${tableName} select 1, sqrt(-1);"""
+
+    qt_select "select * from ${tableName} order by 1;"
+    qt_select "select sqrt(-1);"
+
+    sql "DROP TABLE IF EXISTS ${tableName}"
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to