Skip to content

Commit dfc5be5

Browse files
committed
Use more execute
Signed-off-by: Nicholas Gates <[email protected]>
1 parent d8d129a commit dfc5be5

File tree

12 files changed

+133
-57
lines changed

12 files changed

+133
-57
lines changed

vortex-array/src/arrays/filter/vtable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ use crate::ArrayHash;
2222
use crate::ArrayRef;
2323
use crate::Canonical;
2424
use crate::IntoArray;
25+
use crate::LEGACY_SESSION;
2526
use crate::Precision;
26-
use crate::arrays::LEGACY_SESSION;
2727
use crate::arrays::filter::array::FilterArray;
2828
use crate::arrays::filter::kernel::FilterKernel;
2929
use crate::kernel::BindCtx;

vortex-array/src/arrays/mod.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
#[cfg(any(test, feature = "test-harness"))]
77
mod assertions;
88

9-
use std::sync::LazyLock;
10-
119
#[cfg(any(test, feature = "test-harness"))]
1210
pub use assertions::format_indices;
1311

@@ -59,12 +57,3 @@ pub use scalar_fn::*;
5957
pub use struct_::*;
6058
pub use varbin::*;
6159
pub use varbinview::*;
62-
use vortex_session::VortexSession;
63-
64-
use crate::session::ArraySession;
65-
66-
// TODO(ngates): canonicalize doesn't currently take a session, therefore we cannot invoke execute
67-
// from the new array encodings to support back-compat for legacy encodings. So we hold a session
68-
// here...
69-
static LEGACY_SESSION: LazyLock<VortexSession> =
70-
LazyLock::new(|| VortexSession::empty().with::<ArraySession>());

vortex-array/src/arrays/scalar_fn/vtable/canonical.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use vortex_error::VortexExpect;
55

66
use crate::Array;
77
use crate::Canonical;
8-
use crate::arrays::LEGACY_SESSION;
8+
use crate::LEGACY_SESSION;
99
use crate::arrays::scalar_fn::array::ScalarFnArray;
1010
use crate::arrays::scalar_fn::vtable::ScalarFnVTable;
1111
use crate::executor::VectorExecutor;

vortex-array/src/arrays/scalar_fn/vtable/validity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use vortex_vector::ScalarOps;
88
use vortex_vector::VectorOps;
99

1010
use crate::Array;
11-
use crate::arrays::LEGACY_SESSION;
11+
use crate::LEGACY_SESSION;
1212
use crate::arrays::scalar_fn::array::ScalarFnArray;
1313
use crate::arrays::scalar_fn::vtable::ScalarFnVTable;
1414
use crate::executor::VectorExecutor;

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

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ use vortex_buffer::Buffer;
5353
use vortex_dtype::DType;
5454
use vortex_dtype::IntegerPType;
5555
use vortex_dtype::PType;
56+
use vortex_dtype::PTypeDowncastExt;
5657
use vortex_error::VortexExpect;
5758
use vortex_error::VortexResult;
5859
use vortex_error::vortex_bail;
@@ -62,7 +63,8 @@ use vortex_scalar::DecimalType;
6263
use crate::Array as _;
6364
use crate::Canonical;
6465
use crate::IntoArray;
65-
use crate::ToCanonical;
66+
use crate::LEGACY_SESSION;
67+
use crate::VectorExecutor;
6668
use crate::arrays::BoolArray;
6769
use crate::arrays::DecimalArray;
6870
use crate::arrays::FixedSizeListArray;
@@ -75,11 +77,15 @@ use crate::arrays::list_from_list_view;
7577
use crate::arrow::IntoArrowArray;
7678
use crate::arrow::array::ArrowArray;
7779
use crate::arrow::compute::ToArrowArgs;
80+
<<<<<<< Updated upstream
7881
use crate::arrow::null_buffer::to_null_buffer;
82+
=======
83+
use crate::arrow::compute::to_arrow::null_buffer::to_null_buffer;
84+
use crate::builtins::ArrayBuiltins;
85+
>>>>>>> Stashed changes
7986
use crate::compute::InvocationArgs;
8087
use crate::compute::Kernel;
8188
use crate::compute::Output;
82-
use crate::compute::cast;
8389

8490
/// Implementation of `ToArrow` kernel for canonical Vortex arrays.
8591
#[derive(Debug)]
@@ -555,9 +561,13 @@ fn to_arrow_list<O: IntegerPType + OffsetSizeTrait>(
555561
};
556562

