From 21ecf99db7dcf7e35d65fd71d02d94a3db32098b Mon Sep 17 00:00:00 2001 From: Raphael Taylor-Davies Date: Sat, 24 Sep 2022 10:55:45 +0100 Subject: [PATCH 1/2] Remove ArrowNativeType: FromStr --- arrow-buffer/src/native.rs | 1 - arrow/src/lib.rs | 1 + arrow/src/util/reader_parser.rs | 47 +++++++++++++++------------------ 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/arrow-buffer/src/native.rs b/arrow-buffer/src/native.rs index d8431953c43..c6bf809d45e 100644 --- a/arrow-buffer/src/native.rs +++ b/arrow-buffer/src/native.rs @@ -49,7 +49,6 @@ pub trait ArrowNativeType: + Sync + Copy + PartialOrd - + std::str::FromStr + Default + private::Sealed + 'static diff --git a/arrow/src/lib.rs b/arrow/src/lib.rs index 5cc264b1392..ce171ec861a 100644 --- a/arrow/src/lib.rs +++ b/arrow/src/lib.rs @@ -117,6 +117,7 @@ //! fn parse_to_primitive<'a, T, I>(iter: I) -> PrimitiveArray //! where //! T: ArrowPrimitiveType, +//! T::Native: FromStr, //! I: IntoIterator, //! { //! PrimitiveArray::from_iter(iter.into_iter().map(|val| T::Native::from_str(val).ok())) diff --git a/arrow/src/util/reader_parser.rs b/arrow/src/util/reader_parser.rs index 6b6f24f82a4..91b362df86f 100644 --- a/arrow/src/util/reader_parser.rs +++ b/arrow/src/util/reader_parser.rs @@ -21,9 +21,7 @@ use crate::datatypes::*; /// Specialized parsing implementations /// used by csv and json reader pub(crate) trait Parser: ArrowPrimitiveType { - fn parse(string: &str) -> Option { - string.parse::().ok() - } + fn parse(string: &str) -> Option; fn parse_formatted(string: &str, _format: &str) -> Option { Self::parse(string) @@ -42,21 +40,23 @@ impl Parser for Float64Type { } } -impl Parser for UInt64Type {} - -impl Parser for UInt32Type {} - -impl Parser for UInt16Type {} - -impl Parser for UInt8Type {} - -impl Parser for Int64Type {} - -impl Parser for Int32Type {} - -impl Parser for Int16Type {} - -impl Parser for Int8Type {} +macro_rules! parser_primitive { + ($t:ty) => { + impl Parser for $t { + fn parse(string: &str) -> Option { + string.parse::().ok() + } + } + }; +} +parser_primitive!(UInt64Type); +parser_primitive!(UInt32Type); +parser_primitive!(UInt16Type); +parser_primitive!(UInt8Type); +parser_primitive!(Int64Type); +parser_primitive!(Int32Type); +parser_primitive!(Int16Type); +parser_primitive!(Int8Type); impl Parser for TimestampNanosecondType { fn parse(string: &str) -> Option { @@ -85,13 +85,10 @@ impl Parser for TimestampSecondType { } } -impl Parser for Time64NanosecondType {} - -impl Parser for Time64MicrosecondType {} - -impl Parser for Time32MillisecondType {} - -impl Parser for Time32SecondType {} +parser_primitive!(Time64NanosecondType); +parser_primitive!(Time64MicrosecondType); +parser_primitive!(Time32MillisecondType); +parser_primitive!(Time32SecondType); /// Number of days between 0001-01-01 and 1970-01-01 const EPOCH_DAYS_FROM_CE: i32 = 719_163; From 8307cb220ef91f24e5d39aa48d42efa0ba8f7de3 Mon Sep 17 00:00:00 2001 From: Raphael Taylor-Davies Date: Sat, 24 Sep 2022 11:18:49 +0100 Subject: [PATCH 2/2] Format --- arrow-buffer/src/native.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/arrow-buffer/src/native.rs b/arrow-buffer/src/native.rs index c6bf809d45e..90855872d18 100644 --- a/arrow-buffer/src/native.rs +++ b/arrow-buffer/src/native.rs @@ -44,14 +44,7 @@ mod private { /// /// Due to the above restrictions, this trait is sealed to prevent accidental misuse pub trait ArrowNativeType: - std::fmt::Debug - + Send - + Sync - + Copy - + PartialOrd - + Default - + private::Sealed - + 'static + std::fmt::Debug + Send + Sync + Copy + PartialOrd + Default + private::Sealed + 'static { /// Convert native type from usize. #[inline]