[improvement](serde) Handle NaN values in number for MySQL result write (#33227)
This commit is contained in:
@ -244,9 +244,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.");
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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}"
|
||||
}
|
||||
@ -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}"
|
||||
}
|
||||
Reference in New Issue
Block a user