44// SPDX-FileCopyrightText: Copyright the Vortex contributors
55
66use std:: marker:: PhantomData ;
7+ use std:: sync:: Arc ;
78
89use itertools:: Itertools ;
910use vortex_array:: ArrayRef ;
@@ -90,9 +91,10 @@ impl StatsAccumulator {
9091 Ok ( ( ) )
9192 }
9293
93- pub fn as_array ( & mut self ) -> VortexResult < Option < StructArray > > {
94+ pub fn as_array ( & mut self ) -> VortexResult < Option < ( StructArray , Arc < [ Stat ] > ) > > {
9495 let mut names = Vec :: new ( ) ;
9596 let mut fields = Vec :: new ( ) ;
97+ let mut stats = Vec :: new ( ) ;
9698
9799 for builder in self
98100 . builders
@@ -107,6 +109,7 @@ impl StatsAccumulator {
107109 continue ;
108110 }
109111
112+ stats. push ( builder. stat ( ) ) ;
110113 names. extend ( values. names ) ;
111114 fields. extend ( values. arrays ) ;
112115 }
@@ -115,7 +118,8 @@ impl StatsAccumulator {
115118 return Ok ( None ) ;
116119 }
117120
118- StructArray :: try_new ( names. into ( ) , fields, self . length , Validity :: NonNullable ) . map ( Some )
121+ let array = StructArray :: try_new ( names. into ( ) , fields, self . length , Validity :: NonNullable ) ?;
122+ Ok ( Some ( ( array, stats. into ( ) ) ) )
119123 }
120124
121125 /// Returns an aggregated stats set for the table.
@@ -125,7 +129,7 @@ impl StatsAccumulator {
125129 ctx : & mut ExecutionCtx ,
126130 ) -> VortexResult < StatsSet > {
127131 let mut stats_set = StatsSet :: default ( ) ;
128- let Some ( array) = self . as_array ( ) ? else {
132+ let Some ( ( array, _ ) ) = self . as_array ( ) ? else {
129133 return Ok ( stats_set) ;
130134 } ;
131135
@@ -415,7 +419,7 @@ mod tests {
415419 . vortex_expect ( "push_chunk should succeed for test data" ) ;
416420 acc. push_chunk ( & builder2. finish ( ) , & mut ctx)
417421 . vortex_expect ( "push_chunk should succeed for test data" ) ;
418- let stats_table = acc. as_array ( ) . unwrap ( ) . expect ( "Must have stats table" ) ;
422+ let ( stats_table, _ ) = acc. as_array ( ) . unwrap ( ) . expect ( "Must have stats table" ) ;
419423 assert_eq ! (
420424 stats_table. names( ) . as_ref( ) ,
421425 & [
@@ -452,7 +456,7 @@ mod tests {
452456 let mut acc = StatsAccumulator :: new ( array. dtype ( ) , & [ Stat :: Max , Stat :: Min , Stat :: Sum ] , 12 ) ;
453457 acc. push_chunk ( & array, & mut ctx)
454458 . vortex_expect ( "push_chunk should succeed for test array" ) ;
455- let stats_table = acc. as_array ( ) . unwrap ( ) . expect ( "Must have stats table" ) ;
459+ let ( stats_table, _ ) = acc. as_array ( ) . unwrap ( ) . expect ( "Must have stats table" ) ;
456460 assert_eq ! (
457461 stats_table. names( ) . as_ref( ) ,
458462 & [
0 commit comments