Function arrow_arith::temporal::date_part

source ·
pub fn date_part(
    array: &dyn Array,
    part: DatePart,
) -> Result<ArrayRef, ArrowError>
Expand description

Given an array, return a new array with the extracted DatePart as signed 32-bit integer values.

Currently only supports temporal types:

  • Date32/Date64
  • Time32/Time64
  • Timestamp
  • Interval
  • Duration

Returns an Int32Array unless input was a dictionary type, in which case returns the dictionary but with this function applied onto its values.

If array passed in is not of the above listed types (or is a dictionary array where the values array isn’t of the above listed types), then this function will return an error.

§Examples

let input: TimestampMicrosecondArray =
    vec![Some(1612025847000000), None, Some(1722015847000000)].into();

let actual = date_part(&input, DatePart::Week).unwrap();
let expected: Int32Array = vec![Some(4), None, Some(30)].into();
assert_eq!(actual.as_ref(), &expected);