xudong963 commented on code in PR #15954:
URL: https://github.com/apache/datafusion/pull/15954#discussion_r2102238189


##########
datafusion/physical-plan/src/aggregates/mod.rs:
##########
@@ -751,28 +771,16 @@ impl AggregateExec {
                 })
             }
             _ => {
-                // When the input row count is 0 or 1, we can adopt that 
statistic keeping its reliability.
+                // When the input row count is 1, we can adopt that statistic 
keeping its reliability.
                 // When it is larger than 1, we degrade the precision since it 
may decrease after aggregation.
-                let num_rows = if let Some(value) = self
-                    .input()
-                    .partition_statistics(None)?
-                    .num_rows
-                    .get_value()
+                let num_rows = if let Some(value) = 
child_statistics.num_rows.get_value()
                 {
-                    if *value > 1 {
-                        self.input()
-                            .partition_statistics(None)?
-                            .num_rows
-                            .to_inexact()
-                    } else if *value == 0 {
-                        // Aggregation on an empty table creates a null row.

Review Comment:
   Does it seem like a bug fix? If so, it's better add a unit test to cover it



##########
datafusion/physical-plan/src/aggregates/mod.rs:
##########
@@ -751,28 +771,18 @@ impl AggregateExec {
                 })
             }
             _ => {
-                // When the input row count is 0 or 1, we can adopt that 
statistic keeping its reliability.
+                // When the input row count is 1, we can adopt that statistic 
keeping its reliability.
                 // When it is larger than 1, we degrade the precision since it 
may decrease after aggregation.
-                let num_rows = if let Some(value) = self
-                    .input()
-                    .partition_statistics(None)?
-                    .num_rows
-                    .get_value()
+                let num_rows = if let Some(value) = 
child_statistics.num_rows.get_value()
                 {
                     if *value > 1 {
-                        self.input()
-                            .partition_statistics(None)?
-                            .num_rows
-                            .to_inexact()
+                        child_statistics.num_rows.to_inexact()
                     } else if *value == 0 {
-                        // Aggregation on an empty table creates a null row.
-                        self.input()
-                            .partition_statistics(None)?
-                            .num_rows
-                            .add(&Precision::Exact(1))
+                        child_statistics.num_rows
                     } else {
                         // num_rows = 1 case
-                        self.input().partition_statistics(None)?.num_rows
+                        let grouping_set_num = self.group_by.groups.len();
+                        child_statistics.num_rows.map(|x| x * grouping_set_num)

Review Comment:
   I don't get it here, could you please give a SQL example?



##########
datafusion/physical-plan/src/aggregates/mod.rs:
##########
@@ -733,13 +733,33 @@ impl AggregateExec {
         &self.input_order_mode
     }
 
-    fn statistics_inner(&self) -> Result<Statistics> {
+    fn statistics_inner(&self, child_statistics: Statistics) -> 
Result<Statistics> {
         // TODO stats: group expressions:
         // - once expressions will be able to compute their own stats, use it 
here
         // - case where we group by on a column for which with have the 
`distinct` stat
         // TODO stats: aggr expression:
         // - aggregations sometimes also preserve invariants such as min, 
max...
-        let column_statistics = Statistics::unknown_column(&self.schema());
+
+        let column_statistics = {
+            // self.schema: [<group by exprs>, <aggregate exprs>]
+            let mut column_statistics = 
Statistics::unknown_column(&self.schema());
+
+            for (idx, (expr, _)) in self.group_by.expr.iter().enumerate() {

Review Comment:
   If the child of the agg node is a non-agg node, do the output columns of the 
child match with the `group by expr`?



-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to