From bca2f3ab9f649d4f45674d1fb629f1e3068a8480 Mon Sep 17 00:00:00 2001 From: Matthijs Brobbel Date: Tue, 4 Jun 2024 20:02:51 +0200 Subject: [PATCH] Derive `Copy` for `TimeUnit` and `IntervalUnit` (#5840) * Derive `Copy` for `TimeUnit` and `IntervalUnit` * Fix clippy warnings * Rustfmt --- arrow-cast/src/cast/mod.rs | 10 +++------- arrow-schema/src/datatype.rs | 4 ++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/arrow-cast/src/cast/mod.rs b/arrow-cast/src/cast/mod.rs index df7dc3bc73d0..ae2240bd9404 100644 --- a/arrow-cast/src/cast/mod.rs +++ b/arrow-cast/src/cast/mod.rs @@ -1660,7 +1660,7 @@ pub fn cast_with_options( let array = cast_with_options(array, &Int64, cast_options)?; Ok(make_timestamp_array( array.as_primitive(), - unit.clone(), + *unit, tz.clone(), )) } @@ -1721,11 +1721,7 @@ pub fn cast_with_options( } _ => converted, }; - Ok(make_timestamp_array( - &adjusted, - to_unit.clone(), - to_tz.clone(), - )) + Ok(make_timestamp_array(&adjusted, *to_unit, to_tz.clone())) } (Timestamp(TimeUnit::Microsecond, _), Date32) => { timestamp_to_date32(array.as_primitive::()) @@ -4020,7 +4016,7 @@ mod tests { TimeUnit::Microsecond, TimeUnit::Nanosecond, ] { - let to_type = DataType::Timestamp(time_unit.clone(), None); + let to_type = DataType::Timestamp(*time_unit, None); let b = cast(array, &to_type).unwrap(); match time_unit { diff --git a/arrow-schema/src/datatype.rs b/arrow-schema/src/datatype.rs index 449d363db671..049a4130c5ee 100644 --- a/arrow-schema/src/datatype.rs +++ b/arrow-schema/src/datatype.rs @@ -327,7 +327,7 @@ pub enum DataType { } /// An absolute length of time in seconds, milliseconds, microseconds or nanoseconds. -#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum TimeUnit { /// Time in seconds. @@ -341,7 +341,7 @@ pub enum TimeUnit { } /// YEAR_MONTH, DAY_TIME, MONTH_DAY_NANO interval in SQL style. -#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum IntervalUnit { /// Indicates the number of elapsed whole months, stored as 4-byte integers.