Skip to content

Commit

Permalink
refactor: simplify hour_dyn() with time_fraction_dyn() (#4588)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackwener authored Jul 30, 2023
1 parent 2adb64d commit 1e0f02f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 21 deletions.
21 changes: 1 addition & 20 deletions arrow-arith/src/temporal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,26 +181,7 @@ pub fn using_chrono_tz_and_utc_naive_date_time(
/// the range of [0, 23]. If the given array isn't temporal primitive or dictionary array,
/// an `Err` will be returned.
pub fn hour_dyn(array: &dyn Array) -> Result<ArrayRef, ArrowError> {
match array.data_type().clone() {
DataType::Dictionary(_, _) => {
downcast_dictionary_array!(
array => {
let hour_values = hour_dyn(array.values())?;
Ok(Arc::new(array.with_values(&hour_values)))
}
dt => return_compute_error_with!("hour does not support", dt),
)
}
_ => {
downcast_temporal_array!(
array => {
hour(array)
.map(|a| Arc::new(a) as ArrayRef)
}
dt => return_compute_error_with!("hour does not support", dt),
)
}
}
time_fraction_dyn(array, "hour", |t| t.hour() as i32)
}

/// Extracts the hours of a given temporal primitive array as an array of integers within
Expand Down
2 changes: 1 addition & 1 deletion arrow-array/src/array/string_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pub type StringArray = GenericStringArray<i32>;
/// let arr: LargeStringArray = std::iter::repeat(Some("foo")).take(10).collect();
/// ```
///
/// Constructon and Access
/// Construction and Access
///
/// ```
/// use arrow_array::LargeStringArray;
Expand Down

0 comments on commit 1e0f02f

Please sign in to comment.