diff --git a/arrow-cast/src/parse.rs b/arrow-cast/src/parse.rs index ac3b89e0ba02..24f4e0db6a1e 100644 --- a/arrow-cast/src/parse.rs +++ b/arrow-cast/src/parse.rs @@ -433,21 +433,19 @@ pub trait Parser: ArrowPrimitiveType { impl Parser for Float16Type { fn parse(string: &str) -> Option { - lexical_core::parse(string.as_bytes()) - .ok() - .map(f16::from_f32) + string.parse::().ok() } } impl Parser for Float32Type { fn parse(string: &str) -> Option { - lexical_core::parse(string.as_bytes()).ok() + string.parse::().ok() } } impl Parser for Float64Type { fn parse(string: &str) -> Option { - lexical_core::parse(string.as_bytes()).ok() + string.parse::().ok() } } @@ -455,7 +453,7 @@ macro_rules! parser_primitive { ($t:ty) => { impl Parser for $t { fn parse(string: &str) -> Option { - lexical_core::parse::(string.as_bytes()).ok() + string.parse::().ok() } } }; diff --git a/arrow-json/src/reader/primitive_array.rs b/arrow-json/src/reader/primitive_array.rs index c78e4d914060..c8eb5e67bf21 100644 --- a/arrow-json/src/reader/primitive_array.rs +++ b/arrow-json/src/reader/primitive_array.rs @@ -44,9 +44,15 @@ macro_rules! primitive_parse { ($($t:ty),+) => { $(impl ParseJsonNumber for $t { fn parse(s: &[u8]) -> Option { - match lexical_core::parse::(s) { - Ok(f) => Some(f), - Err(_) => lexical_core::parse::(s).ok().and_then(NumCast::from), + match std::str::from_utf8(s) { + Ok(s) => { + if let Ok(res) = s.parse::<$t>() { + Some(res) + } else { + return s.parse::().ok().and_then(NumCast::from) + } + } + Err(_) => None, } } })+ @@ -57,19 +63,28 @@ primitive_parse!(i8, i16, i32, i64, u8, u16, u32, u64); impl ParseJsonNumber for f16 { fn parse(s: &[u8]) -> Option { - lexical_core::parse::(s).ok().map(f16::from_f32) + match std::str::from_utf8(s) { + Ok(s) => s.parse::().ok(), + Err(_) => None, + } } } impl ParseJsonNumber for f32 { fn parse(s: &[u8]) -> Option { - lexical_core::parse::(s).ok() + match std::str::from_utf8(s) { + Ok(s) => s.parse::().ok(), + Err(_) => None, + } } } impl ParseJsonNumber for f64 { fn parse(s: &[u8]) -> Option { - lexical_core::parse::(s).ok() + match std::str::from_utf8(s) { + Ok(s) => s.parse::().ok(), + Err(_) => None, + } } } diff --git a/arrow-json/src/reader/timestamp_array.rs b/arrow-json/src/reader/timestamp_array.rs index ef69deabce2d..3d77e22c459b 100644 --- a/arrow-json/src/reader/timestamp_array.rs +++ b/arrow-json/src/reader/timestamp_array.rs @@ -77,16 +77,15 @@ where } TapeElement::Number(idx) => { let s = tape.get_string(idx); - let b = s.as_bytes(); - let value = lexical_core::parse::(b) - .or_else(|_| lexical_core::parse::(b).map(|x| x as i64)) + let value = s + .parse::() + .or_else(|_| s.parse::().map(|x| x as i64)) .map_err(|_| { ArrowError::JsonError(format!( "failed to parse {s} as {}", self.data_type )) })?; - builder.append_value(value) } _ => return Err(tape.error(*p, "primitive")),