vortex_btrblocks/
temporal.rs1use vortex_array::arrays::TemporalArray;
4use vortex_array::compress::downscale_integer_array;
5use vortex_array::{ArrayRef, IntoArray, ToCanonical};
6use vortex_datetime_parts::{DateTimePartsArray, TemporalParts, split_temporal};
7use vortex_error::VortexResult;
8
9use crate::integer::IntCompressor;
10use crate::{Compressor, MAX_CASCADE};
11
12pub fn compress_temporal(array: TemporalArray) -> VortexResult<ArrayRef> {
14 let dtype = array.dtype().clone();
15 let TemporalParts {
16 days,
17 seconds,
18 subseconds,
19 } = split_temporal(array)?;
20
21 let days = IntCompressor::compress(
22 &downscale_integer_array(days)?.to_primitive()?,
23 false,
24 MAX_CASCADE - 1,
25 &[],
26 )?;
27 let seconds = IntCompressor::compress(
28 &downscale_integer_array(seconds)?.to_primitive()?,
29 false,
30 MAX_CASCADE - 1,
31 &[],
32 )?;
33 let subseconds = IntCompressor::compress(
34 &downscale_integer_array(subseconds)?.to_primitive()?,
35 false,
36 MAX_CASCADE - 1,
37 &[],
38 )?;
39
40 Ok(DateTimePartsArray::try_new(dtype, days, seconds, subseconds)?.into_array())
41}