Skip to content

Commit 71714ac

Browse files
committed
u
Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
1 parent 6414f5f commit 71714ac

5 files changed

Lines changed: 100 additions & 71 deletions

File tree

encodings/alp/src/alp/array.rs

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use vortex_array::dtype::PType;
2323
use vortex_array::patches::Patches;
2424
use vortex_array::patches::PatchesMetadata;
2525
use vortex_array::require_child;
26+
use vortex_array::require_patches;
2627
use vortex_array::serde::ArrayChildren;
2728
use vortex_array::stats::ArrayStats;
2829
use vortex_array::stats::StatsSetRef;
@@ -194,34 +195,13 @@ impl VTable for ALP {
194195

195196
fn execute(array: Arc<Array<Self>>, ctx: &mut ExecutionCtx) -> VortexResult<ExecutionResult> {
196197
let array = require_child!(array, array.encoded(), ENCODED_SLOT => Primitive);
197-
if array
198-
.patches()
199-
.is_some_and(|p| !p.indices().is::<Primitive>())
200-
{
201-
return Ok(ExecutionResult::execute_slot::<Primitive>(
202-
array,
203-
PATCH_INDICES_SLOT,
204-
));
205-
}
206-
if array
207-
.patches()
208-
.is_some_and(|p| !p.values().is::<Primitive>())
209-
{
210-
return Ok(ExecutionResult::execute_slot::<Primitive>(
211-
array,
212-
PATCH_VALUES_SLOT,
213-
));
214-
}
215-
if array.patches().is_some_and(|p| {
216-
p.chunk_offsets()
217-
.as_ref()
218-
.is_some_and(|co| !co.is::<Primitive>())
219-
}) {
220-
return Ok(ExecutionResult::execute_slot::<Primitive>(
221-
array,
222-
PATCH_CHUNK_OFFSETS_SLOT,
223-
));
224-
}
198+
require_patches!(
199+
array,
200+
array.patches(),
201+
PATCH_INDICES_SLOT,
202+
PATCH_VALUES_SLOT,
203+
PATCH_CHUNK_OFFSETS_SLOT
204+
);
225205

226206
Ok(ExecutionResult::done(
227207
execute_decompress(Arc::unwrap_or_clone(array).into_inner(), ctx)?.into_array(),

encodings/alp/src/alp_rd/array.rs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use vortex_array::dtype::PType;
2626
use vortex_array::patches::Patches;
2727
use vortex_array::patches::PatchesMetadata;
2828
use vortex_array::require_child;
29+
use vortex_array::require_patches;
2930
use vortex_array::serde::ArrayChildren;
3031
use vortex_array::stats::ArrayStats;
3132
use vortex_array::stats::StatsSetRef;
@@ -271,24 +272,13 @@ impl VTable for ALPRD {
271272
fn execute(array: Arc<Array<Self>>, ctx: &mut ExecutionCtx) -> VortexResult<ExecutionResult> {
272273
let array = require_child!(array, array.left_parts(), 0 => Primitive);
273274
let array = require_child!(array, array.right_parts(), 1 => Primitive);
274-
if array
275-
.left_parts_patches()
276-
.is_some_and(|p| !p.indices().is::<Primitive>())
277-
{
278-
return Ok(ExecutionResult::execute_slot::<Primitive>(
279-
array,
280-
LP_PATCH_INDICES_SLOT,
281-
));
282-
}
283-
if array
284-
.left_parts_patches()
285-
.is_some_and(|p| !p.values().is::<Primitive>())
286-
{
287-
return Ok(ExecutionResult::execute_slot::<Primitive>(
288-
array,
289-
LP_PATCH_VALUES_SLOT,
290-
));
291-
}
275+
require_patches!(
276+
array,
277+
array.left_parts_patches(),
278+
LP_PATCH_INDICES_SLOT,
279+
LP_PATCH_VALUES_SLOT,
280+
LP_PATCH_CHUNK_OFFSETS_SLOT
281+
);
292282

293283
let right_bit_width = array.right_bit_width();
294284
let ALPRDArrayParts {

encodings/fastlanes/src/bitpacking/vtable/mod.rs

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ use vortex_array::IntoArray;
1515
use vortex_array::Precision;
1616
use vortex_array::ProstMetadata;
1717
use vortex_array::SerializeMetadata;
18-
use vortex_array::arrays::Primitive;
1918
use vortex_array::buffer::BufferHandle;
2019
use vortex_array::builders::ArrayBuilder;
2120
use vortex_array::dtype::DType;
2221
use vortex_array::dtype::PType;
2322
use vortex_array::match_each_integer_ptype;
2423
use vortex_array::patches::Patches;
2524
use vortex_array::patches::PatchesMetadata;
25+
use vortex_array::require_patches;
26+
use vortex_array::require_validity;
2627
use vortex_array::serde::ArrayChildren;
2728
use vortex_array::stats::StatsSetRef;
2829
use vortex_array::validity::Validity;
@@ -288,30 +289,14 @@ impl VTable for BitPacked {
288289
}
289290

290291
fn execute(array: Arc<Array<Self>>, ctx: &mut ExecutionCtx) -> VortexResult<ExecutionResult> {
291-
if array
292-
.patches()
293-
.is_some_and(|p| !p.indices().is::<Primitive>())
294-
{
295-
return Ok(ExecutionResult::execute_slot::<Primitive>(
296-
array,
297-
PATCH_INDICES_SLOT,
298-
));
299-
}
300-
if array
301-
.patches()
302-
.is_some_and(|p| !p.values().is::<Primitive>())
303-
{
304-
return Ok(ExecutionResult::execute_slot::<Primitive>(
305-
array,
306-
PATCH_VALUES_SLOT,
307-
));
308-
}
309-
if matches!(&array.validity, Validity::Array(v) if !v.is::<AnyCanonical>()) {
310-
return Ok(ExecutionResult::execute_slot::<AnyCanonical>(
311-
array,
312-
VALIDITY_SLOT,
313-
));
314-
}
292+
require_patches!(
293+
array,
294+
array.patches(),
295+
PATCH_INDICES_SLOT,
296+
PATCH_VALUES_SLOT,
297+
PATCH_CHUNK_OFFSETS_SLOT
298+
);
299+
require_validity!(array, &array.validity, VALIDITY_SLOT => AnyCanonical);
315300

316301
Ok(ExecutionResult::done(
317302
unpack_array(&array, ctx)?.into_array(),

vortex-array/public-api.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24082,6 +24082,12 @@ pub macro vortex_array::match_smallest_offset_type!
2408224082

2408324083
pub macro vortex_array::require_child!
2408424084

24085+
pub macro vortex_array::require_opt_child!
24086+
24087+
pub macro vortex_array::require_patches!
24088+
24089+
pub macro vortex_array::require_validity!
24090+
2408524091
pub macro vortex_array::vtable!
2408624092

2408724093
pub enum vortex_array::Canonical

vortex-array/src/executor.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,74 @@ macro_rules! require_child {
477477
}};
478478
}
479479

480+
/// Like [`require_child!`], but for optional children. If the child is `None`, this is a no-op.
481+
/// If the child is `Some` but does not match `$M`, early-returns an [`ExecutionResult`] requesting
482+
/// execution of child `$idx`.
483+
///
484+
/// Unlike `require_child!`, this is a statement macro (no value produced) and does not clone
485+
/// `$parent` — it is moved into the early-return path.
486+
///
487+
/// ```ignore
488+
/// require_opt_child!(array, array.patches().map(|p| p.indices()), 1 => Primitive);
489+
/// ```
490+
#[macro_export]
491+
macro_rules! require_opt_child {
492+
($parent:expr, $child_opt:expr, $idx:expr => $M:ty) => {
493+
if $child_opt.is_some_and(|child| !child.is::<$M>()) {
494+
return Ok($crate::ExecutionResult::execute_slot::<$M>($parent, $idx));
495+
}
496+
};
497+
}
498+
499+
/// Require that all children of a [`Patches`](crate::patches::Patches) (indices, values, and
500+
/// optionally chunk_offsets) are `Primitive`. If no patches are present, this is a no-op.
501+
///
502+
/// Like [`require_opt_child!`], `$parent` is moved (not cloned) into the early-return path.
503+
///
504+
/// ```ignore
505+
/// require_patches!(array, array.patches(), PATCH_INDICES_SLOT, PATCH_VALUES_SLOT, PATCH_CHUNK_OFFSETS_SLOT);
506+
/// ```
507+
#[macro_export]
508+
macro_rules! require_patches {
509+
($parent:expr, $patches:expr, $indices_slot:expr, $values_slot:expr, $chunk_offsets_slot:expr) => {
510+
$crate::require_opt_child!(
511+
$parent,
512+
$patches.map(|p| p.indices()),
513+
$indices_slot => $crate::arrays::Primitive
514+
);
515+
$crate::require_opt_child!(
516+
$parent,
517+
$patches.map(|p| p.values()),
518+
$values_slot => $crate::arrays::Primitive
519+
);
520+
$crate::require_opt_child!(
521+
$parent,
522+
$patches.and_then(|p| p.chunk_offsets().as_ref()),
523+
$chunk_offsets_slot => $crate::arrays::Primitive
524+
);
525+
};
526+
}
527+
528+
/// Require that a [`Validity::Array`] child matches `$M`. If validity is not array-backed
529+
/// (e.g. `NonNullable` or `AllValid`), this is a no-op. If it is array-backed but does not
530+
/// match `$M`, early-returns an [`ExecutionResult`] requesting execution of the validity slot.
531+
///
532+
/// Like [`require_opt_child!`], `$parent` is moved (not cloned) into the early-return path.
533+
///
534+
/// ```ignore
535+
/// require_validity!(array, &array.validity, VALIDITY_SLOT => AnyCanonical);
536+
/// ```
537+
#[macro_export]
538+
macro_rules! require_validity {
539+
($parent:expr, $validity:expr, $idx:expr => $M:ty) => {
540+
if let $crate::validity::Validity::Array(v) = $validity {
541+
if !v.is::<$M>() {
542+
return Ok($crate::ExecutionResult::execute_slot::<$M>($parent, $idx));
543+
}
544+
}
545+
};
546+
}
547+
480548
/// Extension trait for creating an execution context from a session.
481549
pub trait VortexSessionExecute {
482550
/// Create a new execution context from this session.

0 commit comments

Comments
 (0)