Skip to content

Commit fbf570a

Browse files
committed
pub fn-s
Signed-off-by: blaginin <github@blaginin.me>
1 parent af0b9af commit fbf570a

3 files changed

Lines changed: 28 additions & 16 deletions

File tree

vortex-array/public-api.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ pub fn vortex_array::aggregate_fn::fns::first::First::try_accumulate(&self, part
128128

129129
pub struct vortex_array::aggregate_fn::fns::first::FirstPartial
130130

131+
pub fn vortex_array::aggregate_fn::fns::first::first(array: &vortex_array::ArrayRef, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::scalar::Scalar>
132+
131133
pub mod vortex_array::aggregate_fn::fns::is_constant
132134

133135
pub mod vortex_array::aggregate_fn::fns::is_constant::primitive
@@ -338,6 +340,8 @@ pub fn vortex_array::aggregate_fn::fns::last::Last::try_accumulate(&self, partia
338340

339341
pub struct vortex_array::aggregate_fn::fns::last::LastPartial
340342

343+
pub fn vortex_array::aggregate_fn::fns::last::last(array: &vortex_array::ArrayRef, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::scalar::Scalar>
344+
341345
pub mod vortex_array::aggregate_fn::fns::min_max
342346

343347
pub struct vortex_array::aggregate_fn::fns::min_max::MinMax

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,23 @@ use vortex_error::VortexResult;
66
use crate::ArrayRef;
77
use crate::Columnar;
88
use crate::ExecutionCtx;
9+
use crate::aggregate_fn::Accumulator;
910
use crate::aggregate_fn::AggregateFnId;
1011
use crate::aggregate_fn::AggregateFnVTable;
12+
use crate::aggregate_fn::DynAccumulator;
1113
use crate::aggregate_fn::EmptyOptions;
1214
use crate::dtype::DType;
1315
use crate::scalar::Scalar;
1416

17+
/// Return the first non-null value of an array.
18+
///
19+
/// See [`First`] for details.
20+
pub fn first(array: &ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<Scalar> {
21+
let mut acc = Accumulator::try_new(First, EmptyOptions, array.dtype().clone())?;
22+
acc.accumulate(array, ctx)?;
23+
acc.finish()
24+
}
25+
1526
/// Return the first non-null value seen across all batches.
1627
#[derive(Clone, Debug)]
1728
pub struct First;
@@ -126,8 +137,6 @@ mod tests {
126137
use vortex_buffer::buffer;
127138
use vortex_error::VortexResult;
128139

129-
use crate::ArrayRef;
130-
use crate::ExecutionCtx;
131140
use crate::IntoArray;
132141
use crate::LEGACY_SESSION;
133142
use crate::VortexSessionExecute;
@@ -136,6 +145,7 @@ mod tests {
136145
use crate::aggregate_fn::DynAccumulator;
137146
use crate::aggregate_fn::EmptyOptions;
138147
use crate::aggregate_fn::fns::first::First;
148+
use crate::aggregate_fn::fns::first::first;
139149
use crate::arrays::ChunkedArray;
140150
use crate::arrays::ConstantArray;
141151
use crate::arrays::PrimitiveArray;
@@ -147,12 +157,6 @@ mod tests {
147157
use crate::scalar::Scalar;
148158
use crate::validity::Validity;
149159

150-
fn first(array: &ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<Scalar> {
151-
let mut acc = Accumulator::try_new(First, EmptyOptions, array.dtype().clone())?;
152-
acc.accumulate(array, ctx)?;
153-
acc.finish()
154-
}
155-
156160
#[test]
157161
fn first_non_null() -> VortexResult<()> {
158162
let array = PrimitiveArray::new(buffer![10i32, 20, 30], Validity::NonNullable).into_array();

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,23 @@ use vortex_error::VortexResult;
66
use crate::ArrayRef;
77
use crate::Columnar;
88
use crate::ExecutionCtx;
9+
use crate::aggregate_fn::Accumulator;
910
use crate::aggregate_fn::AggregateFnId;
1011
use crate::aggregate_fn::AggregateFnVTable;
12+
use crate::aggregate_fn::DynAccumulator;
1113
use crate::aggregate_fn::EmptyOptions;
1214
use crate::dtype::DType;
1315
use crate::scalar::Scalar;
1416

17+
/// Return the last non-null value of an array.
18+
///
19+
/// See [`Last`] for details.
20+
pub fn last(array: &ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<Scalar> {
21+
let mut acc = Accumulator::try_new(Last, EmptyOptions, array.dtype().clone())?;
22+
acc.accumulate(array, ctx)?;
23+
acc.finish()
24+
}
25+
1526
/// Return the last non-null value seen across all batches.
1627
#[derive(Clone, Debug)]
1728
pub struct Last;
@@ -124,8 +135,6 @@ mod tests {
124135
use vortex_buffer::buffer;
125136
use vortex_error::VortexResult;
126137

127-
use crate::ArrayRef;
128-
use crate::ExecutionCtx;
129138
use crate::IntoArray;
130139
use crate::LEGACY_SESSION;
131140
use crate::VortexSessionExecute;
@@ -134,6 +143,7 @@ mod tests {
134143
use crate::aggregate_fn::DynAccumulator;
135144
use crate::aggregate_fn::EmptyOptions;
136145
use crate::aggregate_fn::fns::last::Last;
146+
use crate::aggregate_fn::fns::last::last;
137147
use crate::arrays::ChunkedArray;
138148
use crate::arrays::ConstantArray;
139149
use crate::arrays::PrimitiveArray;
@@ -145,12 +155,6 @@ mod tests {
145155
use crate::scalar::Scalar;
146156
use crate::validity::Validity;
147157

148-
fn last(array: &ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<Scalar> {
149-
let mut acc = Accumulator::try_new(Last, EmptyOptions, array.dtype().clone())?;
150-
acc.accumulate(array, ctx)?;
151-
acc.finish()
152-
}
153-
154158
#[test]
155159
fn last_non_null() -> VortexResult<()> {
156160
let array = PrimitiveArray::new(buffer![10i32, 20, 30], Validity::NonNullable).into_array();

0 commit comments

Comments
 (0)