44//! Splits temporal arrays into components for independent compression.
55//!
66//! The split keeps days in `i32` when possible and widens only that component to `i64` for extreme
7- //! second or millisecond timestamps. Null slots do not restrict the range of an array.
7+ //! second or millisecond timestamps. The split checks the computed days as it writes the narrow
8+ //! buffer. If any day exceeds `i32`, it checks the non-null days before keeping a wide buffer.
9+ //! Null slots do not restrict the range of an array.
810
911use std:: mem:: MaybeUninit ;
1012
@@ -16,16 +18,12 @@ use vortex_array::aggregate_fn::NumericalAggregateOpts;
1618use vortex_array:: aggregate_fn:: fns:: min_max:: MinMaxResult ;
1719use vortex_array:: aggregate_fn:: fns:: min_max:: min_max;
1820use vortex_array:: arrays:: ConstantArray ;
19- use vortex_array:: arrays:: ExtensionArray ;
2021use vortex_array:: arrays:: PrimitiveArray ;
2122use vortex_array:: arrays:: TemporalArray ;
2223use vortex_array:: builtins:: ArrayBuiltins ;
2324use vortex_array:: dtype:: DType ;
2425use vortex_array:: dtype:: PType ;
25- use vortex_array:: expr:: stats:: Stat ;
26- use vortex_array:: expr:: stats:: StatsProvider ;
2726use vortex_array:: extension:: datetime:: TimeUnit ;
28- use vortex_array:: scalar:: Scalar ;
2927use vortex_buffer:: Buffer ;
3028use vortex_buffer:: BufferMut ;
3129use vortex_error:: VortexResult ;
@@ -59,8 +57,6 @@ pub fn split_temporal(array: TemporalArray, ctx: &mut ExecutionCtx) -> VortexRes
5957 vortex_bail ! ( "Cannot handle day-level data" ) ;
6058 }
6159
62- let check_days = !cached_bounds ( & array) . is_some_and ( |bounds| bounds_fit ( & bounds, time_unit) ) ;
63-
6460 let temporal_values = array
6561 . temporal_values ( )
6662 . clone ( )
@@ -88,11 +84,7 @@ pub fn split_temporal(array: TemporalArray, ctx: &mut ExecutionCtx) -> VortexRes
8884 let seconds_ptr = & mut seconds. spare_capacity_mut ( ) [ ..length] ;
8985
9086 if matches ! ( time_unit, TimeUnit :: Seconds ) {
91- let all_fit = if check_days {
92- split_slice_seconds :: < true > ( days_ptr, seconds_ptr, timestamps)
93- } else {
94- split_slice_seconds :: < false > ( days_ptr, seconds_ptr, timestamps)
95- } ;
87+ let all_fit = split_slice_seconds ( days_ptr, seconds_ptr, timestamps) ;
9688
9789 // SAFETY: `split_slice_seconds` initialized all `length` elements of both buffers.
9890 unsafe {
@@ -118,16 +110,13 @@ pub fn split_temporal(array: TemporalArray, ctx: &mut ExecutionCtx) -> VortexRes
118110
119111 let all_fit = match time_unit {
120112 TimeUnit :: Nanoseconds => {
121- split_slice :: < 1_000_000_000 , false > ( days_ptr, seconds_ptr, subseconds_ptr, timestamps)
113+ split_slice :: < 1_000_000_000 > ( days_ptr, seconds_ptr, subseconds_ptr, timestamps)
122114 }
123115 TimeUnit :: Microseconds => {
124- split_slice :: < 1_000_000 , false > ( days_ptr, seconds_ptr, subseconds_ptr, timestamps)
125- }
126- TimeUnit :: Milliseconds if check_days => {
127- split_slice :: < 1_000 , true > ( days_ptr, seconds_ptr, subseconds_ptr, timestamps)
116+ split_slice :: < 1_000_000 > ( days_ptr, seconds_ptr, subseconds_ptr, timestamps)
128117 }
129118 TimeUnit :: Milliseconds => {
130- split_slice :: < 1_000 , false > ( days_ptr, seconds_ptr, subseconds_ptr, timestamps)
119+ split_slice :: < 1_000 > ( days_ptr, seconds_ptr, subseconds_ptr, timestamps)
131120 }
132121 _ => unreachable ! ( "Handled before" ) ,
133122 } ;
@@ -186,33 +175,6 @@ fn widen_days_if_needed(
186175 Ok ( if fits { days. into_array ( ) } else { wide_days } )
187176}
188177
189- /// Exact min and max cached on the array, which the layout writer computes before compressing.
190- fn cached_bounds ( array : & TemporalArray ) -> Option < [ Scalar ; 2 ] > {
191- let ext = ExtensionArray :: from ( array) ;
192- let stats = ext. statistics ( ) ;
193- if let ( Some ( min) , Some ( max) ) = (
194- stats. get ( Stat :: Min ) . as_exact ( ) ,
195- stats. get ( Stat :: Max ) . as_exact ( ) ,
196- ) {
197- return Some ( [ min, max] . map ( |bound| bound. as_extension ( ) . to_storage_scalar ( ) ) ) ;
198- }
199-
200- let stats = array. temporal_values ( ) . statistics ( ) ;
201- let min = stats. get ( Stat :: Min ) . as_exact ( ) ?;
202- let max = stats. get ( Stat :: Max ) . as_exact ( ) ?;
203-
204- Some ( [ min, max] )
205- }
206-
207- fn bounds_fit ( bounds : & [ Scalar ; 2 ] , time_unit : TimeUnit ) -> bool {
208- bounds. iter ( ) . all ( |bound| {
209- bound
210- . as_primitive ( )
211- . as_ :: < i64 > ( )
212- . is_some_and ( |ts| timestamp:: days_fit_i32 ( ts, time_unit) )
213- } )
214- }
215-
216178/// Adds 2^31 to the days and converts to unsigned, placing in-range days below 2^32.
217179///
218180/// An out-of-range value sets a bit above bit 31. OR-ing the offsets preserves those bits, so the
@@ -224,9 +186,9 @@ fn day_offset(days: i64) -> u64 {
224186
225187/// Initializes all three output slices and reports whether the days fit `i32`.
226188///
227- /// The slices must have the same length. With `CHECK_DAYS` disabled, always returns `true`.
189+ /// The slices must have the same length.
228190#[ inline]
229- fn split_slice < const DIVISOR : i64 , const CHECK_DAYS : bool > (
191+ fn split_slice < const DIVISOR : i64 > (
230192 days : & mut [ MaybeUninit < i32 > ] ,
231193 seconds : & mut [ MaybeUninit < i32 > ] ,
232194 subseconds : & mut [ MaybeUninit < i32 > ] ,
@@ -249,9 +211,7 @@ fn split_slice<const DIVISOR: i64, const CHECK_DAYS: bool>(
249211 let mut subsecond_buf = [ 0i32 ; 4 ] ;
250212 for k in 0 ..4 {
251213 let parts = timestamp:: split_with_divisor :: < DIVISOR > ( timestamp[ k] ) ;
252- if CHECK_DAYS {
253- day_offsets |= day_offset ( parts. days ) ;
254- }
214+ day_offsets |= day_offset ( parts. days ) ;
255215 day_buf[ k] = parts. days . as_ ( ) ;
256216 second_buf[ k] = parts. seconds ;
257217 subsecond_buf[ k] = parts. subseconds ;
@@ -270,9 +230,7 @@ fn split_slice<const DIVISOR: i64, const CHECK_DAYS: bool>(
270230 . zip ( subseconds_rem) ;
271231 for ( ( ( & ts, day) , second) , subsecond) in remainder {
272232 let parts = timestamp:: split_with_divisor :: < DIVISOR > ( ts) ;
273- if CHECK_DAYS {
274- day_offsets |= day_offset ( parts. days ) ;
275- }
233+ day_offsets |= day_offset ( parts. days ) ;
276234 day. write ( parts. days . as_ ( ) ) ;
277235 second. write ( parts. seconds ) ;
278236 subsecond. write ( parts. subseconds ) ;
@@ -283,20 +241,17 @@ fn split_slice<const DIVISOR: i64, const CHECK_DAYS: bool>(
283241
284242/// Initializes the days and seconds slices for second timestamps.
285243///
286- /// The slices must have the same length. With `CHECK_DAYS` enabled, reports whether all days fit
287- /// `i32`. Otherwise returns `true`.
244+ /// The slices must have the same length. Returns whether all days fit `i32`.
288245#[ inline]
289- fn split_slice_seconds < const CHECK_DAYS : bool > (
246+ fn split_slice_seconds (
290247 days : & mut [ MaybeUninit < i32 > ] ,
291248 seconds : & mut [ MaybeUninit < i32 > ] ,
292249 timestamps : & [ i64 ] ,
293250) -> bool {
294251 let mut day_offsets = 0u64 ;
295252 for ( ( day, second) , ts) in days. iter_mut ( ) . zip ( seconds) . zip ( timestamps) {
296253 let parts = timestamp:: split_with_divisor :: < 1 > ( * ts) ;
297- if CHECK_DAYS {
298- day_offsets |= day_offset ( parts. days ) ;
299- }
254+ day_offsets |= day_offset ( parts. days ) ;
300255 day. write ( parts. days . as_ ( ) ) ;
301256 second. write ( parts. seconds ) ;
302257 }
@@ -313,8 +268,6 @@ mod tests {
313268 use vortex_array:: ArrayContext ;
314269 use vortex_array:: IntoArray ;
315270 use vortex_array:: VortexSessionExecute ;
316- use vortex_array:: aggregate_fn:: NumericalAggregateOpts ;
317- use vortex_array:: aggregate_fn:: fns:: min_max:: min_max;
318271 use vortex_array:: arrays:: PrimitiveArray ;
319272 use vortex_array:: arrays:: TemporalArray ;
320273 use vortex_array:: assert_arrays_eq;
@@ -330,7 +283,6 @@ mod tests {
330283 use vortex_session:: VortexSession ;
331284 use vortex_session:: registry:: ReadContext ;
332285
333- use super :: cached_bounds;
334286 use crate :: DateTimeParts ;
335287 use crate :: TemporalParts ;
336288 use crate :: array:: DateTimePartsArraySlotsExt ;
@@ -418,7 +370,6 @@ mod tests {
418370 fn test_extreme_timestamps_roundtrip (
419371 #[ case] unit : TimeUnit ,
420372 #[ case] days_ptype : PType ,
421- #[ values( false , true ) ] cache_bounds : bool ,
422373 ) -> VortexResult < ( ) > {
423374 let mut ctx = SESSION . create_execution_ctx ( ) ;
424375 let temporal = TemporalArray :: new_timestamp (
@@ -433,10 +384,6 @@ mod tests {
433384 Some ( "UTC" . into ( ) ) ,
434385 ) ;
435386 let expected = temporal. clone ( ) . into_array ( ) ;
436- if cache_bounds {
437- min_max ( & expected, & mut ctx, NumericalAggregateOpts :: default ( ) ) ?;
438- }
439- assert_eq ! ( cached_bounds( & temporal) . is_some( ) , cache_bounds) ;
440387
441388 let parts = DateTimeParts :: try_from_temporal ( temporal, & mut ctx) ?;
442389 assert_eq ! ( parts. days( ) . dtype( ) . as_ptype( ) , days_ptype) ;
@@ -479,7 +426,6 @@ mod tests {
479426 fn test_days_at_i32_bounds (
480427 #[ case] unit : TimeUnit ,
481428 #[ case] ticks_per_second : i64 ,
482- #[ values( false , true ) ] cache_bounds : bool ,
483429 ) -> VortexResult < ( ) > {
484430 let mut ctx = SESSION . create_execution_ctx ( ) ;
485431 let ticks_per_day = SECONDS_PER_DAY * ticks_per_second;
@@ -490,13 +436,6 @@ mod tests {
490436 TemporalArray :: new_timestamp ( PrimitiveArray :: from_iter ( values) . into_array ( ) , unit, None )
491437 } ;
492438 let fits = temporal ( vec ! [ max, 0 , min, max, min, 0 , max, min, max] ) ;
493- if cache_bounds {
494- min_max (
495- & fits. clone ( ) . into_array ( ) ,
496- & mut ctx,
497- NumericalAggregateOpts :: default ( ) ,
498- ) ?;
499- }
500439 let parts = DateTimeParts :: try_from_temporal ( fits. clone ( ) , & mut ctx) ?;
501440 assert_eq ! ( parts. days( ) . dtype( ) . as_ptype( ) , PType :: I32 ) ;
502441 assert_arrays_eq ! ( parts, fits, & mut ctx) ;
0 commit comments