Skip to content

Commit decb562

Browse files
authored
FilterArray (#5610)
Signed-off-by: Nicholas Gates <[email protected]>
1 parent 536bca9 commit decb562

File tree

5 files changed

+143
-1
lines changed

5 files changed

+143
-1
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
use vortex_mask::Mask;
5+
6+
use crate::ArrayRef;
7+
use crate::stats::ArrayStats;
8+
9+
#[derive(Clone, Debug)]
10+
pub struct FilterArray {
11+
pub(super) child: ArrayRef,
12+
pub(super) mask: Mask,
13+
pub(super) stats: ArrayStats,
14+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
mod array;
5+
mod vtable;
6+
7+
pub use vtable::*;
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
use std::hash::Hasher;
5+
6+
use vortex_buffer::BufferHandle;
7+
use vortex_dtype::DType;
8+
use vortex_error::VortexResult;
9+
use vortex_error::vortex_bail;
10+
use vortex_mask::Mask;
11+
use vortex_vector::Vector;
12+
13+
use crate::Array;
14+
use crate::ArrayBufferVisitor;
15+
use crate::ArrayChildVisitor;
16+
use crate::ArrayEq;
17+
use crate::ArrayHash;
18+
use crate::Precision;
19+
use crate::arrays::filter::array::FilterArray;
20+
use crate::execution::ExecutionCtx;
21+
use crate::serde::ArrayChildren;
22+
use crate::stats::StatsSetRef;
23+
use crate::vtable;
24+
use crate::vtable::ArrayId;
25+
use crate::vtable::ArrayVTable;
26+
use crate::vtable::ArrayVTableExt;
27+
use crate::vtable::BaseArrayVTable;
28+
use crate::vtable::NotSupported;
29+
use crate::vtable::VTable;
30+
use crate::vtable::VisitorVTable;
31+
32+
vtable!(Filter);
33+
34+
#[derive(Debug)]
35+
pub struct FilterVTable;
36+
37+
impl VTable for FilterVTable {
38+
type Array = FilterArray;
39+
type Metadata = Mask;
40+
type ArrayVTable = Self;
41+
type CanonicalVTable = NotSupported;
42+
type OperationsVTable = NotSupported;
43+
type ValidityVTable = NotSupported;
44+
type VisitorVTable = Self;
45+
type ComputeVTable = NotSupported;
46+
type EncodeVTable = NotSupported;
47+
48+
fn id(&self) -> ArrayId {
49+
ArrayId::from("vortex.filter")
50+
}
51+
52+
fn encoding(_array: &Self::Array) -> ArrayVTable {
53+
FilterVTable.as_vtable()
54+
}
55+
56+
fn metadata(array: &Self::Array) -> VortexResult<Self::Metadata> {
57+
Ok(array.mask.clone())
58+
}
59+
60+
fn serialize(_metadata: Self::Metadata) -> VortexResult<Option<Vec<u8>>> {
61+
Ok(None)
62+
}
63+
64+
fn deserialize(_bytes: &[u8]) -> VortexResult<Self::Metadata> {
65+
vortex_bail!("Filter array is not serializable")
66+
}
67+
68+
fn build(
69+
&self,
70+
dtype: &DType,
71+
len: usize,
72+
metadata: &Self::Metadata,
73+
_buffers: &[BufferHandle],
74+
children: &dyn ArrayChildren,
75+
) -> VortexResult<Self::Array> {
76+
let child = children.get(0, dtype, len)?;
77+
Ok(FilterArray {
78+
child,
79+
mask: metadata.clone(),
80+
stats: Default::default(),
81+
})
82+
}
83+
84+
fn batch_execute(array: &Self::Array, ctx: &mut ExecutionCtx) -> VortexResult<Vector> {
85+
let child = array.child.batch_execute(ctx)?;
86+
Ok(vortex_compute::filter::Filter::filter(&child, &array.mask))
87+
}
88+
}
89+
90+
impl BaseArrayVTable<FilterVTable> for FilterVTable {
91+
fn len(array: &FilterArray) -> usize {
92+
array.mask.true_count()
93+
}
94+
95+
fn dtype(array: &FilterArray) -> &DType {
96+
array.child.dtype()
97+
}
98+
99+
fn stats(array: &FilterArray) -> StatsSetRef<'_> {
100+
array.stats.to_ref(array.as_ref())
101+
}
102+
103+
fn array_hash<H: Hasher>(array: &FilterArray, state: &mut H, precision: Precision) {
104+
array.child.array_hash(state, precision);
105+
array.mask.array_hash(state, precision);
106+
}
107+
108+
fn array_eq(array: &FilterArray, other: &FilterArray, precision: Precision) -> bool {
109+
array.child.array_eq(&other.child, precision) && array.mask.array_eq(&other.mask, precision)
110+
}
111+
}
112+
113+
impl VisitorVTable<FilterVTable> for FilterVTable {
114+
fn visit_buffers(_array: &FilterArray, _visitor: &mut dyn ArrayBufferVisitor) {}
115+
116+
fn visit_children(array: &FilterArray, visitor: &mut dyn ArrayChildVisitor) {
117+
visitor.visit_child("child", &array.child);
118+
}
119+
}

vortex-array/src/arrays/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ mod datetime;
2222
mod decimal;
2323
mod dict;
2424
mod extension;
25+
mod filter;
2526
mod fixed_size_list;
2627
mod list;
2728
mod listview;
@@ -35,6 +36,7 @@ mod varbinview;
3536

3637
#[cfg(feature = "arbitrary")]
3738
pub mod arbitrary;
39+
// pub mod pipeline;
3840
// TODO(connor): Export exact types, not glob.
3941

4042
pub use bool::*;
@@ -44,6 +46,7 @@ pub use datetime::*;
4446
pub use decimal::*;
4547
pub use dict::*;
4648
pub use extension::*;
49+
pub use filter::*;
4750
pub use fixed_size_list::*;
4851
pub use list::*;
4952
pub use listview::*;

vortex-array/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ mod metadata;
3939
pub mod optimizer;
4040
mod partial_ord;
4141
pub mod patches;
42-
// pub mod pipeline;
4342
pub mod scalar_fns;
4443
pub mod search_sorted;
4544
pub mod serde;

0 commit comments

Comments
 (0)