@@ -9,7 +9,7 @@ use parking_lot::RwLock;
99use vortex_error:: { VortexError , VortexResult , vortex_panic} ;
1010use vortex_scalar:: { Scalar , ScalarValue } ;
1111
12- use super :: { Precision , Stat , StatType , StatsProvider , StatsSet , StatsSetIntoIter } ;
12+ use super :: { Precision , Stat , StatsProvider , StatsSet , StatsSetIntoIter , TypedStatsSetRef } ;
1313use crate :: Array ;
1414use crate :: compute:: {
1515 MinMaxResult , is_constant, is_sorted, is_strict_sorted, min_max, nan_count, sum,
@@ -75,19 +75,32 @@ impl StatsSetRef<'_> {
7575 }
7676
7777 pub fn inherit_from ( & self , stats : StatsSetRef < ' _ > ) {
78- stats. with_iter ( |iter| self . inherit ( iter) ) ;
78+ // Only inherit if the underlying stats are different
79+ if !Arc :: ptr_eq ( & self . array_stats . inner , & stats. array_stats . inner ) {
80+ stats. with_iter ( |iter| self . inherit ( iter) ) ;
81+ }
7982 }
8083
8184 pub fn inherit < ' a > ( & self , iter : impl Iterator < Item = & ' a ( Stat , Precision < ScalarValue > ) > ) {
82- // TODO(ngates): depending on statistic, this should choose the more precise one
8385 let mut guard = self . array_stats . inner . write ( ) ;
8486 for ( stat, value) in iter {
85- guard. set ( * stat, value. clone ( ) ) ;
87+ if !value. is_exact ( ) {
88+ if !guard. get ( * stat) . is_some_and ( |v| v. is_exact ( ) ) {
89+ guard. set ( * stat, value. clone ( ) ) ;
90+ }
91+ } else {
92+ guard. set ( * stat, value. clone ( ) ) ;
93+ }
8694 }
8795 }
8896
89- pub fn replace ( & self , stats : StatsSet ) {
90- * self . array_stats . inner . write ( ) = stats;
97+ pub fn with_typed_stats_set < U , F : FnOnce ( TypedStatsSetRef ) -> U > ( & self , apply : F ) -> U {
98+ apply (
99+ self . array_stats
100+ . inner
101+ . read ( )
102+ . as_typed_ref ( self . dyn_array_ref . dtype ( ) ) ,
103+ )
91104 }
92105
93106 pub fn to_owned ( & self ) -> StatsSet {
@@ -165,32 +178,6 @@ impl StatsSetRef<'_> {
165178}
166179
167180impl StatsSetRef < ' _ > {
168- pub fn get_as < U : for < ' a > TryFrom < & ' a Scalar , Error = VortexError > > (
169- & self ,
170- stat : Stat ,
171- ) -> Option < Precision < U > > {
172- self . get ( stat) . map ( |v| {
173- v. map ( |v| {
174- U :: try_from ( & v) . unwrap_or_else ( |err| {
175- vortex_panic ! (
176- err,
177- "Failed to get stat {} as {}" ,
178- stat,
179- std:: any:: type_name:: <U >( )
180- )
181- } )
182- } )
183- } )
184- }
185-
186- pub fn get_as_bound < S , U > ( & self ) -> Option < S :: Bound >
187- where
188- S : StatType < U > ,
189- U : for < ' a > TryFrom < & ' a Scalar , Error = VortexError > ,
190- {
191- self . get_as :: < U > ( S :: STAT ) . map ( |v| v. bound :: < S > ( ) )
192- }
193-
194181 pub fn compute_as < U : for < ' a > TryFrom < & ' a Scalar , Error = VortexError > > (
195182 & self ,
196183 stat : Stat ,
0 commit comments