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