Skip to content

Commit b32f7a3

Browse files
authored
ComputeFn to hold own registry (#3139)
Compute functions now hold their own kernel registry, allowing third-parties to register kernels.
1 parent 996d5ee commit b32f7a3

File tree

43 files changed

+269
-285
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+269
-285
lines changed

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ hashbrown = "0.15.1"
104104
homedir = "0.3.3"
105105
humansize = "2.1.3"
106106
indicatif = "0.17.8"
107+
inventory = "0.3.20"
107108
itertools = "0.14.0"
108109
jiff = "0.2.0"
109110
lending-iterator = "0.1.7"

bench-vortex/src/bin/notimplemented.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use vortex::arrays::{
1010
VarBinViewArray,
1111
};
1212
use vortex::buffer::buffer;
13-
use vortex::compute::Filter;
1413
use vortex::dtype::datetime::{TIME_ID, TemporalMetadata, TimeUnit};
1514
use vortex::dtype::{DType, ExtDType, Nullability, PType};
1615
use vortex::encodings::alp::{ALPArray, Exponents, RDEncoder};
@@ -163,7 +162,6 @@ fn compute_funcs(encodings: &[ArrayRef]) {
163162
"compare",
164163
"fill_forward",
165164
"fill_null",
166-
"filter",
167165
"scalar_at",
168166
"binary_numeric",
169167
"search_sorted",
@@ -180,7 +178,6 @@ fn compute_funcs(encodings: &[ArrayRef]) {
180178
encoding.compare_fn().is_some(),
181179
encoding.fill_forward_fn().is_some(),
182180
encoding.fill_null_fn().is_some(),
183-
arr.find_kernel(&Filter).is_some(),
184181
encoding.scalar_at_fn().is_some(),
185182
encoding.binary_numeric_fn().is_some(),
186183
encoding.search_sorted_fn().is_some(),

encodings/alp/src/alp/compute/mod.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,19 @@ use std::fmt::Debug;
44

55
use vortex_array::arrays::ConstantArray;
66
use vortex_array::compute::{
7-
BetweenFn, BetweenOptions, CompareFn, FilterKernel, FilterKernelAdapter, KernelRef, ScalarAtFn,
7+
BetweenFn, BetweenOptions, CompareFn, FilterKernelAdapter, FilterKernelImpl, ScalarAtFn,
88
SliceFn, StrictComparison, TakeFn, between, filter, scalar_at, slice, take,
99
};
1010
use vortex_array::variants::PrimitiveArrayTrait;
1111
use vortex_array::vtable::ComputeVTable;
12-
use vortex_array::{Array, ArrayComputeImpl, ArrayRef};
12+
use vortex_array::{Array, ArrayRef, register_kernel};
1313
use vortex_dtype::{NativePType, Nullability};
1414
use vortex_error::VortexResult;
1515
use vortex_mask::Mask;
1616
use vortex_scalar::{Scalar, ScalarType};
1717

1818
use crate::{ALPArray, ALPEncoding, ALPFloat, match_each_alp_float_ptype};
1919

20-
impl ArrayComputeImpl for ALPArray {
21-
const FILTER: Option<KernelRef> = FilterKernelAdapter(ALPEncoding).some();
22-
}
2320
impl ComputeVTable for ALPEncoding {
2421
fn between_fn(&self) -> Option<&dyn BetweenFn<&dyn Array>> {
2522
Some(self)
@@ -101,7 +98,7 @@ impl SliceFn<&ALPArray> for ALPEncoding {
10198
}
10299
}
103100

104-
impl FilterKernel for ALPEncoding {
101+
impl FilterKernelImpl for ALPEncoding {
105102
fn filter(&self, array: &ALPArray, mask: &Mask) -> VortexResult<ArrayRef> {
106103
let patches = array
107104
.patches()
@@ -116,6 +113,8 @@ impl FilterKernel for ALPEncoding {
116113
}
117114
}
118115

116+
register_kernel!(FilterKernelAdapter(ALPEncoding).lift());
117+
119118
impl BetweenFn<&ALPArray> for ALPEncoding {
120119
fn between(
121120
&self,

encodings/alp/src/alp_rd/compute/filter.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use vortex_array::compute::{FilterKernel, filter};
2-
use vortex_array::{Array, ArrayRef};
1+
use vortex_array::compute::{FilterKernelAdapter, FilterKernelImpl, filter};
2+
use vortex_array::{Array, ArrayRef, register_kernel};
33
use vortex_error::VortexResult;
44
use vortex_mask::Mask;
55

66
use crate::{ALPRDArray, ALPRDEncoding};
77

8-
impl FilterKernel for ALPRDEncoding {
8+
impl FilterKernelImpl for ALPRDEncoding {
99
fn filter(&self, array: &ALPRDArray, mask: &Mask) -> VortexResult<ArrayRef> {
1010
let left_parts_exceptions = array
1111
.left_parts_patches()
@@ -25,6 +25,8 @@ impl FilterKernel for ALPRDEncoding {
2525
}
2626
}
2727

28+
register_kernel!(FilterKernelAdapter(ALPRDEncoding).lift());
29+
2830
#[cfg(test)]
2931
mod test {
3032
use rstest::rstest;

encodings/alp/src/alp_rd/compute/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
use vortex_array::compute::{FilterKernelAdapter, KernelRef, MaskFn, ScalarAtFn, SliceFn, TakeFn};
1+
use vortex_array::Array;
2+
use vortex_array::compute::{MaskFn, ScalarAtFn, SliceFn, TakeFn};
23
use vortex_array::vtable::ComputeVTable;
3-
use vortex_array::{Array, ArrayComputeImpl};
44

5-
use crate::{ALPRDArray, ALPRDEncoding};
5+
use crate::ALPRDEncoding;
66

77
mod filter;
88
mod mask;
99
mod scalar_at;
1010
mod slice;
1111
mod take;
1212

13-
impl ArrayComputeImpl for ALPRDArray {
14-
const FILTER: Option<KernelRef> = FilterKernelAdapter(ALPRDEncoding).some();
15-
}
16-
1713
impl ComputeVTable for ALPRDEncoding {
1814
fn mask_fn(&self) -> Option<&dyn MaskFn<&dyn Array>> {
1915
Some(self)

encodings/bytebool/src/compute.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@ use vortex_array::compute::{FillForwardFn, MaskFn, ScalarAtFn, SliceFn, TakeFn};
33
use vortex_array::validity::Validity;
44
use vortex_array::variants::PrimitiveArrayTrait;
55
use vortex_array::vtable::ComputeVTable;
6-
use vortex_array::{Array, ArrayComputeImpl, ArrayRef, ToCanonical};
6+
use vortex_array::{Array, ArrayRef, ToCanonical};
77
use vortex_dtype::{Nullability, match_each_integer_ptype};
88
use vortex_error::{VortexResult, vortex_err};
99
use vortex_mask::Mask;
1010
use vortex_scalar::Scalar;
1111

1212
use super::{ByteBoolArray, ByteBoolEncoding};
1313

14-
impl ArrayComputeImpl for ByteBoolArray {}
15-
1614
impl ComputeVTable for ByteBoolEncoding {
1715
fn fill_forward_fn(&self) -> Option<&dyn FillForwardFn<&dyn Array>> {
1816
None
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use vortex_array::compute::{FilterKernel, filter};
2-
use vortex_array::{Array, ArrayRef};
1+
use vortex_array::compute::{FilterKernelAdapter, FilterKernelImpl, filter};
2+
use vortex_array::{Array, ArrayRef, register_kernel};
33
use vortex_error::VortexResult;
44
use vortex_mask::Mask;
55

66
use crate::{DateTimePartsArray, DateTimePartsEncoding};
77

8-
impl FilterKernel for DateTimePartsEncoding {
8+
impl FilterKernelImpl for DateTimePartsEncoding {
99
fn filter(&self, array: &DateTimePartsArray, mask: &Mask) -> VortexResult<ArrayRef> {
1010
Ok(DateTimePartsArray::try_new(
1111
array.dtype().clone(),
@@ -16,3 +16,4 @@ impl FilterKernel for DateTimePartsEncoding {
1616
.into_array())
1717
}
1818
}
19+
register_kernel!(FilterKernelAdapter(DateTimePartsEncoding).lift());

encodings/datetime-parts/src/compute/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ mod is_constant;
55
mod take;
66

77
use vortex_array::compute::{
8-
CastFn, CompareFn, FilterKernelAdapter, IsConstantFn, KernelRef, ScalarAtFn, SliceFn, TakeFn,
9-
scalar_at, slice,
8+
CastFn, CompareFn, IsConstantFn, ScalarAtFn, SliceFn, TakeFn, scalar_at, slice,
109
};
1110
use vortex_array::vtable::ComputeVTable;
12-
use vortex_array::{Array, ArrayComputeImpl, ArrayRef};
11+
use vortex_array::{Array, ArrayRef};
1312
use vortex_dtype::Nullability::{NonNullable, Nullable};
1413
use vortex_dtype::datetime::TemporalMetadata;
1514
use vortex_dtype::{DType, PType};
@@ -19,10 +18,6 @@ use vortex_scalar::Scalar;
1918
use crate::timestamp::{self, TimestampParts};
2019
use crate::{DateTimePartsArray, DateTimePartsEncoding};
2120

22-
impl ArrayComputeImpl for DateTimePartsArray {
23-
const FILTER: Option<KernelRef> = FilterKernelAdapter(DateTimePartsEncoding).some();
24-
}
25-
2621
impl ComputeVTable for DateTimePartsEncoding {
2722
fn cast_fn(&self) -> Option<&dyn CastFn<&dyn Array>> {
2823
Some(self)

encodings/dict/src/compute/mod.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,18 @@ mod min_max;
88
mod optimize;
99

1010
use vortex_array::compute::{
11-
BinaryNumericFn, CompareFn, FillNullFn, FilterKernel, FilterKernelAdapter, IsConstantFn,
12-
IsSortedFn, KernelRef, LikeFn, MinMaxFn, OptimizeFn, ScalarAtFn, SliceFn, TakeFn, filter,
13-
scalar_at, slice, take,
11+
BinaryNumericFn, CompareFn, FillNullFn, FilterKernelAdapter, FilterKernelImpl, IsConstantFn,
12+
IsSortedFn, LikeFn, MinMaxFn, OptimizeFn, ScalarAtFn, SliceFn, TakeFn, filter, scalar_at,
13+
slice, take,
1414
};
1515
use vortex_array::vtable::ComputeVTable;
16-
use vortex_array::{Array, ArrayComputeImpl, ArrayRef};
16+
use vortex_array::{Array, ArrayRef, register_kernel};
1717
use vortex_error::VortexResult;
1818
use vortex_mask::Mask;
1919
use vortex_scalar::Scalar;
2020

2121
use crate::{DictArray, DictEncoding};
2222

23-
impl ArrayComputeImpl for DictArray {
24-
const FILTER: Option<KernelRef> = FilterKernelAdapter(DictEncoding).some();
25-
}
26-
2723
impl ComputeVTable for DictEncoding {
2824
fn binary_numeric_fn(&self) -> Option<&dyn BinaryNumericFn<&dyn Array>> {
2925
Some(self)
@@ -84,13 +80,15 @@ impl TakeFn<&DictArray> for DictEncoding {
8480
}
8581
}
8682

87-
impl FilterKernel for DictEncoding {
83+
impl FilterKernelImpl for DictEncoding {
8884
fn filter(&self, array: &DictArray, mask: &Mask) -> VortexResult<ArrayRef> {
8985
let codes = filter(array.codes(), mask)?;
9086
DictArray::try_new(codes, array.values().clone()).map(|a| a.into_array())
9187
}
9288
}
9389

90+
register_kernel!(FilterKernelAdapter(DictEncoding).lift());
91+
9492
impl SliceFn<&DictArray> for DictEncoding {
9593
// TODO(robert): Add function to trim the dictionary
9694
fn slice(&self, array: &DictArray, start: usize, stop: usize) -> VortexResult<ArrayRef> {

0 commit comments

Comments
 (0)