33
44//! Integer compression schemes.
55
6+ use std:: env;
7+ use std:: sync:: LazyLock ;
8+
69use vortex_array:: ArrayRef ;
710use vortex_array:: Canonical ;
811use vortex_array:: IntoArray ;
12+ use vortex_array:: LEGACY_SESSION ;
913use vortex_array:: ToCanonical ;
14+ use vortex_array:: VortexSessionExecute ;
1015use vortex_array:: arrays:: ConstantArray ;
16+ use vortex_array:: arrays:: Patched ;
1117use vortex_array:: arrays:: primitive:: PrimitiveArrayExt ;
1218use vortex_array:: scalar:: Scalar ;
1319use vortex_compressor:: builtins:: FloatDictScheme ;
@@ -19,7 +25,7 @@ use vortex_error::VortexExpect;
1925use vortex_error:: VortexResult ;
2026use vortex_error:: vortex_bail;
2127use vortex_error:: vortex_err;
22- use vortex_fastlanes:: BitPackedArrayExt ;
28+ use vortex_fastlanes:: BitPacked ;
2329use vortex_fastlanes:: FoR ;
2430use vortex_fastlanes:: FoRArrayExt ;
2531use vortex_fastlanes:: bitpack_compress:: bit_width_histogram;
@@ -294,6 +300,10 @@ impl Scheme for ZigZagScheme {
294300 }
295301}
296302
303+ // replicated from vortex-file
304+ static USE_EXPERIMENTAL_PATCHES : LazyLock < bool > =
305+ LazyLock :: new ( || env:: var ( "VORTEX_EXPERIMENTAL_PATCHED_ARRAY" ) . is_ok ( ) ) ;
306+
297307impl Scheme for BitPackingScheme {
298308 fn scheme_name ( & self ) -> & ' static str {
299309 "vortex.int.bitpacking"
@@ -341,21 +351,49 @@ impl Scheme for BitPackingScheme {
341351 let packed = bitpack_encode ( stats. source ( ) , bw, Some ( & histogram) ) ?;
342352 let packed_stats = packed. statistics ( ) . to_owned ( ) ;
343353 let ptype = packed. dtype ( ) . as_ptype ( ) ;
344- let patches = packed. patches ( ) . map ( compress_patches) . transpose ( ) ?;
345- let mut parts = vortex_fastlanes:: BitPacked :: into_parts ( packed) ;
346- parts. patches = patches;
347-
348- Ok ( vortex_fastlanes:: BitPacked :: try_new (
349- parts. packed ,
350- ptype,
351- parts. validity ,
352- parts. patches ,
353- parts. bit_width ,
354- parts. len ,
355- parts. offset ,
356- ) ?
357- . with_stats_set ( packed_stats)
358- . into_array ( ) )
354+ let mut parts = BitPacked :: into_parts ( packed) ;
355+
356+ let array = if * USE_EXPERIMENTAL_PATCHES {
357+ let patches = parts. patches . take ( ) ;
358+ // Transpose patches into G-ALP style PatchedArray, wrapping an inner BitPackedArray.
359+ let array = BitPacked :: try_new (
360+ parts. packed ,
361+ ptype,
362+ parts. validity ,
363+ None ,
364+ parts. bit_width ,
365+ parts. len ,
366+ parts. offset ,
367+ ) ?
368+ . into_array ( ) ;
369+
370+ match patches {
371+ None => array,
372+ Some ( p) => Patched :: from_array_and_patches (
373+ array,
374+ & p,
375+ & mut LEGACY_SESSION . create_execution_ctx ( ) ,
376+ ) ?
377+ . into_array ( ) ,
378+ }
379+ } else {
380+ // Compress patches and place back into BitPackedArray.
381+ let patches = parts. patches . take ( ) . map ( compress_patches) . transpose ( ) ?;
382+ parts. patches = patches;
383+ BitPacked :: try_new (
384+ parts. packed ,
385+ ptype,
386+ parts. validity ,
387+ parts. patches ,
388+ parts. bit_width ,
389+ parts. len ,
390+ parts. offset ,
391+ ) ?
392+ . with_stats_set ( packed_stats)
393+ . into_array ( )
394+ } ;
395+
396+ Ok ( array)
359397 }
360398}
361399
0 commit comments