From 9893150c7f0e2084a685e9deaad63d5895fc5c47 Mon Sep 17 00:00:00 2001 From: Liuqing Yue Date: Mon, 2 Sep 2024 18:53:10 +0800 Subject: [PATCH] chore: patch borsh-rs to bypass NaN check --- Cargo.lock | 8 ++- Cargo.toml | 1 + src/query/expression/src/types/number.rs | 54 +------------------ .../suites/base/issues/issue_16213.test | 4 +- 4 files changed, 8 insertions(+), 59 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9a13c497e2a9..c605a8543c9f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1676,8 +1676,7 @@ dependencies = [ [[package]] name = "borsh" version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6362ed55def622cddc70a4746a68554d7b687713770de539e59a739b249f8ed" +source = "git+https://github.com/dqhl76/borsh-rs.git?rev=6609a44#6609a44c01ab8d6307b579a9a82b5233286e2f41" dependencies = [ "borsh-derive", "cfg_aliases 0.2.1", @@ -1686,8 +1685,7 @@ dependencies = [ [[package]] name = "borsh-derive" version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3ef8005764f53cd4dca619f5bf64cafd4664dada50ece25e4d81de54c80cc0b" +source = "git+https://github.com/dqhl76/borsh-rs.git?rev=6609a44#6609a44c01ab8d6307b579a9a82b5233286e2f41" dependencies = [ "once_cell", "proc-macro-crate", @@ -5067,7 +5065,7 @@ dependencies = [ "futures", "log", "rand 0.8.5", - "reqwest 0.12.4", + "reqwest 0.12.5", "serde", "serde_json", "tokio", diff --git a/Cargo.toml b/Cargo.toml index b30cdecf8be1..70caa946551a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -408,3 +408,4 @@ orc-rust = { git = "https://github.com/youngsofun/datafusion-orc", rev = "174537 recursive = { git = "https://github.com/zhang2014/recursive.git", rev = "6af35a1" } sled = { git = "https://github.com/datafuse-extras/sled", tag = "v0.34.7-datafuse.1" } xorfilter-rs = { git = "https://github.com/datafuse-extras/xorfilter", tag = "databend-alpha.4" } +borsh = { git = "https://github.com/dqhl76/borsh-rs.git", rev = "6609a44"} diff --git a/src/query/expression/src/types/number.rs b/src/query/expression/src/types/number.rs index 5b1f1f701ffe..d49673258298 100644 --- a/src/query/expression/src/types/number.rs +++ b/src/query/expression/src/types/number.rs @@ -319,24 +319,12 @@ pub enum NumberScalar { serialize_with = "json_serde_impl::serialize_f32", deserialize_with = "json_serde_impl::deserialize_f32" )] - Float32( - #[borsh( - serialize_with = "borsh_serde_impl::serialize_f32", - deserialize_with = "borsh_serde_impl::deserialize_f32" - )] - F32, - ), + Float32(F32), #[serde( serialize_with = "json_serde_impl::serialize_f64", deserialize_with = "json_serde_impl::deserialize_f64" )] - Float64( - #[borsh( - serialize_with = "borsh_serde_impl::serialize_f64", - deserialize_with = "borsh_serde_impl::deserialize_f64" - )] - F64, - ), + Float64(F64), } #[derive(Clone, PartialEq, EnumAsInner)] @@ -1527,41 +1515,3 @@ mod json_serde_impl { } } } - -/// Borsh serialize and deserialize implementation for `F32` and `F64`. -mod borsh_serde_impl { - use ordered_float::OrderedFloat; - - use crate::types::F32; - use crate::types::F64; - - pub fn serialize_f32( - obj: &F32, - writer: &mut W, - ) -> Result<(), borsh::io::Error> { - writer.write_all(&obj.to_bits().to_le_bytes())?; - Ok(()) - } - - pub fn deserialize_f32(reader: &mut R) -> Result { - let mut buf = [0u8; size_of::()]; - reader.read_exact(&mut buf)?; - let res = OrderedFloat::from(f32::from_bits(u32::from_le_bytes(buf))); - Ok(res) - } - - pub fn serialize_f64( - obj: &F64, - writer: &mut W, - ) -> Result<(), borsh::io::Error> { - writer.write_all(&obj.to_bits().to_le_bytes())?; - Ok(()) - } - - pub fn deserialize_f64(reader: &mut R) -> Result { - let mut buf = [0u8; size_of::()]; - reader.read_exact(&mut buf)?; - let res = OrderedFloat::from(f64::from_bits(u64::from_le_bytes(buf))); - Ok(res) - } -} diff --git a/tests/sqllogictests/suites/base/issues/issue_16213.test b/tests/sqllogictests/suites/base/issues/issue_16213.test index 99bb4b7718b3..f457de9c5b88 100644 --- a/tests/sqllogictests/suites/base/issues/issue_16213.test +++ b/tests/sqllogictests/suites/base/issues/issue_16213.test @@ -10,7 +10,7 @@ INSERT INTO test_table_double (ID, Name, Age, City, Score) VALUES (1, 'Alice', 2 query SELECT * FROM test_table_double ---- -1 Alice 25 Toroto inf +1 Alice 25 Toroto Infinity statement ok drop table if exists test_inf_nan @@ -30,4 +30,4 @@ insert into test_inf_nan select 'nan' from numbers(100) query select max(a) from test_inf_nan ---- -inf +NaN