Skip to content

Commit 1058e6d

Browse files
authored
Arrow Executor (#5647)
We eventually need to port all of our execution logic over to executing using Vectors + VortexSession. We can release this new API prior to deprecating the existing one. We should figure out what this API should be. Once the full operators change has finished, we should be able to pull this module out into vortex-arrow. --------- Signed-off-by: Nicholas Gates <[email protected]>
1 parent 50594d4 commit 1058e6d

File tree

44 files changed

+1547
-176
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1547
-176
lines changed

vortex-array/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ arcref = { workspace = true }
2525
arrow-arith = { workspace = true }
2626
arrow-array = { workspace = true, features = ["ffi"] }
2727
arrow-buffer = { workspace = true }
28+
arrow-cast = { workspace = true }
2829
arrow-data = { workspace = true }
2930
arrow-ord = { workspace = true }
3031
arrow-schema = { workspace = true }

vortex-array/src/array/mod.rs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::fmt::Debug;
88
use std::fmt::Formatter;
99
use std::hash::Hash;
1010
use std::hash::Hasher;
11+
use std::ops::Deref;
1112
use std::ops::Range;
1213
use std::sync::Arc;
1314

@@ -18,6 +19,7 @@ use vortex_dtype::Nullability;
1819
use vortex_error::VortexExpect;
1920
use vortex_error::VortexResult;
2021
use vortex_error::vortex_ensure;
22+
use vortex_error::vortex_err;
2123
use vortex_error::vortex_panic;
2224
use vortex_mask::Mask;
2325
use vortex_scalar::Scalar;
@@ -73,6 +75,9 @@ pub trait Array:
7375
/// Returns the array as a reference to a generic [`Any`] trait object.
7476
fn as_any(&self) -> &dyn Any;
7577

78+
/// Returns the array as an `Arc<dyn Any + Send + Sync>`.
79+
fn as_any_arc(self: Arc<Self>) -> Arc<dyn Any + Send + Sync>;
80+
7681
/// Returns the array as an [`ArrayRef`].
7782
fn to_array(&self) -> ArrayRef;
7883

@@ -211,6 +216,10 @@ impl Array for Arc<dyn Array> {
211216
self.as_ref().as_any()
212217
}
213218

219+
fn as_any_arc(self: Arc<Self>) -> Arc<dyn Any + Send + Sync> {
220+
self
221+
}
222+
214223
#[inline]
215224
fn to_array(&self) -> ArrayRef {
216225
self.clone()
@@ -350,6 +359,24 @@ impl dyn Array + '_ {
350359
.map(|array_adapter| &array_adapter.0)
351360
}
352361

362+
/// Returns the array downcast to the given `A` as an owned object.
363+
pub fn try_into<V: VTable>(self: Arc<Self>) -> Result<V::Array, Arc<Self>> {
364+
match self.is::<V>() {
365+
true => {
366+
let arc = self
367+
.as_any_arc()
368+
.downcast::<ArrayAdapter<V>>()
369+
.map_err(|_| vortex_err!("failed to downcast"))
370+
.vortex_expect("Failed to downcast");
371+
Ok(match Arc::try_unwrap(arc) {
372+
Ok(array) => array.0,
373+
Err(arc) => arc.deref().0.clone(),
374+
})
375+
}
376+
false => Err(self),
377+
}
378+
}
379+
353380
/// Is self an array with encoding from vtable `V`.
354381
pub fn is<V: VTable>(&self) -> bool {
355382
self.as_opt::<V>().is_some()
@@ -443,6 +470,10 @@ impl<V: VTable> Array for ArrayAdapter<V> {
443470
self
444471
}
445472

473+
fn as_any_arc(self: Arc<Self>) -> Arc<dyn Any + Send + Sync> {
474+
self
475+
}
476+
446477
fn to_array(&self) -> ArrayRef {
447478
Arc::new(ArrayAdapter::<V>(self.0.clone()))
448479
}
@@ -691,13 +722,6 @@ impl<V: VTable> Array for ArrayAdapter<V> {
691722
}
692723

693724
fn reduce_parent(&self, parent: &ArrayRef, child_idx: usize) -> VortexResult<Option<ArrayRef>> {
694-
#[cfg(debug_assertions)]
695-
vortex_ensure!(
696-
Arc::as_ptr(&parent.children()[child_idx]) == self,
697-
"Parent array's child at index {} does not match self",
698-
child_idx
699-
);
700-
701725
let Some(reduced) = V::reduce_parent(&self.0, parent, child_idx)? else {
702726
return Ok(None);
703727
};

vortex-array/src/arrays/dict/array.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ impl DictArray {
114114
Ok(unsafe { Self::new_unchecked(codes, values) })
115115
}
116116

117+
pub fn into_parts(self) -> (ArrayRef, ArrayRef) {
118+
(self.codes, self.values)
119+
}
120+
117121
#[inline]
118122
pub fn codes(&self) -> &ArrayRef {
119123
&self.codes

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,8 @@ impl FilterArray {
3030
stats: ArrayStats::default(),
3131
}
3232
}
33+
34+
pub fn mask(&self) -> &Mask {
35+
&self.mask
36+
}
3337
}

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/listview/array.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ impl ListViewArray {
319319
.is_ok()
320320
}
321321

322+
pub fn into_parts(self) -> (ArrayRef, ArrayRef, ArrayRef, Validity) {
323+
(self.elements, self.offsets, self.sizes, self.validity)
324+
}
325+
322326
/// Returns the offset at the given index.
323327
///
324328
/// Note that it is possible the corresponding list view is null (which is only defined by the

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/rules.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@ use crate::expr::ReduceNode;
2727
use crate::expr::ReduceNodeRef;
2828
use crate::expr::ScalarFn;
2929
use crate::optimizer::rules::ArrayReduceRule;
30+
use crate::optimizer::rules::ParentRuleSet;
3031
use crate::optimizer::rules::ReduceRuleSet;
3132

3233
pub(super) const RULES: ReduceRuleSet<ScalarFnVTable> =
3334
ReduceRuleSet::new(&[&ScalarFnConstantRule, &ScalarFnAbstractReduceRule]);
3435

36+
pub(super) const PARENT_RULES: ParentRuleSet<ScalarFnVTable> = ParentRuleSet::new(&[]);
37+
3538
#[derive(Debug)]
3639
struct ScalarFnConstantRule;
3740
impl ArrayReduceRule<ScalarFnVTable> for ScalarFnConstantRule {

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/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use crate::arrays::scalar_fn::array::ScalarFnArray;
2525
use crate::arrays::scalar_fn::kernel::KernelInput;
2626
use crate::arrays::scalar_fn::kernel::ScalarFnKernel;
2727
use crate::arrays::scalar_fn::metadata::ScalarFnMetadata;
28+
use crate::arrays::scalar_fn::rules::PARENT_RULES;
2829
use crate::arrays::scalar_fn::rules::RULES;
2930
use crate::expr;
3031
use crate::expr::ExprVTable;
@@ -167,6 +168,14 @@ impl VTable for ScalarFnVTable {
167168
fn reduce(array: &Self::Array) -> VortexResult<Option<ArrayRef>> {
168169
RULES.evaluate(array)
169170
}
171+
172+
fn reduce_parent(
173+
array: &Self::Array,
174+
parent: &ArrayRef,
175+
child_idx: usize,
176+
) -> VortexResult<Option<ArrayRef>> {
177+
PARENT_RULES.evaluate(array, parent, child_idx)
178+
}
170179
}
171180

172181
/// Array factory functions for scalar functions.

0 commit comments

Comments
 (0)