557563
// Convert the child `offsets` and `validity` array to Arrow.
558-
let offsets = cast(list_array.offsets().as_ref(), &DType::from(O::PTYPE))?
559-
.to_primitive()
560-
.buffer::<O>()
564+
let offsets = list_array
565+
.offsets()
566+
.cast(DType::from(O::PTYPE))?
567+
.execute_vector(&LEGACY_SESSION)?
568+
.into_primitive()
569+
.downcast::<O>()
570+
.into_buffer()
561571
.into_arrow_offset_buffer();
562572
let nulls = to_null_buffer(list_array.validity_mask());
563573

@@ -576,16 +586,24 @@ fn to_arrow_listview<O: IntegerPType + OffsetSizeTrait>(
576586
) -> VortexResult<ArrowArrayRef> {
577587
// First we cast the offsets and sizes into the specified width (determined by `O::PTYPE`).
578588
let offsets_dtype = DType::Primitive(O::PTYPE, array.dtype().nullability());
579-
let offsets = cast(array.offsets(), &offsets_dtype)
580-
.map_err(|err| err.with_context(format!("Failed to cast offsets to {offsets_dtype}")))?
581-
.to_primitive();
582-
let sizes = cast(array.sizes(), &offsets_dtype)
583-
.map_err(|err| err.with_context(format!("Failed to cast sizes to {offsets_dtype}")))?
584-
.to_primitive();
589+
let offsets = array
590+
.offsets()
591+
.cast(offsets_dtype.clone())?
592+
.execute_vector(&LEGACY_SESSION)?
593+
.into_primitive()
594+
.downcast::<O>()
595+
.into_buffer()
596+
.into_arrow_scalar_buffer();
597+
let sizes = array
598+
.sizes()
599+
.cast(offsets_dtype)?
600+
.execute_vector(&LEGACY_SESSION)?
601+
.into_primitive()
602+
.downcast::<O>()
603+
.into_buffer()
604+
.into_arrow_scalar_buffer();
585605

586606
// Convert `offsets`, `sizes`, and `validity` to Arrow buffers.
587-
let arrow_offsets = offsets.buffer::<O>().into_arrow_scalar_buffer();
588-
let arrow_sizes = sizes.buffer::<O>().into_arrow_scalar_buffer();
589607
let nulls = to_null_buffer(array.validity_mask());
590608

591609
// Convert the child `elements` array to Arrow.
@@ -609,8 +627,8 @@ fn to_arrow_listview<O: IntegerPType + OffsetSizeTrait>(
609627

610628
Ok(Arc::new(GenericListViewArray::new(
611629
element_field,
612-
arrow_offsets,
613-
arrow_sizes,
630+
offsets,
631+
sizes,
614632
elements,
615633
nulls,
616634
)))

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,26 @@ use arrow_schema::Field;
1111
use arrow_schema::FieldRef;
1212
use vortex_dtype::DType;
1313
use vortex_dtype::IntegerPType;
14+
use vortex_dtype::PTypeDowncastExt;
1415
use vortex_error::VortexResult;
1516
use vortex_error::vortex_bail;
1617

1718
use crate::IntoArray;
18-
use crate::ToCanonical;
19+
use crate::LEGACY_SESSION;
20+
use crate::VectorExecutor;
1921
use crate::arrays::ListArray;
2022
use crate::arrays::ListVTable;
2123
use crate::arrays::list_view_from_list;
2224
use crate::arrow::IntoArrowArray;
2325
use crate::arrow::compute::ToArrowKernel;
2426
use crate::arrow::compute::ToArrowKernelAdapter;
27+
<<<<<<< Updated upstream
2528
use crate::arrow::null_buffer::to_null_buffer;
2629
use crate::compute::cast;
30+
=======
31+
use crate::arrow::compute::to_arrow::null_buffer::to_null_buffer;
32+
use crate::builtins::ArrayBuiltins;
33+
>>>>>>> Stashed changes
2734
use crate::register_kernel;
2835

2936
impl ToArrowKernel for ListVTable {
@@ -62,13 +69,16 @@ fn list_array_to_arrow_list<O: IntegerPType + OffsetSizeTrait>(
6269
element: Option<&FieldRef>,
6370
) -> VortexResult<ArrowArrayRef> {
6471
// First we cast the offsets and sizes into the specified width (determined by `O::PTYPE`).
65-
let offsets_dtype = DType::Primitive(O::PTYPE, array.dtype().nullability());
66-
let offsets = cast(array.offsets(), &offsets_dtype)
67-
.map_err(|err| err.with_context(format!("Failed to cast offsets to {offsets_dtype}")))?
68-
.to_primitive();
72+
let offsets = array
73+
.offsets()
74+
.cast(DType::Primitive(O::PTYPE, array.dtype().nullability()))?
75+
.execute_vector(&LEGACY_SESSION)?
76+
.into_primitive()
77+
.downcast::<O>()
78+
.into_buffer();
6979

7080
// Convert `offsets` and `validity` to Arrow buffers.
71-
let arrow_offsets = offsets.buffer::<O>().into_arrow_offset_buffer();
81+
let arrow_offsets = offsets.into_arrow_offset_buffer();
7282
let nulls = to_null_buffer(array.validity_mask());
7383

7484
// Convert the child `elements` array to Arrow.

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::sync::LazyLock;
1212
use arcref::ArcRef;
1313
use arrow_array::ArrayRef as ArrowArrayRef;
1414
use arrow_schema::DataType;
15+
use vortex_compute::arrow::IntoArrow;
1516
use vortex_dtype::DType;
1617
use vortex_dtype::arrow::FromArrowType;
1718
use vortex_error::VortexError;
@@ -21,6 +22,9 @@ use vortex_error::vortex_bail;
2122
use vortex_error::vortex_err;
2223

2324
use crate::Array;
25+
use crate::LEGACY_SESSION;
26+
use crate::USE_VORTEX_OPERATORS;
27+
use crate::VectorExecutor;
2428
use crate::arrow::array::ArrowArray;
2529
use crate::arrow::array::ArrowVTable;
2630
use crate::compute::ComputeFn;
@@ -124,15 +128,23 @@ impl ComputeFnVTable for ToArrow {
124128
return Ok(output);
125129
}
126130

127-
// Fall back to canonicalizing and then converting.
128131
if !array.is_canonical() {
129-
let canonical_array = array.to_canonical();
130-
let arrow_array = to_arrow_opts(
131-
canonical_array.as_ref(),
132-
&ToArrowOptions {
133-
arrow_type: arrow_type.cloned(),
134-
},
135-
)?;
132+
let arrow_array = if *USE_VORTEX_OPERATORS {
133+
array
134+
.to_array()
135+
.execute_vector(&LEGACY_SESSION)?
136+
.into_arrow()?
137+
} else {
138+
// Fall back to canonicalizing and then converting.
139+
let canonical_array = array.to_canonical();
140+
to_arrow_opts(
141+
canonical_array.as_ref(),
142+
&ToArrowOptions {
143+
arrow_type: arrow_type.cloned(),
144+
},
145+
)?
146+
};
147+
136148
return Ok(ArrowArray::new(arrow_array, array.dtype().nullability())
137149
.to_array()
138150
.into());

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,30 @@ use arrow_schema::DataType;
2121
use arrow_schema::TimeUnit as ArrowTimeUnit;
2222
use vortex_dtype::DType;
2323
use vortex_dtype::NativePType;
24+
use vortex_dtype::PTypeDowncastExt;
2425
use vortex_dtype::datetime::TemporalMetadata;
2526
use vortex_dtype::datetime::TimeUnit;
2627
use vortex_dtype::datetime::is_temporal_ext_type;
2728
use vortex_error::VortexExpect;
2829
use vortex_error::VortexResult;
2930
use vortex_error::vortex_bail;
3031

31-
use crate::Array as _;
3232
use crate::IntoArray;
33-
use crate::ToCanonical;
33+
use crate::LEGACY_SESSION;
34+
use crate::VectorExecutor;
3435
use crate::arrays::ExtensionVTable;
3536
use crate::arrays::TemporalArray;
3637
use crate::arrow::array::ArrowArray;
3738
use crate::arrow::compute::to_arrow::ToArrowArgs;
39+
<<<<<<< Updated upstream
3840
use crate::arrow::null_buffer::to_null_buffer;
41+
=======
42+
use crate::arrow::compute::to_arrow::null_buffer::to_null_buffer;
43+
use crate::builtins::ArrayBuiltins;
44+
>>>>>>> Stashed changes
3945
use crate::compute::InvocationArgs;
4046
use crate::compute::Kernel;
4147
use crate::compute::Output;
42-
use crate::compute::cast;
4348

4449
/// Implementation of `ToArrow` kernel for canonical Vortex arrays.
4550
#[derive(Debug)]
@@ -127,11 +132,17 @@ where
127132
T::Native: NativePType,
128133
{
129134
let values_dtype = DType::Primitive(T::Native::PTYPE, array.dtype().nullability());
130-
let values = cast(array.temporal_values(), &values_dtype)?
131-
.to_primitive()
132-
.into_buffer()
133-
.into_arrow_scalar_buffer();
134-
let nulls = to_null_buffer(array.temporal_values().validity_mask());
135+
let values = array
136+
.temporal_values()
137+
.cast(values_dtype)?
138+
.execute_vector(&LEGACY_SESSION)?
139+
.into_primitive()
140+
.downcast::<T::Native>();
141+
142+
let (buffer, validity) = values.into_parts();
143+
let values = buffer.into_arrow_scalar_buffer();
144+
let nulls = to_null_buffer(validity);
145+
135146
Ok(ArrowPrimitiveArray::<T>::new(values, nulls))
136147
}
137148

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ use vortex_dtype::DType;
1212
use vortex_dtype::IntegerPType;
1313
use vortex_dtype::Nullability;
1414
use vortex_dtype::PType;
15+
use vortex_dtype::PTypeDowncastExt;
1516
use vortex_error::VortexResult;
1617
use vortex_error::vortex_bail;
1718
use vortex_error::vortex_panic;
1819

1920
use crate::Array;
20-
use crate::ToCanonical;
21+
use crate::LEGACY_SESSION;
22+
use crate::VectorExecutor;
2123
use crate::arrays::VarBinArray;
2224
use crate::arrays::VarBinVTable;
2325
use crate::arrow::compute::ToArrowKernel;
@@ -82,7 +84,10 @@ fn to_arrow<O: IntegerPType + OffsetSizeTrait>(array: &VarBinArray) -> VortexRes
8284
array.offsets(),
8385
&DType::Primitive(O::PTYPE, Nullability::NonNullable),
8486
)?
85-
.to_primitive();
87+
.execute_vector(&LEGACY_SESSION)?
88+
.into_primitive()
89+
.downcast::<O>()
90+
.into_buffer();
8691

8792
let nulls = to_null_buffer(array.validity_mask());
8893
let data = array.bytes().clone();
@@ -91,14 +96,14 @@ fn to_arrow<O: IntegerPType + OffsetSizeTrait>(array: &VarBinArray) -> VortexRes
9196
Ok(match array.dtype() {
9297
DType::Binary(_) => Arc::new(unsafe {
9398
GenericBinaryArray::new_unchecked(
94-
offsets.buffer::<O>().into_arrow_offset_buffer(),
99+
offsets.into_arrow_offset_buffer(),
95100
data.into_arrow_buffer(),
96101
nulls,
97102
)
98103
}),
99104
DType::Utf8(_) => Arc::new(unsafe {
100105
GenericStringArray::new_unchecked(
101-
offsets.buffer::<O>().into_arrow_offset_buffer(),
106+
offsets.into_arrow_offset_buffer(),
102107
data.into_arrow_buffer(),
103108
nulls,
104109
)

vortex-array/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@
1212
//! Every data type recognized by Vortex also has a canonical physical encoding format, which
1313
//! arrays can be [canonicalized](Canonical) into for ease of access in compute functions.
1414
15+
use std::sync::LazyLock;
16+
1517
pub use array::*;
1618
pub use canonical::*;
1719
pub use context::*;
1820
pub use executor::*;
1921
pub use hash::*;
2022
pub use mask_future::*;
2123
pub use metadata::*;
24+
use vortex_session::VortexSession;
25+
26+
use crate::session::ArraySession;
2227

2328
pub mod accessor;
2429
#[doc(hidden)]
@@ -60,3 +65,15 @@ pub mod flatbuffers {
6065
//! Re-exported autogenerated code from the core Vortex flatbuffer definitions.
6166
pub use vortex_flatbuffers::array::*;
6267
}
68+
69+
static USE_VORTEX_OPERATORS: LazyLock<bool> = LazyLock::new(|| {
70+
std::env::var("VORTEX_OPERATORS")
71+
.map(|v| v == "1" || v.to_lowercase() == "true")
72+
.unwrap_or(false)
73+
});
74+
75+
// TODO(ngates): canonicalize doesn't currently take a session, therefore we cannot invoke execute
76+
// from the new array encodings to support back-compat for legacy encodings. So we hold a session
77+
// here...
78+
static LEGACY_SESSION: LazyLock<VortexSession> =
79+
LazyLock::new(|| VortexSession::empty().with::<ArraySession>());

0 commit comments

Comments
 (0)