Skip to content

Commit 60ce4b5

Browse files
authored
PrimitiveArray operator vtable (#5091)
Signed-off-by: Nicholas Gates <[email protected]>
1 parent b645a51 commit 60ce4b5

File tree

3 files changed

+39
-87
lines changed

3 files changed

+39
-87
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{EncodingId, EncodingRef, vtable};
88
mod array;
99
mod canonical;
1010
mod operations;
11-
mod pipeline;
11+
mod operator;
1212
mod serde;
1313
mod validity;
1414
mod visitor;
@@ -26,8 +26,8 @@ impl VTable for PrimitiveVTable {
2626
type VisitorVTable = Self;
2727
type ComputeVTable = NotSupported;
2828
type EncodeVTable = NotSupported;
29-
type OperatorVTable = Self;
3029
type SerdeVTable = Self;
30+
type OperatorVTable = Self;
3131

3232
fn id(_encoding: &Self::Encoding) -> EncodingId {
3333
EncodingId::new_ref("vortex.primitive")
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
use vortex_compute::filter::Filter;
5+
use vortex_dtype::match_each_native_ptype;
6+
use vortex_error::VortexResult;
7+
use vortex_vector::PVector;
8+
9+
use crate::ArrayRef;
10+
use crate::arrays::{PrimitiveArray, PrimitiveVTable};
11+
use crate::execution::{BatchKernelRef, BindCtx, kernel};
12+
use crate::vtable::{OperatorVTable, ValidityHelper};
13+
14+
impl OperatorVTable<PrimitiveVTable> for PrimitiveVTable {
15+
fn bind(
16+
array: &PrimitiveArray,
17+
selection: Option<&ArrayRef>,
18+
ctx: &mut dyn BindCtx,
19+
) -> VortexResult<BatchKernelRef> {
20+
let mask = ctx.bind_selection(array.len(), selection)?;
21+
let validity = ctx.bind_validity(array.validity(), array.len(), selection)?;
22+
23+
match_each_native_ptype!(array.ptype(), |T| {
24+
let elements = array.buffer::<T>();
25+
Ok(kernel(move || {
26+
let mask = mask.execute()?;
27+
let validity = validity.execute()?;
28+
29+
// Note that validity already has the mask applied so we only need to apply it to
30+
// the elements.
31+
let elements = elements.filter(&mask);
32+
33+
Ok(PVector::new(elements, validity).into())
34+
}))
35+
})
36+
}
37+
}

vortex-array/src/arrays/primitive/vtable/pipeline.rs

Lines changed: 0 additions & 85 deletions
This file was deleted.

0 commit comments

Comments
 (0)