liamzwbao commented on code in PR #17061: URL: https://github.com/apache/datafusion/pull/17061#discussion_r2292426712
########## 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: What's the expected behavior if `partition_count` is 0 and the `partition` arg of this function is larger than 0? - `partition_statistics(Some(0))` -> `Statistics::new_unknown()` - `partition_statistics(Some(1))` -> `Internal Error` or `Statistics::new_unknown()` ? -- 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