Skip to content

Commit dc0e9c9

Browse files
committed
execute update
Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
1 parent 8d72e46 commit dc0e9c9

20 files changed

Lines changed: 113 additions & 53 deletions

File tree

encodings/alp/src/alp/array.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ mod tests {
479479
use std::sync::LazyLock;
480480

481481
use rstest::rstest;
482+
use vortex_array::ExecutionCtx;
482483
use vortex_array::ToCanonical;
483484
use vortex_array::VectorExecutor;
484485
use vortex_array::arrays::PrimitiveArray;
@@ -505,7 +506,10 @@ mod tests {
505506
let values = PrimitiveArray::from_iter((0..size).map(|i| i as f32));
506507
let encoded = alp_encode(&values, None).unwrap();
507508

508-
let result_canonical = encoded.to_array().execute_session(&SESSION).unwrap();
509+
let result_canonical = {
510+
let mut ctx = ExecutionCtx::new(SESSION.clone());
511+
encoded.to_array().execute(&mut ctx).unwrap()
512+
};
509513
// Compare against the traditional array-based decompress path
510514
let expected = decompress_into_array(encoded);
511515

@@ -532,7 +536,10 @@ mod tests {
532536
let values = PrimitiveArray::from_iter((0..size).map(|i| i as f64));
533537
let encoded = alp_encode(&values, None).unwrap();
534538

535-
let result_canonical = encoded.to_array().execute_session(&SESSION).unwrap();
539+
let result_canonical = {
540+
let mut ctx = ExecutionCtx::new(SESSION.clone());
541+
encoded.to_array().execute(&mut ctx).unwrap()
542+
};
536543
// Compare against the traditional array-based decompress path
537544
let expected = decompress_into_array(encoded);
538545

@@ -565,7 +572,10 @@ mod tests {
565572
let encoded = alp_encode(&array, None).unwrap();
566573
assert!(encoded.patches().unwrap().array_len() > 0);
567574

568-
let result_canonical = encoded.to_array().execute_session(&SESSION).unwrap();
575+
let result_canonical = {
576+
let mut ctx = ExecutionCtx::new(SESSION.clone());
577+
encoded.to_array().execute(&mut ctx).unwrap()
578+
};
569579
// Compare against the traditional array-based decompress path
570580
let expected = decompress_into_array(encoded);
571581

@@ -596,7 +606,10 @@ mod tests {
596606
let array = PrimitiveArray::from_option_iter(values);
597607
let encoded = alp_encode(&array, None).unwrap();
598608

599-
let result_canonical = encoded.to_array().execute_session(&SESSION).unwrap();
609+
let result_canonical = {
610+
let mut ctx = ExecutionCtx::new(SESSION.clone());
611+
encoded.to_array().execute(&mut ctx).unwrap()
612+
};
600613
// Compare against the traditional array-based decompress path
601614
let expected = decompress_into_array(encoded);
602615

@@ -638,7 +651,10 @@ mod tests {
638651
let encoded = alp_encode(&array, None).unwrap();
639652
assert!(encoded.patches().unwrap().array_len() > 0);
640653

641-
let result_canonical = encoded.to_array().execute_session(&SESSION).unwrap();
654+
let result_canonical = {
655+
let mut ctx = ExecutionCtx::new(SESSION.clone());
656+
encoded.to_array().execute(&mut ctx).unwrap()
657+
};
642658
// Compare against the traditional array-based decompress path
643659
let expected = decompress_into_array(encoded);
644660

@@ -683,7 +699,10 @@ mod tests {
683699
let slice_len = slice_end - slice_start;
684700
let sliced_encoded = encoded.slice(slice_start..slice_end);
685701

686-
let result_canonical = sliced_encoded.execute_session(&SESSION).unwrap();
702+
let result_canonical = {
703+
let mut ctx = ExecutionCtx::new(SESSION.clone());
704+
sliced_encoded.execute(&mut ctx).unwrap()
705+
};
687706
let result_primitive = result_canonical.into_primitive();
688707

689708
for idx in 0..slice_len {

encodings/fastlanes/src/bitpacking/array/bitpack_decompress.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ pub fn count_exceptions(bit_width: u8, bit_width_freq: &[usize]) -> usize {
203203
mod tests {
204204
use std::sync::LazyLock;
205205

206+
use vortex_array::ExecutionCtx;
206207
use vortex_array::IntoArray;
207208
use vortex_array::VectorExecutor;
208209
use vortex_array::assert_arrays_eq;
@@ -534,7 +535,10 @@ mod tests {
534535
let unpacked_array = unpack_array(&bitpacked);
535536

536537
// Method 3: Using the execute() method (this is what would be used in production).
537-
let executed = bitpacked.into_array().execute_session(&SESSION).unwrap();
538+
let executed = {
539+
let mut ctx = ExecutionCtx::new(SESSION.clone());
540+
bitpacked.into_array().execute(&mut ctx).unwrap()
541+
};
538542

539543
// All three should produce the same length.
540544
assert_eq!(vector_result.len(), array.len(), "vector length mismatch");
@@ -554,11 +558,14 @@ mod tests {
554558

555559
// Verify that the execute() method works correctly by comparing with unpack_array.
556560
// We convert unpack_array result to canonical to compare.
557-
let unpacked_executed = unpacked_array
558-
.into_array()
559-
.execute_session(&SESSION)
560-
.unwrap()
561-
.into_primitive();
561+
let unpacked_executed = {
562+
let mut ctx = ExecutionCtx::new(SESSION.clone());
563+
unpacked_array
564+
.into_array()
565+
.execute(&mut ctx)
566+
.unwrap()
567+
.into_primitive()
568+
};
562569
assert_eq!(
563570
executed_primitive.len(),
564571
unpacked_executed.len(),
@@ -590,7 +597,10 @@ mod tests {
590597
let sliced_bp = sliced.as_::<BitPackedVTable>();
591598
let vector_result = unpack_to_primitive_vector(sliced_bp);
592599
let unpacked_array = unpack_array(sliced_bp);
593-
let executed = sliced.execute_session(&SESSION).unwrap();
600+
let executed = {
601+
let mut ctx = ExecutionCtx::new(SESSION.clone());
602+
sliced.execute(&mut ctx).unwrap()
603+
};
594604

595605
assert_eq!(
596606
vector_result.len(),

vortex-array/src/arrow/compute/to_arrow/canonical.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ use vortex_scalar::DecimalType;
5757

5858
use crate::Array as _;
5959
use crate::Canonical;
60+
use crate::ExecutionCtx;
6061
use crate::IntoArray;
6162
use crate::LEGACY_SESSION;
6263
use crate::VectorExecutor;
@@ -531,10 +532,11 @@ fn to_arrow_list<O: IntegerPType + OffsetSizeTrait>(
531532
};
532533

533534
// Convert the child `offsets` and `validity` array to Arrow.
535+
let mut ctx = ExecutionCtx::new(LEGACY_SESSION.clone());
534536
let offsets = list_array
535537
.offsets()
536538
.cast(DType::from(O::PTYPE))?
537-
.execute_session(&LEGACY_SESSION)?
539+
.execute(&mut ctx)?
538540
.to_vector_session(&LEGACY_SESSION)?
539541
.into_primitive()
540542
.downcast::<O>()
@@ -557,10 +559,11 @@ fn to_arrow_listview<O: IntegerPType + OffsetSizeTrait>(
557559
) -> VortexResult<ArrowArrayRef> {
558560
// First we cast the offsets and sizes into the specified width (determined by `O::PTYPE`).
559561
let offsets_dtype = DType::Primitive(O::PTYPE, array.dtype().nullability());
562+
let mut ctx = ExecutionCtx::new(LEGACY_SESSION.clone());
560563
let offsets = array
561564
.offsets()
562565
.cast(offsets_dtype.clone())?
563-
.execute_session(&LEGACY_SESSION)?
566+
.execute(&mut ctx)?
564567
.to_vector_session(&LEGACY_SESSION)?
565568
.into_primitive()
566569
.downcast::<O>()
@@ -569,7 +572,7 @@ fn to_arrow_listview<O: IntegerPType + OffsetSizeTrait>(
569572
let sizes = array
570573
.sizes()
571574
.cast(offsets_dtype)?
572-
.execute_session(&LEGACY_SESSION)?
575+
.execute(&mut ctx)?
573576
.to_vector_session(&LEGACY_SESSION)?
574577
.into_primitive()
575578
.downcast::<O>()

vortex-array/src/arrow/compute/to_arrow/list.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use vortex_dtype::PTypeDowncastExt;
1515
use vortex_error::VortexResult;
1616
use vortex_error::vortex_bail;
1717

18+
use crate::ExecutionCtx;
1819
use crate::IntoArray;
1920
use crate::LEGACY_SESSION;
2021
use crate::VectorExecutor;
@@ -64,10 +65,11 @@ fn list_array_to_arrow_list<O: IntegerPType + OffsetSizeTrait>(
6465
element: Option<&FieldRef>,
6566
) -> VortexResult<ArrowArrayRef> {
6667
// First we cast the offsets and sizes into the specified width (determined by `O::PTYPE`).
68+
let mut ctx = ExecutionCtx::new(LEGACY_SESSION.clone());
6769
let offsets = array
6870
.offsets()
6971
.cast(DType::Primitive(O::PTYPE, array.dtype().nullability()))?
70-
.execute_session(&LEGACY_SESSION)?
72+
.execute(&mut ctx)?
7173
.to_vector_session(&LEGACY_SESSION)?
7274
.into_primitive()
7375
.downcast::<O>()

vortex-array/src/arrow/compute/to_arrow/temporal.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use vortex_error::VortexExpect;
2929
use vortex_error::VortexResult;
3030
use vortex_error::vortex_bail;
3131

32+
use crate::ExecutionCtx;
3233
use crate::IntoArray;
3334
use crate::LEGACY_SESSION;
3435
use crate::VectorExecutor;
@@ -128,10 +129,11 @@ where
128129
T::Native: NativePType,
129130
{
130131
let values_dtype = DType::Primitive(T::Native::PTYPE, array.dtype().nullability());
132+
let mut ctx = ExecutionCtx::new(LEGACY_SESSION.clone());
131133
let values = array
132134
.temporal_values()
133135
.cast(values_dtype)?
134-
.execute_session(&LEGACY_SESSION)?
136+
.execute(&mut ctx)?
135137
.to_vector_session(&LEGACY_SESSION)?
136138
.into_primitive()
137139
.downcast::<T::Native>();

vortex-array/src/arrow/compute/to_arrow/varbin.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use vortex_error::vortex_bail;
1818
use vortex_error::vortex_panic;
1919

2020
use crate::Array;
21+
use crate::ExecutionCtx;
2122
use crate::LEGACY_SESSION;
2223
use crate::VectorExecutor;
2324
use crate::arrays::VarBinArray;
@@ -80,11 +81,12 @@ impl ToArrowKernel for VarBinVTable {
8081
register_kernel!(ToArrowKernelAdapter(VarBinVTable).lift());
8182

8283
fn to_arrow<O: IntegerPType + OffsetSizeTrait>(array: &VarBinArray) -> VortexResult<ArrowArrayRef> {
84+
let mut ctx = ExecutionCtx::new(LEGACY_SESSION.clone());
8385
let offsets = cast(
8486
array.offsets(),
8587
&DType::Primitive(O::PTYPE, Nullability::NonNullable),
8688
)?
87-
.execute_session(&LEGACY_SESSION)?
89+
.execute(&mut ctx)?
8890
.to_vector_session(&LEGACY_SESSION)?
8991
.into_primitive()
9092
.downcast::<O>()

vortex-array/src/arrow/executor/bool.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use vortex_error::VortexResult;
99
use vortex_session::VortexSession;
1010

1111
use crate::ArrayRef;
12+
use crate::ExecutionCtx;
1213
use crate::VectorExecutor;
1314
use crate::arrays::BoolArray;
1415
use crate::arrow::null_buffer::to_null_buffer;
@@ -25,6 +26,7 @@ pub(super) fn to_arrow_bool(
2526
array: ArrayRef,
2627
session: &VortexSession,
2728
) -> VortexResult<ArrowArrayRef> {
28-
let bool_array = array.execute_session(session)?.into_bool();
29+
let mut ctx = ExecutionCtx::new(session.clone());
30+
let bool_array = array.execute(&mut ctx)?.into_bool();
2931
Ok(canonical_bool_to_arrow(&bool_array))
3032
}

vortex-array/src/arrow/executor/byte.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use vortex_error::VortexResult;
1616
use vortex_session::VortexSession;
1717

1818
use crate::ArrayRef;
19+
use crate::ExecutionCtx;
1920
use crate::VectorExecutor;
2021
use crate::arrays::VarBinArray;
2122
use crate::arrays::VarBinVTable;
@@ -37,8 +38,9 @@ where
3738
}
3839

3940
// Otherwise, we execute the array to a BinaryView vector and cast from there.
41+
let mut ctx = ExecutionCtx::new(session.clone());
4042
let binary_view = array
41-
.execute_session(session)?
43+
.execute(&mut ctx)?
4244
.to_vector_session(session)?
4345
.into_arrow()?;
4446
arrow_cast::cast(&binary_view, &T::DATA_TYPE).map_err(VortexError::from)
@@ -53,10 +55,11 @@ where
5355
T::Offset: NativePType,
5456
{
5557
// We must cast the offsets to the required offset type.
58+
let mut ctx = ExecutionCtx::new(session.clone());
5659
let offsets = array
5760
.offsets()
5861
.cast(DType::Primitive(T::Offset::PTYPE, Nullability::NonNullable))?
59-
.execute_session(session)?
62+
.execute(&mut ctx)?
6063
.to_vector_session(session)?
6164
.into_primitive()
6265
.downcast::<T::Offset>()

vortex-array/src/arrow/executor/byte_view.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use vortex_error::VortexResult;
1414
use vortex_session::VortexSession;
1515

1616
use crate::ArrayRef;
17+
use crate::ExecutionCtx;
1718
use crate::VectorExecutor;
1819
use crate::arrays::VarBinViewArray;
1920
use crate::arrow::null_buffer::to_null_buffer;
@@ -44,6 +45,7 @@ pub(super) fn to_arrow_byte_view<T: ByteViewType>(
4445
// flexible since there's no prescribed nullability in Arrow types.
4546
let array = array.cast(DType::from_arrow((&T::DATA_TYPE, Nullability::Nullable)))?;
4647

47-
let varbinview = array.execute_session(session)?.into_varbinview();
48+
let mut ctx = ExecutionCtx::new(session.clone());
49+
let varbinview = array.execute(&mut ctx)?.into_varbinview();
4850
Ok(canonical_varbinview_to_arrow::<T>(&varbinview))
4951
}

vortex-array/src/arrow/executor/decimal.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use vortex_error::vortex_ensure;
1717
use vortex_session::VortexSession;
1818

1919
use crate::ArrayRef;
20+
use crate::ExecutionCtx;
2021
use crate::VectorExecutor;
2122
use crate::arrow::null_buffer::to_null_buffer;
2223
use crate::builtins::ArrayBuiltins;
@@ -30,7 +31,7 @@ pub(super) fn to_arrow_decimal<D: DecimalType, N: NativeDecimalType>(
3031
session: &VortexSession,
3132
) -> VortexResult<ArrowArrayRef> {
3233
// Since Vortex doesn't have physical types, our DecimalDType only contains precision and scale.
33-
// When calling execute_vector, Vortex may use any physical type >= the smallest type that can
34+
// When calling execute, Vortex may use any physical type >= the smallest type that can
3435
// hold the requested precision.
3536
//
3637
// We therefore create a fake precision that forces Vortex to use a native type that is at
@@ -45,8 +46,9 @@ pub(super) fn to_arrow_decimal<D: DecimalType, N: NativeDecimalType>(
4546
))?;
4647

4748
// Execute the array as a vector and downcast to our native type.
49+
let mut ctx = ExecutionCtx::new(session.clone());
4850
let vector = array
49-
.execute_session(session)?
51+
.execute(&mut ctx)?
5052
.to_vector_session(session)?
5153
.into_decimal();
5254
vortex_ensure!(

0 commit comments

Comments
 (0)