Skip to content

Commit 7d9fc3d

Browse files
committed
wip: chunked iter exe
Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
1 parent b80f796 commit 7d9fc3d

File tree

9 files changed

+149
-51
lines changed

9 files changed

+149
-51
lines changed

vortex-array/public-api.lock

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3364,7 +3364,7 @@ pub fn vortex_array::arrays::patched::Patched::deserialize(bytes: &[u8], _dtype:
33643364

33653365
pub fn vortex_array::arrays::patched::Patched::dtype(array: &Self::Array) -> &vortex_array::dtype::DType
33663366

3367-
pub fn vortex_array::arrays::patched::Patched::execute(array: alloc::sync::Arc<vortex_array::vtable::Array<Self>>, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::ExecutionResult>
3367+
pub fn vortex_array::arrays::patched::Patched::execute(array: alloc::sync::Arc<vortex_array::vtable::Array<Self>>, _ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::ExecutionResult>
33683368

33693369
pub fn vortex_array::arrays::patched::Patched::execute_parent(array: &vortex_array::vtable::Array<Self>, parent: &vortex_array::ArrayRef, child_idx: usize, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
33703370

@@ -3416,6 +3416,10 @@ pub fn vortex_array::arrays::patched::PatchedArray::from_array_and_patches(inner
34163416

34173417
impl vortex_array::arrays::patched::PatchedArray
34183418

3419+
pub fn vortex_array::arrays::patched::PatchedArray::into_parts(self) -> vortex_array::arrays::patched::PatchedArrayParts
3420+
3421+
impl vortex_array::arrays::patched::PatchedArray
3422+
34193423
pub fn vortex_array::arrays::patched::PatchedArray::to_array(&self) -> vortex_array::ArrayRef
34203424

34213425
impl core::clone::Clone for vortex_array::arrays::patched::PatchedArray
@@ -3444,6 +3448,22 @@ impl vortex_array::IntoArray for vortex_array::arrays::patched::PatchedArray
34443448

34453449
pub fn vortex_array::arrays::patched::PatchedArray::into_array(self) -> vortex_array::ArrayRef
34463450

3451+
pub struct vortex_array::arrays::patched::PatchedArrayParts
3452+
3453+
pub vortex_array::arrays::patched::PatchedArrayParts::indices: vortex_array::ArrayRef
3454+
3455+
pub vortex_array::arrays::patched::PatchedArrayParts::inner: vortex_array::ArrayRef
3456+
3457+
pub vortex_array::arrays::patched::PatchedArrayParts::lane_offsets: vortex_array::ArrayRef
3458+
3459+
pub vortex_array::arrays::patched::PatchedArrayParts::len: usize
3460+
3461+
pub vortex_array::arrays::patched::PatchedArrayParts::n_lanes: usize
3462+
3463+
pub vortex_array::arrays::patched::PatchedArrayParts::offset: usize
3464+
3465+
pub vortex_array::arrays::patched::PatchedArrayParts::values: vortex_array::ArrayRef
3466+
34473467
pub struct vortex_array::arrays::patched::PatchedMetadata
34483468

34493469
impl core::clone::Clone for vortex_array::arrays::patched::PatchedMetadata
@@ -4148,7 +4168,7 @@ pub fn vortex_array::arrays::slice::Slice::deserialize(_bytes: &[u8], _dtype: &v
41484168

41494169
pub fn vortex_array::arrays::slice::Slice::dtype(array: &vortex_array::arrays::slice::SliceArray) -> &vortex_array::dtype::DType
41504170

4151-
pub fn vortex_array::arrays::slice::Slice::execute(array: alloc::sync::Arc<vortex_array::vtable::Array<Self>>, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::ExecutionResult>
4171+
pub fn vortex_array::arrays::slice::Slice::execute(array: alloc::sync::Arc<vortex_array::vtable::Array<Self>>, _ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::ExecutionResult>
41524172

41534173
pub fn vortex_array::arrays::slice::Slice::execute_parent(array: &vortex_array::vtable::Array<Self>, parent: &vortex_array::ArrayRef, child_idx: usize, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
41544174

@@ -7332,7 +7352,7 @@ pub fn vortex_array::arrays::patched::Patched::deserialize(bytes: &[u8], _dtype:
73327352

73337353
pub fn vortex_array::arrays::patched::Patched::dtype(array: &Self::Array) -> &vortex_array::dtype::DType
73347354

7335-
pub fn vortex_array::arrays::patched::Patched::execute(array: alloc::sync::Arc<vortex_array::vtable::Array<Self>>, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::ExecutionResult>
7355+
pub fn vortex_array::arrays::patched::Patched::execute(array: alloc::sync::Arc<vortex_array::vtable::Array<Self>>, _ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::ExecutionResult>
73367356

73377357
pub fn vortex_array::arrays::patched::Patched::execute_parent(array: &vortex_array::vtable::Array<Self>, parent: &vortex_array::ArrayRef, child_idx: usize, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
73387358

@@ -7384,6 +7404,10 @@ pub fn vortex_array::arrays::patched::PatchedArray::from_array_and_patches(inner
73847404

73857405
impl vortex_array::arrays::patched::PatchedArray
73867406

7407+
pub fn vortex_array::arrays::patched::PatchedArray::into_parts(self) -> vortex_array::arrays::patched::PatchedArrayParts
7408+
7409+
impl vortex_array::arrays::patched::PatchedArray
7410+
73877411
pub fn vortex_array::arrays::patched::PatchedArray::to_array(&self) -> vortex_array::ArrayRef
73887412

73897413
impl core::clone::Clone for vortex_array::arrays::patched::PatchedArray
@@ -7942,7 +7966,7 @@ pub fn vortex_array::arrays::slice::Slice::deserialize(_bytes: &[u8], _dtype: &v
79427966

79437967
pub fn vortex_array::arrays::slice::Slice::dtype(array: &vortex_array::arrays::slice::SliceArray) -> &vortex_array::dtype::DType
79447968

7945-
pub fn vortex_array::arrays::slice::Slice::execute(array: alloc::sync::Arc<vortex_array::vtable::Array<Self>>, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::ExecutionResult>
7969+
pub fn vortex_array::arrays::slice::Slice::execute(array: alloc::sync::Arc<vortex_array::vtable::Array<Self>>, _ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::ExecutionResult>
79467970

79477971
pub fn vortex_array::arrays::slice::Slice::execute_parent(array: &vortex_array::vtable::Array<Self>, parent: &vortex_array::ArrayRef, child_idx: usize, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
79487972

@@ -22324,7 +22348,7 @@ pub fn vortex_array::arrays::patched::Patched::deserialize(bytes: &[u8], _dtype:
2232422348

2232522349
pub fn vortex_array::arrays::patched::Patched::dtype(array: &Self::Array) -> &vortex_array::dtype::DType
2232622350

22327-
pub fn vortex_array::arrays::patched::Patched::execute(array: alloc::sync::Arc<vortex_array::vtable::Array<Self>>, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::ExecutionResult>
22351+
pub fn vortex_array::arrays::patched::Patched::execute(array: alloc::sync::Arc<vortex_array::vtable::Array<Self>>, _ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::ExecutionResult>
2232822352

2232922353
pub fn vortex_array::arrays::patched::Patched::execute_parent(array: &vortex_array::vtable::Array<Self>, parent: &vortex_array::ArrayRef, child_idx: usize, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
2233022354

@@ -22444,7 +22468,7 @@ pub fn vortex_array::arrays::slice::Slice::deserialize(_bytes: &[u8], _dtype: &v
2244422468

2244522469
pub fn vortex_array::arrays::slice::Slice::dtype(array: &vortex_array::arrays::slice::SliceArray) -> &vortex_array::dtype::DType
2244622470

22447-
pub fn vortex_array::arrays::slice::Slice::execute(array: alloc::sync::Arc<vortex_array::vtable::Array<Self>>, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::ExecutionResult>
22471+
pub fn vortex_array::arrays::slice::Slice::execute(array: alloc::sync::Arc<vortex_array::vtable::Array<Self>>, _ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::ExecutionResult>
2244822472

2244922473
pub fn vortex_array::arrays::slice::Slice::execute_parent(array: &vortex_array::vtable::Array<Self>, parent: &vortex_array::ArrayRef, child_idx: usize, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
2245022474

@@ -23768,7 +23792,7 @@ pub fn vortex_array::arrays::patched::Patched::deserialize(bytes: &[u8], _dtype:
2376823792

2376923793
pub fn vortex_array::arrays::patched::Patched::dtype(array: &Self::Array) -> &vortex_array::dtype::DType
2377023794

23771-
pub fn vortex_array::arrays::patched::Patched::execute(array: alloc::sync::Arc<vortex_array::vtable::Array<Self>>, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::ExecutionResult>
23795+
pub fn vortex_array::arrays::patched::Patched::execute(array: alloc::sync::Arc<vortex_array::vtable::Array<Self>>, _ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::ExecutionResult>
2377223796

2377323797
pub fn vortex_array::arrays::patched::Patched::execute_parent(array: &vortex_array::vtable::Array<Self>, parent: &vortex_array::ArrayRef, child_idx: usize, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
2377423798

@@ -23888,7 +23912,7 @@ pub fn vortex_array::arrays::slice::Slice::deserialize(_bytes: &[u8], _dtype: &v
2388823912

2388923913
pub fn vortex_array::arrays::slice::Slice::dtype(array: &vortex_array::arrays::slice::SliceArray) -> &vortex_array::dtype::DType
2389023914

23891-
pub fn vortex_array::arrays::slice::Slice::execute(array: alloc::sync::Arc<vortex_array::vtable::Array<Self>>, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::ExecutionResult>
23915+
pub fn vortex_array::arrays::slice::Slice::execute(array: alloc::sync::Arc<vortex_array::vtable::Array<Self>>, _ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::ExecutionResult>
2389223916

2389323917
pub fn vortex_array::arrays::slice::Slice::execute_parent(array: &vortex_array::vtable::Array<Self>, parent: &vortex_array::ArrayRef, child_idx: usize, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
2389423918

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ use vortex_error::vortex_panic;
1313
use vortex_mask::Mask;
1414
use vortex_session::VortexSession;
1515

16+
use crate::AnyCanonical;
1617
use crate::ArrayEq;
1718
use crate::ArrayHash;
1819
use crate::ArrayRef;
1920
use crate::DynArray;
2021
use crate::IntoArray;
2122
use crate::Precision;
23+
use crate::arrays::filter::array::CHILD_SLOT;
2224
use crate::arrays::filter::array::FilterArray;
2325
use crate::arrays::filter::array::NUM_SLOTS;
2426
use crate::arrays::filter::array::SLOT_NAMES;
@@ -30,6 +32,7 @@ use crate::buffer::BufferHandle;
3032
use crate::dtype::DType;
3133
use crate::executor::ExecutionCtx;
3234
use crate::executor::ExecutionResult;
35+
use crate::require_child;
3336
use crate::scalar::Scalar;
3437
use crate::serde::ArrayChildren;
3538
use crate::stats::StatsSetRef;
@@ -151,14 +154,18 @@ impl VTable for Filter {
151154
if let Some(canonical) = execute_filter_fast_paths(&array, ctx)? {
152155
return Ok(ExecutionResult::done(canonical));
153156
}
157+
158+
let array = require_child!(array, array.child(), CHILD_SLOT => AnyCanonical);
159+
154160
let Mask::Values(mask_values) = &array.mask else {
155161
unreachable!("`execute_filter_fast_paths` handles AllTrue and AllFalse")
156162
};
157163

158-
// We rely on the optimization pass that runs prior to this execution for filter pushdown,
159-
// so now we can just execute the filter without worrying.
164+
// Child is pre-canonicalized — apply the filter directly.
165+
debug_assert!(array.child().is_canonical());
166+
let child = array.child().to_canonical()?;
160167
Ok(ExecutionResult::done(
161-
execute_filter(array.child().clone().execute(ctx)?, mask_values).into_array(),
168+
execute_filter(child, mask_values).into_array(),
162169
))
163170
}
164171

vortex-array/src/arrays/list/vtable/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ use crate::IntoArray;
1818
use crate::Precision;
1919
use crate::ProstMetadata;
2020
use crate::arrays::ListArray;
21+
use crate::arrays::Primitive;
2122
use crate::arrays::list::array::NUM_SLOTS;
23+
use crate::arrays::list::array::OFFSETS_SLOT;
2224
use crate::arrays::list::array::SLOT_NAMES;
2325
use crate::arrays::list::array::VALIDITY_SLOT;
2426
use crate::arrays::list::compute::PARENT_KERNELS;
@@ -32,6 +34,7 @@ use crate::hash::ArrayEq;
3234
use crate::hash::ArrayHash;
3335
use crate::metadata::DeserializeMetadata;
3436
use crate::metadata::SerializeMetadata;
37+
use crate::require_child;
3538
use crate::serde::ArrayChildren;
3639
use crate::stats::StatsSetRef;
3740
use crate::validity::Validity;
@@ -193,6 +196,7 @@ impl VTable for List {
193196
}
194197

195198
fn execute(array: Arc<Array<Self>>, ctx: &mut ExecutionCtx) -> VortexResult<ExecutionResult> {
199+
let array = require_child!(array, array.offsets(), OFFSETS_SLOT => Primitive);
196200
Ok(ExecutionResult::done(
197201
list_view_from_list(ListArray::clone(&array), ctx)?.into_array(),
198202
))

vortex-array/src/arrays/masked/vtable/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ use vortex_error::vortex_ensure;
1313
use vortex_error::vortex_panic;
1414
use vortex_session::VortexSession;
1515

16+
use crate::AnyCanonical;
1617
use crate::ArrayRef;
17-
use crate::Canonical;
1818
use crate::EmptyMetadata;
1919
use crate::IntoArray;
2020
use crate::Precision;
2121
use crate::arrays::ConstantArray;
2222
use crate::arrays::MaskedArray;
23+
use crate::arrays::masked::array::CHILD_SLOT;
2324
use crate::arrays::masked::array::NUM_SLOTS;
2425
use crate::arrays::masked::array::SLOT_NAMES;
2526
use crate::arrays::masked::compute::rules::PARENT_RULES;
@@ -30,6 +31,7 @@ use crate::executor::ExecutionCtx;
3031
use crate::executor::ExecutionResult;
3132
use crate::hash::ArrayEq;
3233
use crate::hash::ArrayHash;
34+
use crate::require_child;
3335
use crate::scalar::Scalar;
3436
use crate::serde::ArrayChildren;
3537
use crate::stats::StatsSetRef;
@@ -162,7 +164,10 @@ impl VTable for Masked {
162164
// While we could manually convert the dtype, `mask_validity_canonical` is already O(1) for
163165
// `AllTrue` masks (no data copying), so there's no benefit.
164166

165-
let child = array.child().clone().execute::<Canonical>(ctx)?;
167+
let array = require_child!(array, array.child(), CHILD_SLOT => AnyCanonical);
168+
169+
debug_assert!(array.child().is_canonical());
170+
let child = array.child().to_canonical()?;
166171
Ok(ExecutionResult::done(
167172
mask_validity_canonical(child, &validity_mask, ctx)?.into_array(),
168173
))

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,47 @@ impl PatchedArray {
205205
}
206206
}
207207

208+
/// The owned parts of a [`PatchedArray`], produced by [`PatchedArray::into_parts`].
209+
pub struct PatchedArrayParts {
210+
/// The inner array being patched.
211+
pub inner: ArrayRef,
212+
/// The lane offsets array (u32).
213+
pub lane_offsets: ArrayRef,
214+
/// The patch indices array (u16).
215+
pub indices: ArrayRef,
216+
/// The patch values array.
217+
pub values: ArrayRef,
218+
/// Number of lanes.
219+
pub n_lanes: usize,
220+
/// Offset into the first chunk.
221+
pub offset: usize,
222+
/// Logical length.
223+
pub len: usize,
224+
}
225+
226+
impl PatchedArray {
227+
/// Consume this array into its owned parts.
228+
pub fn into_parts(mut self) -> PatchedArrayParts {
229+
PatchedArrayParts {
230+
inner: self.slots[INNER_SLOT]
231+
.take()
232+
.vortex_expect("PatchedArray inner slot"),
233+
lane_offsets: self.slots[LANE_OFFSETS_SLOT]
234+
.take()
235+
.vortex_expect("PatchedArray lane_offsets slot"),
236+
indices: self.slots[INDICES_SLOT]
237+
.take()
238+
.vortex_expect("PatchedArray indices slot"),
239+
values: self.slots[VALUES_SLOT]
240+
.take()
241+
.vortex_expect("PatchedArray values slot"),
242+
n_lanes: self.n_lanes,
243+
offset: self.offset,
244+
len: self.len,
245+
}
246+
}
247+
}
248+
208249
impl PatchedArray {
209250
/// Returns a reference to the base array being patched.
210251
#[inline]

vortex-array/src/arrays/patched/vtable/mod.rs

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,16 @@ use crate::IntoArray;
2828
use crate::Precision;
2929
use crate::ProstMetadata;
3030
use crate::SerializeMetadata;
31+
use crate::arrays::Primitive;
3132
use crate::arrays::PrimitiveArray;
3233
use crate::arrays::patched::PatchedArray;
34+
use crate::arrays::patched::PatchedArrayParts;
35+
use crate::arrays::patched::array::INDICES_SLOT;
36+
use crate::arrays::patched::array::INNER_SLOT;
37+
use crate::arrays::patched::array::LANE_OFFSETS_SLOT;
3338
use crate::arrays::patched::array::NUM_SLOTS;
3439
use crate::arrays::patched::array::SLOT_NAMES;
40+
use crate::arrays::patched::array::VALUES_SLOT;
3541
use crate::arrays::patched::compute::rules::PARENT_RULES;
3642
use crate::arrays::patched::vtable::kernels::PARENT_KERNELS;
3743
use crate::arrays::primitive::PrimitiveArrayParts;
@@ -42,6 +48,7 @@ use crate::dtype::DType;
4248
use crate::dtype::NativePType;
4349
use crate::dtype::PType;
4450
use crate::match_each_native_ptype;
51+
use crate::require_child;
4552
use crate::serde::ArrayChildren;
4653
use crate::stats::ArrayStats;
4754
use crate::stats::StatsSetRef;
@@ -288,45 +295,53 @@ impl VTable for Patched {
288295
Ok(())
289296
}
290297

291-
fn execute(array: Arc<Array<Self>>, ctx: &mut ExecutionCtx) -> VortexResult<ExecutionResult> {
292-
let inner = array
293-
.base_array()
294-
.clone()
295-
.execute::<Canonical>(ctx)?
296-
.into_primitive();
298+
fn execute(array: Arc<Array<Self>>, _ctx: &mut ExecutionCtx) -> VortexResult<ExecutionResult> {
299+
let array = require_child!(array, array.base_array(), INNER_SLOT => Primitive);
300+
let array = require_child!(array, array.lane_offsets(), LANE_OFFSETS_SLOT => Primitive);
301+
let array = require_child!(array, array.patch_indices(), INDICES_SLOT => Primitive);
302+
let array = require_child!(array, array.patch_values(), VALUES_SLOT => Primitive);
303+
304+
let PatchedArrayParts {
305+
inner,
306+
lane_offsets,
307+
indices,
308+
values,
309+
n_lanes,
310+
offset,
311+
len,
312+
} = Arc::unwrap_or_clone(array).into_inner().into_parts();
313+
314+
let inner = inner
315+
.try_into::<Primitive>()
316+
.ok()
317+
.vortex_expect("base_array pre-canonicalized to Primitive");
318+
let lane_offsets = lane_offsets
319+
.try_into::<Primitive>()
320+
.ok()
321+
.vortex_expect("lane_offsets pre-canonicalized to Primitive");
322+
let indices = indices
323+
.try_into::<Primitive>()
324+
.ok()
325+
.vortex_expect("patch_indices pre-canonicalized to Primitive");
326+
let values = values
327+
.try_into::<Primitive>()
328+
.ok()
329+
.vortex_expect("patch_values pre-canonicalized to Primitive");
297330

298331
let PrimitiveArrayParts {
299332
buffer,
300333
ptype,
301334
validity,
302335
} = inner.into_parts();
303336

304-
let lane_offsets = array
305-
.lane_offsets()
306-
.clone()
307-
.execute::<PrimitiveArray>(ctx)?;
308-
let indices = array
309-
.patch_indices()
310-
.clone()
311-
.execute::<PrimitiveArray>(ctx)?;
312-
313-
// TODO(aduffy): add support for non-primitive PatchedArray patches application (?)
314-
let values = array
315-
.patch_values()
316-
.clone()
317-
.execute::<PrimitiveArray>(ctx)?;
318-
319337
let patched_values = match_each_native_ptype!(values.ptype(), |V| {
320-
let offset = array.offset;
321-
let len = array.len;
322-
323338
let mut output = Buffer::<V>::from_byte_buffer(buffer.unwrap_host()).into_mut();
324339

325340
apply_patches_primitive::<V>(
326341
&mut output,
327342
offset,
328343
len,
329-
array.n_lanes,
344+
n_lanes,
330345
lane_offsets.as_slice::<u32>(),
331346
indices.as_slice::<u16>(),
332347
values.as_slice::<V>(),

0 commit comments

Comments
 (0)