Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ArrowNativeType::FromStr #2775

Merged
merged 2 commits into from Sep 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 1 addition & 9 deletions arrow-buffer/src/native.rs
Expand Up @@ -44,15 +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
+ std::str::FromStr
+ Default
+ private::Sealed
+ 'static
std::fmt::Debug + Send + Sync + Copy + PartialOrd + Default + private::Sealed + 'static
{
/// Convert native type from usize.
#[inline]
Expand Down
1 change: 1 addition & 0 deletions arrow/src/lib.rs
Expand Up @@ -117,6 +117,7 @@
//! fn parse_to_primitive<'a, T, I>(iter: I) -> PrimitiveArray<T>
//! where
//! T: ArrowPrimitiveType,
//! T::Native: FromStr,
//! I: IntoIterator<Item=&'a str>,
//! {
//! PrimitiveArray::from_iter(iter.into_iter().map(|val| T::Native::from_str(val).ok()))
Expand Down
47 changes: 22 additions & 25 deletions arrow/src/util/reader_parser.rs
Expand Up @@ -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<Self::Native> {
string.parse::<Self::Native>().ok()
}
fn parse(string: &str) -> Option<Self::Native>;

fn parse_formatted(string: &str, _format: &str) -> Option<Self::Native> {
Self::parse(string)
Expand All @@ -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<Self::Native> {
string.parse::<Self::Native>().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<i64> {
Expand Down Expand Up @@ -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;
Expand Down