diff --git a/arrow/src/compute/kernels/temporal.rs b/arrow/src/compute/kernels/temporal.rs index 94ddc95c759..c94e21a1b2e 100644 --- a/arrow/src/compute/kernels/temporal.rs +++ b/arrow/src/compute/kernels/temporal.rs @@ -175,16 +175,6 @@ pub fn using_chrono_tz_and_utc_naive_date_time( Some(tz.offset_from_utc_datetime(&utc).fix()) } -/// Extracts the hours of a given temporal primitive array as an array of integers within -/// the range of [0, 23]. -pub fn hour(array: &PrimitiveArray) -> Result -where - T: ArrowTemporalType + ArrowNumericType, - i64: From, -{ - hour_internal(array) -} - /// Extracts the hours of a given array as an array of integers within /// the range of [0, 23]. If the given array isn't temporal primitive or dictionary array, /// an `Err` will be returned. @@ -202,7 +192,7 @@ pub fn hour_dyn(array: &dyn Array) -> Result { _ => { downcast_temporal_array!( array => { - hour_internal(array) + hour(array) .map(|a| Arc::new(a) as ArrayRef) } dt => return_compute_error_with!("hour does not support", dt), @@ -211,8 +201,9 @@ pub fn hour_dyn(array: &dyn Array) -> Result { } } -/// Extracts the hours of a given temporal array as an array of integers -fn hour_internal(array: &PrimitiveArray) -> Result +/// Extracts the hours of a given temporal primitive array as an array of integers within +/// the range of [0, 23]. +pub fn hour(array: &PrimitiveArray) -> Result where T: ArrowTemporalType + ArrowNumericType, i64: From, @@ -246,15 +237,6 @@ where } } -/// Extracts the years of a given temporal primitive array as an array of integers -pub fn year(array: &PrimitiveArray) -> Result -where - T: ArrowTemporalType + ArrowNumericType, - i64: From, -{ - year_internal(array) -} - /// Extracts the years of a given temporal array as an array of integers. /// If the given array isn't temporal primitive or dictionary array, /// an `Err` will be returned. @@ -272,7 +254,7 @@ pub fn year_dyn(array: &dyn Array) -> Result { _ => { downcast_temporal_array!( array => { - year_internal(array) + year(array) .map(|a| Arc::new(a) as ArrayRef) } dt => return_compute_error_with!("year does not support", dt), @@ -281,8 +263,8 @@ pub fn year_dyn(array: &dyn Array) -> Result { } } -/// Extracts the years of a given temporal array as an array of integers -fn year_internal(array: &PrimitiveArray) -> Result +/// Extracts the years of a given temporal primitive array as an array of integers +pub fn year(array: &PrimitiveArray) -> Result where T: ArrowTemporalType + ArrowNumericType, i64: From, @@ -301,16 +283,6 @@ where } } -/// Extracts the quarter of a given temporal primitive array as an array of integers within -/// the range of [1, 4]. -pub fn quarter(array: &PrimitiveArray) -> Result -where - T: ArrowTemporalType + ArrowNumericType, - i64: From, -{ - quarter_internal(array) -} - /// Extracts the quarter of a given temporal array as an array of integersa within /// the range of [1, 4]. If the given array isn't temporal primitive or dictionary array, /// an `Err` will be returned. @@ -328,7 +300,7 @@ pub fn quarter_dyn(array: &dyn Array) -> Result { _ => { downcast_temporal_array!( array => { - quarter_internal(array) + quarter(array) .map(|a| Arc::new(a) as ArrayRef) } dt => return_compute_error_with!("quarter does not support", dt), @@ -337,8 +309,9 @@ pub fn quarter_dyn(array: &dyn Array) -> Result { } } -/// Extracts the quarter of a given temporal array as an array of integers -fn quarter_internal(array: &PrimitiveArray) -> Result +/// Extracts the quarter of a given temporal primitive array as an array of integers within +/// the range of [1, 4]. +pub fn quarter(array: &PrimitiveArray) -> Result where T: ArrowTemporalType + ArrowNumericType, i64: From, @@ -361,16 +334,6 @@ where } } -/// Extracts the month of a given temporal primitive array as an array of integers within -/// the range of [1, 12]. -pub fn month(array: &PrimitiveArray) -> Result -where - T: ArrowTemporalType + ArrowNumericType, - i64: From, -{ - month_internal(array) -} - /// Extracts the month of a given temporal array as an array of integers. /// If the given array isn't temporal primitive or dictionary array, /// an `Err` will be returned. @@ -388,7 +351,7 @@ pub fn month_dyn(array: &dyn Array) -> Result { _ => { downcast_temporal_array!( array => { - month_internal(array) + month(array) .map(|a| Arc::new(a) as ArrayRef) } dt => return_compute_error_with!("month does not support", dt), @@ -397,8 +360,9 @@ pub fn month_dyn(array: &dyn Array) -> Result { } } -/// Extracts the month of a given temporal array as an array of integers -fn month_internal(array: &PrimitiveArray) -> Result +/// Extracts the month of a given temporal primitive array as an array of integers within +/// the range of [1, 12]. +pub fn month(array: &PrimitiveArray) -> Result where T: ArrowTemporalType + ArrowNumericType, i64: From, @@ -421,20 +385,6 @@ where } } -/// Extracts the day of week of a given temporal primitive array as an array of -/// integers. -/// -/// Monday is encoded as `0`, Tuesday as `1`, etc. -/// -/// See also [`num_days_from_sunday`] which starts at Sunday. -pub fn num_days_from_monday(array: &PrimitiveArray) -> Result -where - T: ArrowTemporalType + ArrowNumericType, - i64: From, -{ - num_days_from_monday_internal(array) -} - /// Extracts the day of week of a given temporal array as an array of /// integers. /// @@ -458,7 +408,7 @@ pub fn num_days_from_monday_dyn(array: &dyn Array) -> Result { _ => { downcast_temporal_array!( array => { - num_days_from_monday_internal(array) + num_days_from_monday(array) .map(|a| Arc::new(a) as ArrayRef) } dt => return_compute_error_with!("num_days_from_monday does not support", dt), @@ -467,13 +417,13 @@ pub fn num_days_from_monday_dyn(array: &dyn Array) -> Result { } } -/// Extracts the day of week of a given temporal array as an array of +/// Extracts the day of week of a given temporal primitive array as an array of /// integers. /// /// Monday is encoded as `0`, Tuesday as `1`, etc. /// /// See also [`num_days_from_sunday`] which starts at Sunday. -fn num_days_from_monday_internal(array: &PrimitiveArray) -> Result +pub fn num_days_from_monday(array: &PrimitiveArray) -> Result where T: ArrowTemporalType + ArrowNumericType, i64: From, @@ -496,20 +446,6 @@ where } } -/// Extracts the day of week of a given temporal primitive array as an array of -/// integers, starting at Sunday. -/// -/// Sunday is encoded as `0`, Monday as `1`, etc. -/// -/// See also [`num_days_from_monday`] which starts at Monday. -pub fn num_days_from_sunday(array: &PrimitiveArray) -> Result -where - T: ArrowTemporalType + ArrowNumericType, - i64: From, -{ - num_days_from_sunday_internal(array) -} - /// Extracts the day of week of a given temporal array as an array of /// integers, starting at Sunday. /// @@ -533,7 +469,7 @@ pub fn num_days_from_sunday_dyn(array: &dyn Array) -> Result { _ => { downcast_temporal_array!( array => { - num_days_from_sunday_internal(array) + num_days_from_sunday(array) .map(|a| Arc::new(a) as ArrayRef) } dt => return_compute_error_with!("num_days_from_sunday does not support", dt), @@ -542,13 +478,13 @@ pub fn num_days_from_sunday_dyn(array: &dyn Array) -> Result { } } -/// Extracts the day of week of a given temporal array as an array of +/// Extracts the day of week of a given temporal primitive array as an array of /// integers, starting at Sunday. /// /// Sunday is encoded as `0`, Monday as `1`, etc. /// /// See also [`num_days_from_monday`] which starts at Monday. -fn num_days_from_sunday_internal(array: &PrimitiveArray) -> Result +pub fn num_days_from_sunday(array: &PrimitiveArray) -> Result where T: ArrowTemporalType + ArrowNumericType, i64: From, @@ -574,15 +510,6 @@ where } } -/// Extracts the day of a given temporal primitive array as an array of integers -pub fn day(array: &PrimitiveArray) -> Result -where - T: ArrowTemporalType + ArrowNumericType, - i64: From, -{ - day_internal(array) -} - /// Extracts the day of a given temporal array as an array of integers. /// If the given array isn't temporal primitive or dictionary array, /// an `Err` will be returned. @@ -600,7 +527,7 @@ pub fn day_dyn(array: &dyn Array) -> Result { _ => { downcast_temporal_array!( array => { - day_internal(array) + day(array) .map(|a| Arc::new(a) as ArrayRef) } dt => return_compute_error_with!("day does not support", dt), @@ -609,8 +536,8 @@ pub fn day_dyn(array: &dyn Array) -> Result { } } -/// Extracts the day of a given temporal array as an array of integers -fn day_internal(array: &PrimitiveArray) -> Result +/// Extracts the day of a given temporal primitive array as an array of integers +pub fn day(array: &PrimitiveArray) -> Result where T: ArrowTemporalType + ArrowNumericType, i64: From, @@ -631,16 +558,6 @@ where } } -/// Extracts the day of year of a given temporal primitive array as an array of integers -/// The day of year that ranges from 1 to 366 -pub fn doy(array: &PrimitiveArray) -> Result -where - T: ArrowTemporalType + ArrowNumericType, - i64: From, -{ - doy_internal(array) -} - /// Extracts the day of year of a given temporal array as an array of integers /// The day of year that ranges from 1 to 366. /// If the given array isn't temporal primitive or dictionary array, @@ -659,7 +576,7 @@ pub fn doy_dyn(array: &dyn Array) -> Result { _ => { downcast_temporal_array!( array => { - doy_internal(array) + doy(array) .map(|a| Arc::new(a) as ArrayRef) } dt => return_compute_error_with!("doy does not support", dt), @@ -668,9 +585,9 @@ pub fn doy_dyn(array: &dyn Array) -> Result { } } -/// Extracts the day of year of a given temporal array as an array of integers +/// Extracts the day of year of a given temporal primitive array as an array of integers /// The day of year that ranges from 1 to 366 -fn doy_internal(array: &PrimitiveArray) -> Result +pub fn doy(array: &PrimitiveArray) -> Result where T: ArrowTemporalType + ArrowNumericType, T::Native: ArrowNativeType, @@ -703,15 +620,6 @@ where time_fraction_internal(array, "minute", |t| t.minute() as i32) } -/// Extracts the week of a given temporal primitive array as an array of integers -pub fn week(array: &PrimitiveArray) -> Result -where - T: ArrowTemporalType + ArrowNumericType, - i64: From, -{ - week_internal(array) -} - /// Extracts the week of a given temporal array as an array of integers. /// If the given array isn't temporal primitive or dictionary array, /// an `Err` will be returned. @@ -729,7 +637,7 @@ pub fn week_dyn(array: &dyn Array) -> Result { _ => { downcast_temporal_array!( array => { - week_internal(array) + week(array) .map(|a| Arc::new(a) as ArrayRef) } dt => return_compute_error_with!("week does not support", dt), @@ -738,8 +646,8 @@ pub fn week_dyn(array: &dyn Array) -> Result { } } -/// Extracts the week of a given temporal array as an array of integers -fn week_internal(array: &PrimitiveArray) -> Result +/// Extracts the week of a given temporal primitive array as an array of integers +pub fn week(array: &PrimitiveArray) -> Result where T: ArrowTemporalType + ArrowNumericType, i64: From,