Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions encodings/runend/benches/run_end_compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn compress(bencher: Bencher, (length, run_step): (usize, usize)) {

bencher
.with_inputs(|| &values)
.bench_refs(|values| runend_encode(values));
.bench_refs(|values| runend_encode(values, &mut LEGACY_SESSION.create_execution_ctx()));
}

#[divan::bench(types = [u8, u16, u32, u64], args = BENCH_ARGS)]
Expand Down Expand Up @@ -92,7 +92,7 @@ fn take_indices(bencher: Bencher, (length, run_step): (usize, usize)) {
);

let source_array = PrimitiveArray::from_iter(0..(length as i32)).into_array();
let (ends, values) = runend_encode(&values);
let (ends, values) = runend_encode(&values, &mut LEGACY_SESSION.create_execution_ctx());
let runend_array = RunEndArray::try_new(ends.into_array(), values)
.unwrap()
.to_array();
Expand Down
4 changes: 2 additions & 2 deletions encodings/runend/public-api.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ pub fn vortex_runend::compress::runend_decode_typed_bool(run_ends: impl core::it

pub fn vortex_runend::compress::runend_decode_typed_primitive<T: vortex_array::dtype::ptype::NativePType>(run_ends: impl core::iter::traits::iterator::Iterator<Item = usize>, values: &[T], values_validity: vortex_mask::Mask, values_nullability: vortex_array::dtype::nullability::Nullability, length: usize) -> vortex_array::arrays::primitive::array::PrimitiveArray

pub fn vortex_runend::compress::runend_encode(array: &vortex_array::arrays::primitive::array::PrimitiveArray) -> (vortex_array::arrays::primitive::array::PrimitiveArray, vortex_array::array::ArrayRef)
pub fn vortex_runend::compress::runend_encode(array: &vortex_array::arrays::primitive::array::PrimitiveArray, ctx: &mut vortex_array::executor::ExecutionCtx) -> (vortex_array::arrays::primitive::array::PrimitiveArray, vortex_array::array::ArrayRef)

pub struct vortex_runend::RunEndArray

impl vortex_runend::RunEndArray

pub fn vortex_runend::RunEndArray::encode(array: vortex_array::array::ArrayRef) -> vortex_error::VortexResult<Self>
pub fn vortex_runend::RunEndArray::encode(array: vortex_array::array::ArrayRef, ctx: &mut vortex_array::executor::ExecutionCtx) -> vortex_error::VortexResult<Self>

pub fn vortex_runend::RunEndArray::ends(&self) -> &vortex_array::array::ArrayRef

Expand Down
4 changes: 2 additions & 2 deletions encodings/runend/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,9 @@ impl RunEndArray {
}

/// Run the array through run-end encoding.
pub fn encode(array: ArrayRef) -> VortexResult<Self> {
pub fn encode(array: ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<Self> {
if let Some(parray) = array.as_opt::<PrimitiveVTable>() {
let (ends, values) = runend_encode(parray);
let (ends, values) = runend_encode(parray, ctx);
// SAFETY: runend_encode handles this
unsafe {
Ok(Self::new_unchecked(
Expand Down
1 change: 1 addition & 0 deletions encodings/runend/src/arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ mod tests {
fn test_sliced_runend_to_arrow_ree() -> VortexResult<()> {
let array = RunEndArray::encode(
PrimitiveArray::from_iter(vec![10i32, 10, 20, 20, 20, 30, 30]).into_array(),
&mut SESSION.create_execution_ctx(),
)?;
// Slicing from index 1 produces a non-zero offset in the RunEndArray.
let sliced = array.into_array().slice(1..5)?;
Expand Down
16 changes: 9 additions & 7 deletions encodings/runend/src/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use itertools::Itertools;
use vortex_array::ArrayRef;
use vortex_array::ExecutionCtx;
use vortex_array::IntoArray;
use vortex_array::ToCanonical;
use vortex_array::arrays::BoolArray;
Expand All @@ -29,7 +30,7 @@ use vortex_mask::Mask;
use crate::iter::trimmed_ends_iter;

/// Run-end encode a `PrimitiveArray`, returning a tuple of `(ends, values)`.
pub fn runend_encode(array: &PrimitiveArray) -> (PrimitiveArray, ArrayRef) {
pub fn runend_encode(array: &PrimitiveArray, ctx: &mut ExecutionCtx) -> (PrimitiveArray, ArrayRef) {
let validity = match array.validity() {
Validity::NonNullable => None,
Validity::AllValid => None,
Expand Down Expand Up @@ -69,9 +70,8 @@ pub fn runend_encode(array: &PrimitiveArray) -> (PrimitiveArray, ArrayRef) {
};

let ends = ends
.narrow()
.vortex_expect("Ends must succeed downcasting")
.to_primitive();
.narrow(ctx)
.vortex_expect("Ends must succeed downcasting");

ends.statistics()
.set(Stat::IsStrictSorted, Precision::Exact(true.into()));
Expand Down Expand Up @@ -306,7 +306,9 @@ pub fn runend_decode_typed_bool(

#[cfg(test)]
mod test {
use vortex_array::LEGACY_SESSION;
use vortex_array::ToCanonical;
use vortex_array::VortexSessionExecute;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::assert_arrays_eq;
use vortex_array::validity::Validity;
Expand All @@ -320,7 +322,7 @@ mod test {
#[test]
fn encode() {
let arr = PrimitiveArray::from_iter([1i32, 1, 2, 2, 2, 3, 3, 3, 3, 3]);
let (ends, values) = runend_encode(&arr);
let (ends, values) = runend_encode(&arr, &mut LEGACY_SESSION.create_execution_ctx());
let values = values.to_primitive();

let expected_ends = PrimitiveArray::from_iter(vec![2u8, 5, 10]);
Expand All @@ -337,7 +339,7 @@ mod test {
true, true, false, false, true, true, true, true, false, false,
])),
);
let (ends, values) = runend_encode(&arr);
let (ends, values) = runend_encode(&arr, &mut LEGACY_SESSION.create_execution_ctx());
let values = values.to_primitive();

let expected_ends = PrimitiveArray::from_iter(vec![2u8, 4, 5, 8, 10]);
Expand All @@ -353,7 +355,7 @@ mod test {
buffer![0, 0, 0, 0, 0],
Validity::from(BitBuffer::new_unset(5)),
);
let (ends, values) = runend_encode(&arr);
let (ends, values) = runend_encode(&arr, &mut LEGACY_SESSION.create_execution_ctx());
let values = values.to_primitive();

let expected_ends = PrimitiveArray::from_iter(vec![5u64]);
Expand Down
3 changes: 3 additions & 0 deletions encodings/runend/src/compute/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ impl CompareKernel for RunEndVTable {
#[cfg(test)]
mod test {
use vortex_array::IntoArray;
use vortex_array::LEGACY_SESSION;
use vortex_array::VortexSessionExecute;
use vortex_array::arrays::BoolArray;
use vortex_array::arrays::ConstantArray;
use vortex_array::arrays::PrimitiveArray;
Expand All @@ -59,6 +61,7 @@ mod test {
fn ree_array() -> RunEndArray {
RunEndArray::encode(
PrimitiveArray::from_iter([1, 1, 1, 4, 4, 4, 2, 2, 5, 5, 5, 5]).into_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap()
}
Expand Down
3 changes: 3 additions & 0 deletions encodings/runend/src/compute/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ fn filter_run_end_primitive<R: NativePType + AddAssign + From<bool> + AsPrimitiv
mod tests {
use vortex_array::Array;
use vortex_array::IntoArray;
use vortex_array::LEGACY_SESSION;
use vortex_array::VortexSessionExecute;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::assert_arrays_eq;
use vortex_error::VortexResult;
Expand All @@ -127,6 +129,7 @@ mod tests {
fn ree_array() -> RunEndArray {
RunEndArray::encode(
PrimitiveArray::from_iter([1, 1, 1, 4, 4, 4, 2, 2, 5, 5, 5, 5]).into_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap()
}
Expand Down
20 changes: 14 additions & 6 deletions encodings/runend/src/compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub(crate) mod take_from;
mod tests {
use rstest::rstest;
use vortex_array::IntoArray;
use vortex_array::LEGACY_SESSION;
use vortex_array::VortexSessionExecute;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::compute::conformance::consistency::test_array_consistency;
use vortex_buffer::buffer;
Expand All @@ -24,24 +26,30 @@ mod tests {
#[rstest]
// Simple run-end arrays
#[case::runend_i32(RunEndArray::encode(
buffer![1i32, 1, 1, 2, 2, 3, 3, 3, 3].into_array()
buffer![1i32, 1, 1, 2, 2, 3, 3, 3, 3].into_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
).unwrap())]
#[case::runend_single_run(RunEndArray::encode(
buffer![5i32, 5, 5, 5, 5].into_array()
buffer![5i32, 5, 5, 5, 5].into_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
).unwrap())]
#[case::runend_alternating(RunEndArray::encode(
buffer![1i32, 2, 1, 2, 1, 2].into_array()
buffer![1i32, 2, 1, 2, 1, 2].into_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
).unwrap())]
// Different types
#[case::runend_u64(RunEndArray::encode(
buffer![100u64, 100, 200, 200, 200].into_array()
buffer![100u64, 100, 200, 200, 200].into_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
).unwrap())]
// Edge cases
#[case::runend_single(RunEndArray::encode(
buffer![42i32].into_array()
buffer![42i32].into_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
).unwrap())]
#[case::runend_large(RunEndArray::encode(
PrimitiveArray::from_iter((0..1000).map(|i| i / 10)).into_array()
PrimitiveArray::from_iter((0..1000).map(|i| i / 10)).into_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
).unwrap())]

fn test_runend_consistency(#[case] array: RunEndArray) {
Expand Down
21 changes: 17 additions & 4 deletions encodings/runend/src/compute/take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ mod test {
use crate::RunEndArray;

fn ree_array() -> RunEndArray {
RunEndArray::encode(buffer![1, 1, 1, 4, 4, 4, 2, 2, 5, 5, 5, 5].into_array()).unwrap()
RunEndArray::encode(
buffer![1, 1, 1, 4, 4, 4, 2, 2, 5, 5, 5, 5].into_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap()
}

#[test]
Expand Down Expand Up @@ -154,6 +158,7 @@ mod test {
#[case(ree_array())]
#[case(RunEndArray::encode(
buffer![1u8, 1, 2, 2, 2, 3, 3, 3, 3, 4].into_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
).unwrap())]
#[case(RunEndArray::encode(
PrimitiveArray::from_option_iter([
Expand All @@ -166,11 +171,15 @@ mod test {
Some(20),
])
.into_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
).unwrap())]
#[case(RunEndArray::encode(
buffer![42i32, 42, 42, 42, 42].into_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
).unwrap())]
#[case(RunEndArray::encode(buffer![42i32, 42, 42, 42, 42].into_array())
.unwrap())]
#[case(RunEndArray::encode(
buffer![1i32, 2, 3, 4, 5, 6, 7, 8, 9, 10].into_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
).unwrap())]
#[case({
let mut values = Vec::new();
Expand All @@ -179,7 +188,10 @@ mod test {
values.push(i);
}
}
RunEndArray::encode(PrimitiveArray::from_iter(values).into_array()).unwrap()
RunEndArray::encode(
PrimitiveArray::from_iter(values).into_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
).unwrap()
})]
fn test_take_runend_conformance(#[case] array: RunEndArray) {
test_take_conformance(&array.to_array());
Expand All @@ -190,6 +202,7 @@ mod test {
#[case({
let array = RunEndArray::encode(
buffer![1i32, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3].into_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap();
array.slice(2..8).unwrap()
Expand Down
8 changes: 7 additions & 1 deletion encodings/runend/src/compute/take_from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ mod tests {
use vortex_array::Array;
use vortex_array::ExecutionCtx;
use vortex_array::IntoArray;
use vortex_array::LEGACY_SESSION;
use vortex_array::VortexSessionExecute;
use vortex_array::arrays::DictArray;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::assert_arrays_eq;
Expand All @@ -73,7 +75,11 @@ mod tests {
/// Codes: `[0, 0, 0, 1, 1, 0, 0]`
/// RunEnd encoded codes: ends=`[3, 5, 7]`, values=`[0, 1, 0]`
fn make_dict_with_runend_codes() -> (RunEndArray, DictArray) {
let codes = RunEndArray::encode(buffer![0u32, 0, 0, 1, 1, 0, 0].into_array()).unwrap();
let codes = RunEndArray::encode(
buffer![0u32, 0, 0, 1, 1, 0, 0].into_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap();
let values = buffer![2i32, 3].into_array();
let dict = DictArray::try_new(codes.clone().into_array(), values).unwrap();
(codes, dict)
Expand Down
13 changes: 9 additions & 4 deletions encodings/runend/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ mod tests {

use vortex_array::Array;
use vortex_array::IntoArray;
use vortex_array::LEGACY_SESSION;
use vortex_array::VortexSessionExecute;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::assert_arrays_eq;
use vortex_array::compute::Cost;
Expand Down Expand Up @@ -151,10 +153,13 @@ mod tests {

#[test]
fn ree_scalar_at_end() {
let scalar = RunEndArray::encode(buffer![1, 1, 1, 4, 4, 4, 2, 2, 5, 5, 5, 5].into_array())
.unwrap()
.scalar_at(11)
.unwrap();
let scalar = RunEndArray::encode(
buffer![1, 1, 1, 4, 4, 4, 2, 2, 5, 5, 5, 5].into_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap()
.scalar_at(11)
.unwrap();
assert_eq!(scalar, 5.into());
}

Expand Down
31 changes: 26 additions & 5 deletions vortex-array/benches/dict_compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use std::str::from_utf8;

use vortex_array::Canonical;
use vortex_array::LEGACY_SESSION;
use vortex_array::RecursiveCanonical;
use vortex_array::VortexSessionExecute;
use vortex_array::accessor::ArrayAccessor;
Expand Down Expand Up @@ -49,7 +50,11 @@ const LENGTH_AND_UNIQUE_VALUES: &[(usize, usize)] = &[
#[divan::bench(args = LENGTH_AND_UNIQUE_VALUES)]
fn bench_compare_primitive(bencher: divan::Bencher, (len, uniqueness): (usize, usize)) {
let primitive_arr = gen_primitive_for_dict::<i32>(len, uniqueness);
let dict = dict_encode(&primitive_arr.to_array()).unwrap();
let dict = dict_encode(
&primitive_arr.to_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap();
let value = primitive_arr.as_slice::<i32>()[0];
let session = VortexSession::empty();

Expand All @@ -67,7 +72,11 @@ fn bench_compare_primitive(bencher: divan::Bencher, (len, uniqueness): (usize, u
#[divan::bench(args = LENGTH_AND_UNIQUE_VALUES)]
fn bench_compare_varbin(bencher: divan::Bencher, (len, uniqueness): (usize, usize)) {
let varbin_arr = VarBinArray::from(gen_varbin_words(len, uniqueness));
let dict = dict_encode(&varbin_arr.to_array()).unwrap();
let dict = dict_encode(
&varbin_arr.to_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap();
let bytes = varbin_arr.with_iterator(|i| i.next().unwrap().unwrap().to_vec());
let value = from_utf8(bytes.as_slice()).unwrap();
let session = VortexSession::empty();
Expand All @@ -86,7 +95,11 @@ fn bench_compare_varbin(bencher: divan::Bencher, (len, uniqueness): (usize, usiz
#[divan::bench(args = LENGTH_AND_UNIQUE_VALUES)]
fn bench_compare_varbinview(bencher: divan::Bencher, (len, uniqueness): (usize, usize)) {
let varbinview_arr = VarBinViewArray::from_iter_str(gen_varbin_words(len, uniqueness));
let dict = dict_encode(&varbinview_arr.to_array()).unwrap();
let dict = dict_encode(
&varbinview_arr.to_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap();
let bytes = varbinview_arr.with_iterator(|i| i.next().unwrap().unwrap().to_vec());
let value = from_utf8(bytes.as_slice()).unwrap();
let session = VortexSession::empty();
Expand Down Expand Up @@ -120,7 +133,11 @@ fn bench_compare_sliced_dict_primitive(
(codes_len, values_len): (usize, usize),
) {
let primitive_arr = gen_primitive_for_dict::<i32>(codes_len.max(values_len), values_len);
let dict = dict_encode(&primitive_arr.to_array()).unwrap();
let dict = dict_encode(
&primitive_arr.to_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap();
let dict = dict.slice(0..codes_len).unwrap();
let value = primitive_arr.as_slice::<i32>()[0];
let session = VortexSession::empty();
Expand All @@ -141,7 +158,11 @@ fn bench_compare_sliced_dict_varbinview(
(codes_len, values_len): (usize, usize),
) {
let varbin_arr = VarBinArray::from(gen_varbin_words(codes_len.max(values_len), values_len));
let dict = dict_encode(&varbin_arr.to_array()).unwrap();
let dict = dict_encode(
&varbin_arr.to_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap();
let dict = dict.slice(0..codes_len).unwrap();
let bytes = varbin_arr.with_iterator(|i| i.next().unwrap().unwrap().to_vec());
let value = from_utf8(bytes.as_slice()).unwrap();
Expand Down
Loading