adriangb commented on code in PR #17028: URL: https://github.com/apache/datafusion/pull/17028#discussion_r2254847146
########## datafusion/physical-plan/src/sorts/sort.rs: ########## @@ -1116,10 +1127,46 @@ impl ExecutionPlan for SortExec { self: Arc<Self>, children: Vec<Arc<dyn ExecutionPlan>>, ) -> Result<Arc<dyn ExecutionPlan>> { - let mut new_sort = SortExec::new(self.expr.clone(), Arc::clone(&children[0])) - .with_fetch(self.fetch) - .with_preserve_partitioning(self.preserve_partitioning); - new_sort.filter = self.filter.clone(); + let mut new_sort = self.cloned(); + assert!( + children.len() == 1, + "SortExec should have exactly one child" + ); + new_sort.input = Arc::clone(&children[0]); + // Recompute the properties based on the new input since they may have changed. + let (cache, sort_prefix) = Self::compute_properties( + &new_sort.input, + new_sort.expr.clone(), + new_sort.preserve_partitioning, + ) Review Comment: The logic for this change is: 1. We need to do similar work as `with_new_children` (i.e. clone `SortExec`) but each method has slightly different requirements (`with_new_children` needs to reset `cache` while `reset_state` needs to reset `filter`. 2. To solve this I created the new `SortExec::cloned` which does neither of those two things and moved the resetting of `cache` into `with_new_children` and the resetting of `filter` into `reset_state`. In other words, it doesn't make sense to put `Self::compute_properties(...)` in `reset_state`. -- 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