Skip to content

Commit

Permalink
add weekday temporal kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
nl5887 committed Jun 16, 2022
1 parent 8d787d9 commit b510a7d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions arrow/src/compute/kernels/temporal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,35 @@ where
Ok(b.finish())
}

/// Extracts the day of week of a given temporal array as an array of integers
pub fn weekday<T>(array: &PrimitiveArray<T>) -> Result<Int32Array>
where
T: ArrowTemporalType + ArrowNumericType,
i64: std::convert::From<T::Native>,
{
let mut b = Int32Builder::new(array.len());
match array.data_type() {
&DataType::Date32 | &DataType::Date64 | &DataType::Timestamp(_, None) => {
extract_component_from_array!(array, b, weekday, value_as_datetime)
}
&DataType::Timestamp(_, Some(ref tz)) => {
let mut scratch = Parsed::new();
extract_component_from_array!(
array,
b,
weekday,
value_as_datetime_with_tz,
tz,
scratch
)
}
dt => return_compute_error_with!("weekday does not support", dt),
}

Ok(b.finish())
}


/// Extracts the day of a given temporal array as an array of integers
pub fn day<T>(array: &PrimitiveArray<T>) -> Result<Int32Array>
where
Expand Down

0 comments on commit b510a7d

Please sign in to comment.