xudong963 commented on code in PR #17061: URL: https://github.com/apache/datafusion/pull/17061#discussion_r2290663739
########## datafusion/physical-plan/src/repartition/mod.rs: ########## @@ -755,10 +756,40 @@ impl ExecutionPlan for RepartitionExec { } fn partition_statistics(&self, partition: Option<usize>) -> Result<Statistics> { - if partition.is_none() { - self.input.partition_statistics(None) + if let Some(partition) = partition { + let partition_count = self.partitioning().partition_count(); + if partition >= partition_count { + return internal_err!( + "RepartitionExec invalid partition {} (expected less than {})", + partition, + self.partitioning().partition_count() + ); + } + + let mut stats = self.input.partition_statistics(None)?; + + // Distribute statistics across partitions + stats.num_rows = stats + .num_rows + .get_value() + .map(|rows| Precision::Inexact(rows / partition_count)) + .unwrap_or(Precision::Absent); + stats.total_byte_size = stats + .total_byte_size + .get_value() + .map(|bytes| Precision::Inexact(bytes / partition_count)) Review Comment: I think for the case `partition_count` is 0, it's better to return unknown statistics, which means the child node is empty and doesn't have data. -- 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