@@ -187,7 +187,7 @@ pub struct FileStatistics {
187187    /// Statistics on a column level. 
188188/// Each entry in the vector corresponds to a column in the source schema. 
189189/// None entries are possible if statistics are not available for a column. 
190- pub  column_statistics :  Vec < Option < ColumnDistributionStatistics > > , 
190+ pub  column_statistics :  Vec < Option < Arc < ColumnDistributionStatistics > > > , 
191191} 
192192
193193impl  Default  for  FileStatistics  { 
@@ -212,7 +212,7 @@ impl FileStatistics {
212212            column_statistics :  schema
213213                . fields ( ) 
214214                . iter ( ) 
215-                 . map ( |_| Some ( ColumnDistributionStatistics :: new_unknown ( ) ) ) 
215+                 . map ( |_| Some ( Arc :: new ( ColumnDistributionStatistics :: new_unknown ( ) ) ) ) 
216216                . collect ( ) , 
217217        } 
218218    } 
@@ -232,7 +232,7 @@ impl FileStatistics {
232232    /// Add a column to the column statistics 
233233pub  fn  add_column_statistics ( 
234234        mut  self , 
235-         column_stats :  Option < ColumnDistributionStatistics > , 
235+         column_stats :  Option < Arc < ColumnDistributionStatistics > > , 
236236    )  -> Self  { 
237237        self . column_statistics . push ( column_stats) ; 
238238        self 
@@ -246,7 +246,7 @@ impl FileStatistics {
246246        self . column_statistics  = self 
247247            . column_statistics 
248248            . into_iter ( ) 
249-             . map ( |s| s. map ( |stats| stats . to_inexact ( ) ) ) 
249+             . map ( |s| s. map ( |arc_stats|  Arc :: new ( arc_stats . as_ref ( ) . clone ( ) . to_inexact ( ) ) ) ) 
250250            . collect ( ) ; 
251251        self 
252252    } 
@@ -266,7 +266,7 @@ impl FileStatistics {
266266            /// The column is taken and put into the specified statistics location 
267267Taken ( usize ) , 
268268            /// The original column is present 
269- Present ( Option < ColumnDistributionStatistics > ) , 
269+ Present ( Option < Arc < ColumnDistributionStatistics > > ) , 
270270        } 
271271
272272        // Convert to Vec<Slot> so we can avoid copying the statistics 
@@ -358,9 +358,9 @@ impl FileStatistics {
358358    /// Merge two optional column distribution statistics. 
359359/// Returns None if either input is None. 
360360fn  merge_column_distribution_stats ( 
361-         left :  & Option < ColumnDistributionStatistics > , 
362-         right :  & Option < ColumnDistributionStatistics > , 
363-     )  -> Result < Option < ColumnDistributionStatistics > >  { 
361+         left :  & Option < Arc < ColumnDistributionStatistics > > , 
362+         right :  & Option < Arc < ColumnDistributionStatistics > > , 
363+     )  -> Result < Option < Arc < ColumnDistributionStatistics > > >  { 
364364        match  ( left,  right)  { 
365365            ( Some ( l) ,  Some ( r) )  => { 
366366                let  null_count = l. null_count . add ( & r. null_count ) ; 
@@ -371,13 +371,13 @@ impl FileStatistics {
371371                let  distinct_count = Precision :: Absent ; 
372372                let  row_size = Self :: merge_distributions ( & l. row_size ,  & r. row_size ) ?; 
373373
374-                 Ok ( Some ( ColumnDistributionStatistics  { 
374+                 Ok ( Some ( Arc :: new ( ColumnDistributionStatistics  { 
375375                    null_count, 
376376                    distribution, 
377377                    sum_value, 
378378                    distinct_count, 
379379                    row_size, 
380-                 } ) ) 
380+                 } ) ) ) 
381381            } 
382382            _ => Ok ( None ) , 
383383        } 
@@ -1098,10 +1098,10 @@ mod tests {
10981098        let  stats = FileStatistics :: default ( ) 
10991099            . with_num_rows ( Precision :: Exact ( 100 ) ) 
11001100            . with_total_byte_size ( Precision :: Exact ( 1024 ) ) 
1101-             . add_column_statistics ( Some ( 
1101+             . add_column_statistics ( Some ( Arc :: new ( 
11021102                ColumnDistributionStatistics :: new_unknown ( ) 
11031103                    . with_null_count ( Precision :: Exact ( 5 ) ) , 
1104-             ) ) ; 
1104+             ) ) ) ; 
11051105
11061106        let  inexact = stats. to_inexact ( ) ; 
11071107
@@ -1119,18 +1119,18 @@ mod tests {
11191119        use  datafusion_common:: stats:: Precision ; 
11201120
11211121        let  stats = FileStatistics :: default ( ) 
1122-             . add_column_statistics ( Some ( 
1122+             . add_column_statistics ( Some ( Arc :: new ( 
11231123                ColumnDistributionStatistics :: new_unknown ( ) 
11241124                    . with_null_count ( Precision :: Exact ( 1 ) ) , 
1125-             ) ) 
1126-             . add_column_statistics ( Some ( 
1125+             ) ) ) 
1126+             . add_column_statistics ( Some ( Arc :: new ( 
11271127                ColumnDistributionStatistics :: new_unknown ( ) 
11281128                    . with_null_count ( Precision :: Exact ( 2 ) ) , 
1129-             ) ) 
1130-             . add_column_statistics ( Some ( 
1129+             ) ) ) 
1130+             . add_column_statistics ( Some ( Arc :: new ( 
11311131                ColumnDistributionStatistics :: new_unknown ( ) 
11321132                    . with_null_count ( Precision :: Exact ( 3 ) ) , 
1133-             ) ) ; 
1133+             ) ) ) ; 
11341134
11351135        // Project to columns [2, 0] 
11361136        let  projection = vec ! [ 2 ,  0 ] ; 
@@ -1176,22 +1176,22 @@ mod tests {
11761176        let  stats1 = FileStatistics :: default ( ) 
11771177            . with_num_rows ( Precision :: Exact ( 100 ) ) 
11781178            . with_total_byte_size ( Precision :: Exact ( 1000 ) ) 
1179-             . add_column_statistics ( Some ( 
1179+             . add_column_statistics ( Some ( Arc :: new ( 
11801180                ColumnDistributionStatistics :: new_unknown ( ) 
11811181                    . with_null_count ( Precision :: Exact ( 5 ) ) 
11821182                    . with_distribution ( Precision :: Exact ( dist1) ) 
11831183                    . with_sum_value ( Precision :: Exact ( ScalarValue :: Int32 ( Some ( 500 ) ) ) ) , 
1184-             ) ) ; 
1184+             ) ) ) ; 
11851185
11861186        let  stats2 = FileStatistics :: default ( ) 
11871187            . with_num_rows ( Precision :: Exact ( 200 ) ) 
11881188            . with_total_byte_size ( Precision :: Inexact ( 2000 ) ) 
1189-             . add_column_statistics ( Some ( 
1189+             . add_column_statistics ( Some ( Arc :: new ( 
11901190                ColumnDistributionStatistics :: new_unknown ( ) 
11911191                    . with_null_count ( Precision :: Exact ( 10 ) ) 
11921192                    . with_distribution ( Precision :: Exact ( dist2) ) 
11931193                    . with_sum_value ( Precision :: Exact ( ScalarValue :: Int32 ( Some ( 1000 ) ) ) ) , 
1194-             ) ) ; 
1194+             ) ) ) ; 
11951195
11961196        let  merged = stats1. try_merge ( & stats2) . unwrap ( ) ; 
11971197
@@ -1224,10 +1224,10 @@ mod tests {
12241224        let  stats = FileStatistics :: default ( ) 
12251225            . with_num_rows ( Precision :: Exact ( 100 ) ) 
12261226            . with_total_byte_size ( Precision :: Inexact ( 1024 ) ) 
1227-             . add_column_statistics ( Some ( 
1227+             . add_column_statistics ( Some ( Arc :: new ( 
12281228                ColumnDistributionStatistics :: new_unknown ( ) 
12291229                    . with_null_count ( Precision :: Exact ( 5 ) ) , 
1230-             ) ) ; 
1230+             ) ) ) ; 
12311231
12321232        let  display_str = format ! ( "{}" ,  stats) ; 
12331233        assert ! ( display_str. contains( "Rows=Exact(100)" ) ) ; 
0 commit comments