Skip to content

Commit 94afb78

Browse files
committed
Clarify docs in session accessors
Signed-off-by: Nicholas Gates <[email protected]>
1 parent f828fa0 commit 94afb78

File tree

5 files changed

+57
-27
lines changed

5 files changed

+57
-27
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

44
use vortex_compute::filter::Filter;
5-
use vortex_dtype::DType;
65
use vortex_error::VortexResult;
76
use vortex_mask::Mask;
87
use vortex_vector::Vector;
@@ -15,13 +14,11 @@ use crate::kernel::PushDownResult;
1514
pub struct FilterKernel {
1615
child: KernelRef,
1716
mask: Mask,
18-
// Used for estimating filter cost
19-
dtype: DType,
2017
}
2118

2219
impl FilterKernel {
23-
pub fn new(child: KernelRef, mask: Mask, dtype: DType) -> Self {
24-
Self { child, mask, dtype }
20+
pub fn new(child: KernelRef, mask: Mask) -> Self {
21+
Self { child, mask }
2522
}
2623
}
2724

@@ -36,7 +33,6 @@ impl Kernel for FilterKernel {
3633
PushDownResult::NotPushed(k) => PushDownResult::NotPushed(Box::new(FilterKernel {
3734
child: k,
3835
mask: new_mask,
39-
dtype: self.dtype.clone(),
4036
})),
4137
PushDownResult::Pushed(new_k) => PushDownResult::Pushed(new_k),
4238
})

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,7 @@ impl VTable for FilterVTable {
122122
}
123123

124124
// Otherwise, wrap up the child in a filter kernel.
125-
Ok(Box::new(FilterKernel::new(
126-
child,
127-
mask,
128-
array.dtype().clone(),
129-
)))
125+
Ok(Box::new(FilterKernel::new(child, mask)))
130126
}
131127
}
132128

vortex-array/src/arrays/scalar_fn/kernel.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use vortex_vector::Datum;
88
use vortex_vector::Scalar;
99
use vortex_vector::Vector;
1010

11-
use crate::arrays::FilterKernel;
1211
use crate::expr::ExecutionArgs;
1312
use crate::expr::ScalarFn;
1413
use crate::kernel::Kernel;
@@ -63,20 +62,14 @@ impl Kernel for ScalarFnKernel {
6362

6463
fn push_down_filter(self: Box<Self>, selection: &Mask) -> VortexResult<PushDownResult> {
6564
let mut new_inputs = Vec::with_capacity(self.inputs.len());
66-
for (input, dtype) in self.inputs.into_iter().zip(&self.input_dtypes) {
65+
for input in self.inputs {
6766
match input {
6867
KernelInput::Scalar(s) => {
6968
new_inputs.push(KernelInput::Scalar(s.clone()));
7069
}
71-
KernelInput::Vector(k) => match k.push_down_filter(selection)? {
72-
PushDownResult::Pushed(new_k) => {
73-
new_inputs.push(KernelInput::Vector(new_k));
74-
}
75-
PushDownResult::NotPushed(k) => {
76-
let new_k = FilterKernel::new(k, selection.clone(), dtype.clone());
77-
new_inputs.push(KernelInput::Vector(Box::new(new_k)));
78-
}
79-
},
70+
KernelInput::Vector(k) => {
71+
new_inputs.push(KernelInput::Vector(k.force_push_down_filter(selection)?));
72+
}
8073
}
8174
}
8275

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

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@ use std::sync::Arc;
55

66
use itertools::Itertools;
77
use vortex_buffer::BufferHandle;
8+
use vortex_compute::filter::Filter;
89
use vortex_dtype::DType;
910
use vortex_error::VortexExpect;
1011
use vortex_error::VortexResult;
1112
use vortex_error::vortex_bail;
13+
use vortex_mask::Mask;
14+
use vortex_vector::Vector;
1215
use vortex_vector::struct_::StructVector;
1316

1417
use crate::EmptyMetadata;
1518
use crate::arrays::struct_::StructArray;
1619
use crate::kernel::BindCtx;
20+
use crate::kernel::Kernel;
1721
use crate::kernel::KernelRef;
18-
use crate::kernel::kernel;
22+
use crate::kernel::PushDownResult;
1923
use crate::serde::ArrayChildren;
2024
use crate::validity::Validity;
2125
use crate::vtable;
@@ -115,13 +119,42 @@ impl VTable for StructVTable {
115119
.try_collect()?;
116120
let validity_mask = array.validity_mask();
117121

118-
Ok(kernel(move || {
119-
// SAFETY: we know that all field lengths match the struct array length, and the validity
120-
let fields = fields.into_iter().map(|k| k.execute()).try_collect()?;
121-
Ok(unsafe { StructVector::new_unchecked(Arc::new(fields), validity_mask) }.into())
122+
Ok(Box::new(StructKernel {
123+
fields,
124+
validity_mask,
122125
}))
123126
}
124127
}
125128

129+
#[derive(Debug)]
130+
struct StructKernel {
131+
fields: Box<[KernelRef]>,
132+
// TODO(ngates): hold a kernel that computes the mask.
133+
validity_mask: Mask,
134+
}
135+
136+
impl Kernel for StructKernel {
137+
fn execute(self: Box<Self>) -> VortexResult<Vector> {
138+
// SAFETY: we know that all field lengths match the struct array length, and the validity
139+
let fields = self.fields.into_iter().map(|k| k.execute()).try_collect()?;
140+
Ok(unsafe { StructVector::new_unchecked(Arc::new(fields), self.validity_mask) }.into())
141+
}
142+
143+
fn push_down_filter(self: Box<Self>, selection: &Mask) -> VortexResult<PushDownResult> {
144+
let fields = self
145+
.fields
146+
.into_iter()
147+
.map(|k| k.force_push_down_filter(selection))
148+
.try_collect()?;
149+
150+
let validity_mask = self.validity_mask.filter(selection);
151+
152+
Ok(PushDownResult::Pushed(Box::new(StructKernel {
153+
fields,
154+
validity_mask,
155+
})))
156+
}
157+
}
158+
126159
#[derive(Debug)]
127160
pub struct StructVTable;

vortex-array/src/kernel/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ use vortex_mask::Mask;
1717
use vortex_session::VortexSession;
1818
use vortex_vector::Vector;
1919

20+
use crate::arrays::FilterKernel;
21+
2022
/// A boxed reference to a kernel.
2123
pub type KernelRef = Box<dyn Kernel>;
2224

@@ -52,3 +54,13 @@ impl BindCtx {
5254
&self.session
5355
}
5456
}
57+
58+
impl dyn Kernel + '_ {
59+
/// Push-down a filter mask, or else wrap up the kernel to apply the filter later.
60+
pub fn force_push_down_filter(self: Box<Self>, selection: &Mask) -> VortexResult<KernelRef> {
61+
match self.push_down_filter(selection)? {
62+
PushDownResult::Pushed(k) => Ok(k),
63+
PushDownResult::NotPushed(k) => Ok(Box::new(FilterKernel::new(k, selection.clone()))),
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)