use vortex_array::ArrayRef;
use vortex_array::ArrayView;
use vortex_array::IntoArray;
use vortex_array::arrays::filter::FilterReduce;
use vortex_error::VortexResult;
use vortex_mask::Mask;
use crate::DateTimeParts;
use crate::array::DateTimePartsArrayExt;
impl FilterReduce for DateTimeParts {
fn filter(array: ArrayView<'_, Self>, mask: &Mask) -> VortexResult<Option<ArrayRef>> {
Ok(Some(
DateTimeParts::try_new(
array.dtype().clone(),
array.days().filter(mask.clone())?,
array.seconds().filter(mask.clone())?,
array.subseconds().filter(mask.clone())?,
)?
.into_array(),
))
}
}
#[cfg(test)]
mod test {
use vortex_array::IntoArray;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::arrays::TemporalArray;
use vortex_array::compute::conformance::filter::test_filter_conformance;
use vortex_array::extension::datetime::TimeUnit;
use vortex_buffer::buffer;
use crate::DateTimeParts;
#[test]
fn test_filter_datetime_parts() {
let timestamps = buffer![
0i64,
86_400_000, 172_800_000, 259_200_000, 345_600_000, ]
.into_array();
let temporal =
TemporalArray::new_timestamp(timestamps, TimeUnit::Milliseconds, Some("UTC".into()));
let array = DateTimeParts::try_from_temporal(temporal).unwrap();
test_filter_conformance(&array.into_array());
let timestamps = PrimitiveArray::from_option_iter([
Some(0i64),
None,
Some(172_800_000), Some(259_200_000), None,
])
.into_array();
let temporal =
TemporalArray::new_timestamp(timestamps, TimeUnit::Milliseconds, Some("UTC".into()));
let array = DateTimeParts::try_from_temporal(temporal).unwrap();
test_filter_conformance(&array.into_array());
}
}