xudong963 commented on code in PR #17061: URL: https://github.com/apache/datafusion/pull/17061#discussion_r2278054549
########## datafusion/physical-plan/src/repartition/mod.rs: ########## @@ -755,10 +756,43 @@ 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)) + .unwrap_or(Precision::Absent); + + // Handle column statistics: keep min/max values, make others absent + for col_stats in &mut stats.column_statistics { + // Keep min_value and max_value as they represent data range Review Comment: If we assume the data distribution is uniform, and we use "Inexact", the min/max for each partition will be so inaccurate, so here I incline to be conservative -- 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