jonathanc-n commented on code in PR #20768:
URL: https://github.com/apache/datafusion/pull/20768#discussion_r2898703132


##########
datafusion/common/src/stats.rs:
##########
@@ -576,92 +579,201 @@ impl Statistics {
     /// If not, maybe you can call `SchemaMapper::map_column_statistics` to 
make them consistent.
     ///
     /// Returns an error if the statistics do not match the specified schemas.
-    pub fn try_merge_iter<'a, I>(items: I, schema: &Schema) -> 
Result<Statistics>
-    where
-        I: IntoIterator<Item = &'a Statistics>,
-    {
-        let mut items = items.into_iter();
-
-        let Some(init) = items.next() else {
-            return Ok(Statistics::new_unknown(schema));
-        };
-        items.try_fold(init.clone(), |acc: Statistics, item_stats: 
&Statistics| {
-            acc.try_merge(item_stats)
-        })
-    }
-
-    /// Merge this Statistics value with another Statistics value.
-    ///
-    /// Returns an error if the statistics do not match (different schemas).
     ///
     /// # Example
     /// ```
     /// # use datafusion_common::{ColumnStatistics, ScalarValue, Statistics};
     /// # use arrow::datatypes::{Field, Schema, DataType};
     /// # use datafusion_common::stats::Precision;
     /// let stats1 = Statistics::default()
-    ///     .with_num_rows(Precision::Exact(1))
-    ///     .with_total_byte_size(Precision::Exact(2))
+    ///     .with_num_rows(Precision::Exact(10))
     ///     .add_column_statistics(
     ///         ColumnStatistics::new_unknown()
-    ///             .with_null_count(Precision::Exact(3))
-    ///             .with_min_value(Precision::Exact(ScalarValue::from(4)))
-    ///             .with_max_value(Precision::Exact(ScalarValue::from(5))),
+    ///             .with_min_value(Precision::Exact(ScalarValue::from(1)))
+    ///             .with_max_value(Precision::Exact(ScalarValue::from(100)))
+    ///             .with_sum_value(Precision::Exact(ScalarValue::from(500))),
     ///     );
     ///
     /// let stats2 = Statistics::default()
-    ///     .with_num_rows(Precision::Exact(10))
-    ///     .with_total_byte_size(Precision::Inexact(20))
+    ///     .with_num_rows(Precision::Exact(20))
     ///     .add_column_statistics(
     ///         ColumnStatistics::new_unknown()
-    ///             // absent null count
-    ///             .with_min_value(Precision::Exact(ScalarValue::from(40)))
-    ///             .with_max_value(Precision::Exact(ScalarValue::from(50))),
+    ///             .with_min_value(Precision::Exact(ScalarValue::from(5)))
+    ///             .with_max_value(Precision::Exact(ScalarValue::from(200)))
+    ///             .with_sum_value(Precision::Exact(ScalarValue::from(1000))),
     ///     );
     ///
-    /// let merged_stats = stats1.try_merge(&stats2).unwrap();
-    /// let expected_stats = Statistics::default()
-    ///     .with_num_rows(Precision::Exact(11))
-    ///     .with_total_byte_size(Precision::Inexact(22)) // inexact in stats2 
--> inexact
-    ///     .add_column_statistics(
-    ///         ColumnStatistics::new_unknown()
-    ///             .with_null_count(Precision::Absent) // missing from stats2 
--> absent
-    ///             .with_min_value(Precision::Exact(ScalarValue::from(4)))
-    ///             .with_max_value(Precision::Exact(ScalarValue::from(50))),
-    ///     );
+    /// let schema = Schema::new(vec![Field::new("a", DataType::Int32, true)]);
+    /// let merged = Statistics::try_merge_iter(
+    ///     &[stats1, stats2],
+    ///     &schema,
+    /// ).unwrap();
     ///
-    /// assert_eq!(merged_stats, expected_stats)
+    /// assert_eq!(merged.num_rows, Precision::Exact(30));
+    /// assert_eq!(merged.column_statistics[0].min_value,
+    ///     Precision::Exact(ScalarValue::from(1)));
+    /// assert_eq!(merged.column_statistics[0].max_value,
+    ///     Precision::Exact(ScalarValue::from(200)));
+    /// assert_eq!(merged.column_statistics[0].sum_value,
+    ///     Precision::Exact(ScalarValue::from(1500)));
     /// ```
-    pub fn try_merge(self, other: &Statistics) -> Result<Self> {

Review Comment:
   I think this removal should be fine since most API calls would've been 
through `try_merge_iter`, should be mentioned in the upgrade guide though. 



##########
datafusion/common/src/utils/aggregate.rs:
##########


Review Comment:
   Had to add this instead of importing aggregate common functions because 
there would be circular dependency. Much of it is just duplicate code



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to