Skip to content

Commit

Permalink
chore: patch borsh-rs to bypass NaN check
Browse files Browse the repository at this point in the history
  • Loading branch information
dqhl76 committed Sep 3, 2024
1 parent 73c14ad commit 9893150
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 59 deletions.
8 changes: 3 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
54 changes: 2 additions & 52 deletions src/query/expression/src/types/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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<W: borsh::io::Write>(
obj: &F32,
writer: &mut W,
) -> Result<(), borsh::io::Error> {
writer.write_all(&obj.to_bits().to_le_bytes())?;
Ok(())
}

pub fn deserialize_f32<R: borsh::io::Read>(reader: &mut R) -> Result<F32, borsh::io::Error> {
let mut buf = [0u8; size_of::<F32>()];
reader.read_exact(&mut buf)?;
let res = OrderedFloat::from(f32::from_bits(u32::from_le_bytes(buf)));
Ok(res)
}

pub fn serialize_f64<W: borsh::io::Write>(
obj: &F64,
writer: &mut W,
) -> Result<(), borsh::io::Error> {
writer.write_all(&obj.to_bits().to_le_bytes())?;
Ok(())
}

pub fn deserialize_f64<R: borsh::io::Read>(reader: &mut R) -> Result<F64, borsh::io::Error> {
let mut buf = [0u8; size_of::<F64>()];
reader.read_exact(&mut buf)?;
let res = OrderedFloat::from(f64::from_bits(u64::from_le_bytes(buf)));
Ok(res)
}
}
4 changes: 2 additions & 2 deletions tests/sqllogictests/suites/base/issues/issue_16213.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,4 +30,4 @@ insert into test_inf_nan select 'nan' from numbers(100)
query
select max(a) from test_inf_nan
----
inf
NaN

0 comments on commit 9893150

Please sign in to comment.