Skip to content

Commit 2927bfd

Browse files
committed
MinMaxAggregateFn
Signed-off-by: Nicholas Gates <nick@nickgates.com>
1 parent c48cfdd commit 2927bfd

10 files changed

Lines changed: 42 additions & 4 deletions

File tree

encodings/runend/src/compute/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mod fill_null;
77
pub(crate) mod filter;
88
mod is_constant;
99
mod is_sorted;
10+
pub(crate) mod min_max;
1011
pub(crate) mod take;
1112
pub(crate) mod take_from;
1213

encodings/runend/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,22 @@ pub mod _benchmarking {
2626
use super::*;
2727
}
2828

29+
use vortex_array::aggregate_fn::AggregateFnVTable;
30+
use vortex_array::aggregate_fn::fns::min_max::MinMax;
31+
use vortex_array::aggregate_fn::session::AggregateFnSessionExt;
2932
use vortex_array::session::ArraySessionExt;
3033
use vortex_session::VortexSession;
3134

3235
/// Initialize run-end encoding in the given session.
3336
pub fn initialize(session: &mut VortexSession) {
3437
session.arrays().register(RunEnd::ID, RunEnd);
38+
39+
// Register the RunEnd-specific min/max aggregate kernel.
40+
session.aggregate_fns().register_aggregate_kernel(
41+
RunEnd::ID,
42+
Some(MinMax.id()),
43+
&compute::min_max::RunEndMinMaxKernel,
44+
);
3545
}
3646

3747
#[cfg(test)]

encodings/sequence/public-api.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,6 @@ pub vortex_sequence::SequenceArrayParts::nullability: vortex_array::dtype::nulla
158158

159159
pub vortex_sequence::SequenceArrayParts::ptype: vortex_array::dtype::ptype::PType
160160

161+
pub fn vortex_sequence::initialize(session: &mut vortex_session::VortexSession)
162+
161163
pub fn vortex_sequence::sequence_encode(primitive_array: &vortex_array::arrays::primitive::array::PrimitiveArray) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::ArrayRef>>

encodings/sequence/src/compute/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub(crate) mod compare;
66
mod filter;
77
mod is_sorted;
88
mod list_contains;
9+
pub(crate) mod min_max;
910
mod slice;
1011
mod take;
1112

encodings/sequence/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@ pub use array::Sequence;
1515
pub use array::SequenceArray;
1616
pub use array::SequenceArrayParts;
1717
pub use compress::sequence_encode;
18+
use vortex_array::aggregate_fn::AggregateFnVTable;
19+
use vortex_array::aggregate_fn::fns::min_max::MinMax;
20+
use vortex_array::aggregate_fn::session::AggregateFnSessionExt;
21+
use vortex_array::session::ArraySessionExt;
22+
use vortex_session::VortexSession;
23+
24+
/// Initialize sequence encoding in the given session.
25+
pub fn initialize(session: &mut VortexSession) {
26+
session.arrays().register(Sequence::ID, Sequence);
27+
28+
// Register the Sequence-specific min/max aggregate kernel.
29+
session.aggregate_fns().register_aggregate_kernel(
30+
Sequence::ID,
31+
Some(MinMax.id()),
32+
&compute::min_max::SequenceMinMaxKernel,
33+
);
34+
}
1835

1936
// TODO(joe): hook up to the compressor
2037
// TODO(joe): support comparisons with other operators

vortex-array/public-api.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ pub fn vortex_array::aggregate_fn::fns::min_max::MinMaxResult::fmt(&self, f: &mu
102102

103103
impl core::marker::StructuralPartialEq for vortex_array::aggregate_fn::fns::min_max::MinMaxResult
104104

105+
pub fn vortex_array::aggregate_fn::fns::min_max::make_struct_dtype(element_dtype: &vortex_array::dtype::DType) -> vortex_array::dtype::DType
106+
105107
pub fn vortex_array::aggregate_fn::fns::min_max::min_max(array: &vortex_array::ArrayRef, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::aggregate_fn::fns::min_max::MinMaxResult>>
106108

107109
pub mod vortex_array::aggregate_fn::fns::nan_count

vortex-array/src/aggregate_fn/fns/min_max/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ impl MinMaxPartial {
154154
}
155155
}
156156

157-
fn make_struct_dtype(element_dtype: &DType) -> DType {
157+
/// Creates the struct dtype `{min: T, max: T}` (nullable) used for min/max aggregate results.
158+
pub fn make_struct_dtype(element_dtype: &DType) -> DType {
158159
DType::Struct(
159160
StructFields::new(
160161
NAMES.clone(),

vortex-array/src/aggregate_fn/session.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ use vortex_utils::aliases::hash_map::HashMap;
1212
use crate::aggregate_fn::AggregateFnId;
1313
use crate::aggregate_fn::AggregateFnPluginRef;
1414
use crate::aggregate_fn::AggregateFnVTable;
15+
use crate::aggregate_fn::fns::min_max::MinMax;
1516
use crate::aggregate_fn::kernels::DynAggregateKernel;
1617
use crate::aggregate_fn::kernels::DynGroupedAggregateKernel;
1718
use crate::arrays::Chunked;
19+
use crate::arrays::Dict;
1820
use crate::arrays::chunked::compute::aggregate::ChunkedArrayAggregate;
21+
use crate::arrays::dict::compute::min_max::DictMinMaxKernel;
1922
use crate::vtable::ArrayId;
2023

2124
/// Registry of aggregate function vtables.
@@ -42,6 +45,7 @@ impl Default for AggregateFnSession {
4245

4346
// Register the built-in aggregate kernels.
4447
this.register_aggregate_kernel(Chunked::ID, None, &ChunkedArrayAggregate);
48+
this.register_aggregate_kernel(Dict::ID, Some(MinMax.id()), &DictMinMaxKernel);
4549

4650
this
4751
}

vortex-array/src/arrays/dict/compute/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ mod is_constant;
88
mod is_sorted;
99
mod like;
1010
mod mask;
11+
pub(crate) mod min_max;
1112
pub(crate) mod rules;
1213
mod slice;
1314

vortex-file/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ use vortex_fastlanes::FoR;
120120
use vortex_fastlanes::RLE;
121121
use vortex_fsst::FSST;
122122
use vortex_pco::Pco;
123-
use vortex_sequence::Sequence;
124123
use vortex_session::VortexSession;
125124
use vortex_sparse::Sparse;
126125
use vortex_zigzag::ZigZag;
@@ -175,7 +174,6 @@ pub fn register_default_encodings(session: &mut VortexSession) {
175174
arrays.register(FoR::ID, FoR);
176175
arrays.register(Pco::ID, Pco);
177176
arrays.register(RLE::ID, RLE);
178-
arrays.register(Sequence::ID, Sequence);
179177
arrays.register(Sparse::ID, Sparse);
180178
arrays.register(ZigZag::ID, ZigZag);
181179
#[cfg(feature = "zstd")]
@@ -187,5 +185,6 @@ pub fn register_default_encodings(session: &mut VortexSession) {
187185
// Eventually all encodings crates should expose an initialize function. For now it's only
188186
// a few of them.
189187
vortex_alp::initialize(session);
190-
vortex_runend::initialize(session)
188+
vortex_runend::initialize(session);
189+
vortex_sequence::initialize(session);
191190
}

0 commit comments

Comments
 (0)