Skip to content

Commit 206c2d3

Browse files
committed
build PatchedArray with env var VORTEX_EXPERIMENTAL_PATCHED_ARRAY.
Signed-off-by: Andrew Duffy <andrew@a10y.dev>
1 parent bd68641 commit 206c2d3

File tree

2 files changed

+56
-17
lines changed

2 files changed

+56
-17
lines changed

vortex-btrblocks/src/schemes/integer.rs

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33

44
//! Integer compression schemes.
55
6+
use std::env;
7+
use std::sync::LazyLock;
8+
69
use vortex_array::ArrayRef;
710
use vortex_array::Canonical;
811
use vortex_array::IntoArray;
12+
use vortex_array::LEGACY_SESSION;
913
use vortex_array::ToCanonical;
14+
use vortex_array::VortexSessionExecute;
1015
use vortex_array::arrays::ConstantArray;
16+
use vortex_array::arrays::Patched;
1117
use vortex_array::arrays::primitive::PrimitiveArrayExt;
1218
use vortex_array::scalar::Scalar;
1319
use vortex_compressor::builtins::FloatDictScheme;
@@ -19,7 +25,7 @@ use vortex_error::VortexExpect;
1925
use vortex_error::VortexResult;
2026
use vortex_error::vortex_bail;
2127
use vortex_error::vortex_err;
22-
use vortex_fastlanes::BitPackedArrayExt;
28+
use vortex_fastlanes::BitPacked;
2329
use vortex_fastlanes::FoR;
2430
use vortex_fastlanes::FoRArrayExt;
2531
use 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+
297307
impl 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

vortex-file/src/strategy.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use vortex_alp::ALP;
1111
// Compressed encodings from encoding crates
1212
// Canonical array encodings from vortex-array
1313
use vortex_alp::ALPRD;
14+
use vortex_array::arrays::Bool;
1415
use vortex_array::arrays::Chunked;
1516
use vortex_array::arrays::Constant;
1617
use vortex_array::arrays::Decimal;
@@ -21,11 +22,11 @@ use vortex_array::arrays::List;
2122
use vortex_array::arrays::ListView;
2223
use vortex_array::arrays::Masked;
2324
use vortex_array::arrays::Null;
25+
use vortex_array::arrays::Patched;
2426
use vortex_array::arrays::Primitive;
2527
use vortex_array::arrays::Struct;
2628
use vortex_array::arrays::VarBin;
2729
use vortex_array::arrays::VarBinView;
28-
use vortex_array::arrays::{Bool, Patched};
2930
use vortex_array::dtype::FieldPath;
3031
use vortex_array::session::ArrayRegistry;
3132
use vortex_array::session::ArraySession;

0 commit comments

Comments
 (0)