Skip to content
Merged
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
2 changes: 1 addition & 1 deletion encodings/fastlanes/src/rle/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ mod tests {
.indices()
.clone()
.execute::<PrimitiveArray>(&mut ctx)?
.narrow()?;
.narrow(&mut ctx)?;
let re_encoded = RLEData::encode(indices_prim.as_view(), &mut ctx)?;

// Reconstruct the outer RLE with re-encoded indices.
Expand Down
4 changes: 3 additions & 1 deletion encodings/runend/src/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ pub fn runend_encode(
}
};

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

ends.statistics()
.set(Stat::IsStrictSorted, Precision::Exact(true.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 @@ -7,6 +7,7 @@ use std::str::from_utf8;

use vortex_array::Canonical;
use vortex_array::IntoArray;
use vortex_array::LEGACY_SESSION;
use vortex_array::RecursiveCanonical;
use vortex_array::VortexSessionExecute;
use vortex_array::accessor::ArrayAccessor;
Expand Down Expand Up @@ -48,7 +49,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.clone().into_array()).unwrap();
let dict = dict_encode(
&primitive_arr.clone().into_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.clone().into_array()).unwrap();
let dict = dict_encode(
&varbin_arr.clone().into_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 @@ -87,7 +96,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.clone().into_array()).unwrap();
let dict = dict_encode(
&varbinview_arr.clone().into_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 @@ -122,7 +135,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.clone().into_array()).unwrap();
let dict = dict_encode(
&primitive_arr.clone().into_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap();
let dict = dict.into_array().slice(0..codes_len).unwrap();
let value = primitive_arr.as_slice::<i32>()[0];
let session = VortexSession::empty();
Expand All @@ -144,7 +161,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.clone().into_array()).unwrap();
let dict = dict_encode(
&varbin_arr.clone().into_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap();
let dict = dict.into_array().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
52 changes: 36 additions & 16 deletions vortex-array/benches/dict_compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,36 @@ where
{
let primitive_arr = gen_primitive_for_dict::<T>(len, unique_values);

bencher
.with_inputs(|| &primitive_arr)
.bench_refs(|arr| dict_encode(&arr.clone().into_array()));
bencher.with_inputs(|| &primitive_arr).bench_refs(|arr| {
dict_encode(
&arr.clone().into_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
)
});
}

#[divan::bench(args = BENCH_ARGS)]
fn encode_varbin(bencher: Bencher, (len, unique_values): (usize, usize)) {
let varbin_arr = VarBinArray::from(gen_varbin_words(len, unique_values));

bencher
.with_inputs(|| &varbin_arr)
.bench_refs(|arr| dict_encode(&arr.clone().into_array()));
bencher.with_inputs(|| &varbin_arr).bench_refs(|arr| {
dict_encode(
&arr.clone().into_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
)
});
}

#[divan::bench(args = BENCH_ARGS)]
fn encode_varbinview(bencher: Bencher, (len, unique_values): (usize, usize)) {
let varbinview_arr = VarBinViewArray::from_iter_str(gen_varbin_words(len, unique_values));

bencher
.with_inputs(|| &varbinview_arr)
.bench_refs(|arr| dict_encode(&arr.clone().into_array()));
bencher.with_inputs(|| &varbinview_arr).bench_refs(|arr| {
dict_encode(
&arr.clone().into_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
)
});
}

#[divan::bench(types = [u8, f32, i64], args = BENCH_ARGS)]
Expand All @@ -73,9 +82,12 @@ where
StandardUniform: Distribution<T>,
{
let primitive_arr = gen_primitive_for_dict::<T>(len, unique_values);
let dict = dict_encode(&primitive_arr.into_array())
.unwrap()
.into_array();
let dict = dict_encode(
&primitive_arr.into_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap()
.into_array();

bencher
.with_inputs(|| (&dict, LEGACY_SESSION.create_execution_ctx()))
Expand All @@ -85,7 +97,12 @@ where
#[divan::bench(args = BENCH_ARGS)]
fn decode_varbin(bencher: Bencher, (len, unique_values): (usize, usize)) {
let varbin_arr = VarBinArray::from(gen_varbin_words(len, unique_values));
let dict = dict_encode(&varbin_arr.into_array()).unwrap().into_array();
let dict = dict_encode(
&varbin_arr.into_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap()
.into_array();

bencher
.with_inputs(|| (&dict, LEGACY_SESSION.create_execution_ctx()))
Expand All @@ -95,9 +112,12 @@ fn decode_varbin(bencher: Bencher, (len, unique_values): (usize, usize)) {
#[divan::bench(args = BENCH_ARGS)]
fn decode_varbinview(bencher: Bencher, (len, unique_values): (usize, usize)) {
let varbinview_arr = VarBinViewArray::from_iter_str(gen_varbin_words(len, unique_values));
let dict = dict_encode(&varbinview_arr.into_array())
.unwrap()
.into_array();
let dict = dict_encode(
&varbinview_arr.into_array(),
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap()
.into_array();

bencher
.with_inputs(|| (&dict, LEGACY_SESSION.create_execution_ctx()))
Expand Down
8 changes: 4 additions & 4 deletions vortex-array/public-api.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5200,7 +5200,7 @@ pub trait vortex_array::arrays::primitive::PrimitiveArrayExt: vortex_array::Type

pub fn vortex_array::arrays::primitive::PrimitiveArrayExt::buffer_handle(&self) -> &vortex_array::buffer::BufferHandle

pub fn vortex_array::arrays::primitive::PrimitiveArrayExt::narrow(&self) -> vortex_error::VortexResult<vortex_array::arrays::PrimitiveArray>
pub fn vortex_array::arrays::primitive::PrimitiveArrayExt::narrow(&self, &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::arrays::PrimitiveArray>

pub fn vortex_array::arrays::primitive::PrimitiveArrayExt::nullability(&self) -> vortex_array::dtype::Nullability

Expand All @@ -5216,7 +5216,7 @@ impl<T: vortex_array::TypedArrayRef<vortex_array::arrays::Primitive>> vortex_arr

pub fn T::buffer_handle(&self) -> &vortex_array::buffer::BufferHandle

pub fn T::narrow(&self) -> vortex_error::VortexResult<vortex_array::arrays::PrimitiveArray>
pub fn T::narrow(&self, &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::arrays::PrimitiveArray>

pub fn T::nullability(&self) -> vortex_array::dtype::Nullability

Expand Down Expand Up @@ -8718,9 +8718,9 @@ pub fn vortex_array::builders::dict::DictEncoder::encode(&mut self, &vortex_arra

pub fn vortex_array::builders::dict::DictEncoder::reset(&mut self) -> vortex_array::ArrayRef

pub fn vortex_array::builders::dict::dict_encode(&vortex_array::ArrayRef) -> vortex_error::VortexResult<vortex_array::arrays::dict::DictArray>
pub fn vortex_array::builders::dict::dict_encode(&vortex_array::ArrayRef, &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::arrays::dict::DictArray>

pub fn vortex_array::builders::dict::dict_encode_with_constraints(&vortex_array::ArrayRef, &vortex_array::builders::dict::DictConstraints) -> vortex_error::VortexResult<vortex_array::arrays::dict::DictArray>
pub fn vortex_array::builders::dict::dict_encode_with_constraints(&vortex_array::ArrayRef, &vortex_array::builders::dict::DictConstraints, &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::arrays::dict::DictArray>

pub fn vortex_array::builders::dict::dict_encoder(&vortex_array::ArrayRef, &vortex_array::builders::dict::DictConstraints) -> alloc::boxed::Box<dyn vortex_array::builders::dict::DictEncoder>

Expand Down
22 changes: 15 additions & 7 deletions vortex-array/src/arrays/dict/compute/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ impl CastReduce for Dict {

#[cfg(test)]
mod tests {
use std::sync::LazyLock;

use rstest::rstest;
use vortex_buffer::buffer;
use vortex_session::VortexSession;

use crate::IntoArray;
#[expect(deprecated)]
use crate::ToCanonical as _;
use crate::VortexSessionExecute;
use crate::arrays::Dict;
use crate::arrays::PrimitiveArray;
use crate::arrays::dict::DictArraySlotsExt;
Expand All @@ -62,11 +66,15 @@ mod tests {
use crate::dtype::DType;
use crate::dtype::Nullability;
use crate::dtype::PType;
use crate::session::ArraySession;

static SESSION: LazyLock<VortexSession> =
LazyLock::new(|| VortexSession::empty().with::<ArraySession>());

#[test]
fn test_cast_dict_to_wider_type() {
let values = buffer![1i32, 2, 3, 2, 1].into_array();
let dict = dict_encode(&values).unwrap();
let dict = dict_encode(&values, &mut SESSION.create_execution_ctx()).unwrap();

let casted = dict
.into_array()
Expand All @@ -86,7 +94,7 @@ mod tests {
fn test_cast_dict_nullable() {
let values =
PrimitiveArray::from_option_iter([Some(10i32), None, Some(20), Some(10), None]);
let dict = dict_encode(&values.into_array()).unwrap();
let dict = dict_encode(&values.into_array(), &mut SESSION.create_execution_ctx()).unwrap();

let casted = dict
.into_array()
Expand All @@ -102,7 +110,7 @@ mod tests {
fn test_cast_dict_allvalid_to_nonnullable_and_back() {
// Create an AllValid dict array (no nulls)
let values = buffer![10i32, 20, 30, 40].into_array();
let dict = dict_encode(&values).unwrap();
let dict = dict_encode(&values, &mut SESSION.create_execution_ctx()).unwrap();

// Verify initial state - codes should be NonNullable, values should be NonNullable
assert_eq!(dict.codes().dtype().nullability(), Nullability::NonNullable);
Expand Down Expand Up @@ -171,10 +179,10 @@ mod tests {
}

#[rstest]
#[case(dict_encode(&buffer![1i32, 2, 3, 2, 1, 3].into_array()).unwrap().into_array())]
#[case(dict_encode(&buffer![100u32, 200, 100, 300, 200].into_array()).unwrap().into_array())]
#[case(dict_encode(&PrimitiveArray::from_option_iter([Some(1i32), None, Some(2), Some(1), None]).into_array()).unwrap().into_array())]
#[case(dict_encode(&buffer![1.5f32, 2.5, 1.5, 3.5].into_array()).unwrap().into_array())]
#[case(dict_encode(&buffer![1i32, 2, 3, 2, 1, 3].into_array(), &mut SESSION.create_execution_ctx()).unwrap().into_array())]
#[case(dict_encode(&buffer![100u32, 200, 100, 300, 200].into_array(), &mut SESSION.create_execution_ctx()).unwrap().into_array())]
#[case(dict_encode(&PrimitiveArray::from_option_iter([Some(1i32), None, Some(2), Some(1), None]).into_array(), &mut SESSION.create_execution_ctx()).unwrap().into_array())]
#[case(dict_encode(&buffer![1.5f32, 2.5, 1.5, 3.5].into_array(), &mut SESSION.create_execution_ctx()).unwrap().into_array())]
fn test_cast_dict_conformance(#[case] array: crate::ArrayRef) {
test_cast_conformance(&array);
}
Expand Down
19 changes: 15 additions & 4 deletions vortex-array/src/arrays/dict/compute/min_max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,27 @@ impl DynAggregateKernel for DictMinMaxKernel {

#[cfg(test)]
mod tests {
use std::sync::LazyLock;

use rstest::rstest;
use vortex_buffer::buffer;
use vortex_error::VortexResult;
use vortex_session::VortexSession;

use crate::ArrayRef;
use crate::IntoArray;
use crate::LEGACY_SESSION;
use crate::VortexSessionExecute;
use crate::aggregate_fn::fns::min_max::min_max;
use crate::arrays::DictArray;
use crate::arrays::PrimitiveArray;
use crate::builders::dict::dict_encode;
use crate::session::ArraySession;

static SESSION: LazyLock<VortexSession> =
LazyLock::new(|| VortexSession::empty().with::<ArraySession>());

fn assert_min_max(array: &ArrayRef, expected: Option<(i32, i32)>) -> VortexResult<()> {
let mut ctx = LEGACY_SESSION.create_execution_ctx();
let mut ctx = SESSION.create_execution_ctx();
match (min_max(array, &mut ctx)?, expected) {
(Some(result), Some((expected_min, expected_max))) => {
assert_eq!(i32::try_from(&result.min)?, expected_min);
Expand Down Expand Up @@ -117,7 +123,11 @@ mod tests {
}

fn dict_single() -> DictArray {
dict_encode(&buffer![42i32].into_array()).expect("valid single-value dictionary")
dict_encode(
&buffer![42i32].into_array(),
&mut SESSION.create_execution_ctx(),
)
.expect("valid single-value dictionary")
}

fn dict_nullable_codes() -> DictArray {
Expand All @@ -132,6 +142,7 @@ mod tests {
dict_encode(
&PrimitiveArray::from_option_iter([Some(1i32), None, Some(2), Some(1), None])
.into_array(),
&mut SESSION.create_execution_ctx(),
)
.expect("valid nullable-value dictionary")
}
Expand Down Expand Up @@ -166,7 +177,7 @@ mod tests {
#[test]
fn test_sliced_dict() -> VortexResult<()> {
let reference = PrimitiveArray::from_iter([1, 5, 10, 50, 100]);
let dict = dict_encode(&reference.into_array())?;
let dict = dict_encode(&reference.into_array(), &mut SESSION.create_execution_ctx())?;
let sliced = dict.slice(1..3)?;
assert_min_max(&sliced, Some((5, 10)))
}
Expand Down
Loading
Loading