@@ -6,12 +6,23 @@ use vortex_error::VortexResult;
66use crate :: ArrayRef ;
77use crate :: Columnar ;
88use crate :: ExecutionCtx ;
9+ use crate :: aggregate_fn:: Accumulator ;
910use crate :: aggregate_fn:: AggregateFnId ;
1011use crate :: aggregate_fn:: AggregateFnVTable ;
12+ use crate :: aggregate_fn:: DynAccumulator ;
1113use crate :: aggregate_fn:: EmptyOptions ;
1214use crate :: dtype:: DType ;
1315use 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 ) ]
1728pub 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 ( ) ;
0 commit comments