cool9850311 commented on code in PR #27532:
URL: https://github.com/apache/datafusion/pull/27532#discussion_r4727226007


##########
datafusion/physical-optimizer/src/limit_pushdown_past_window.rs:
##########
@@ -190,21 +227,84 @@ fn get_limit(node: &Arc<dyn ExecutionPlan>, ctx: &mut 
TraverseState) -> bool {
     // In distributed execution, GlobalLimitExec becomes LocalLimitExec
     // per partition. Handle it the same way (LocalLimitExec has no skip).
     if let Some(limit) = RowBound::of_limit_node(node) {
-        ctx.reset_limit(limit.input_rows());
+        ctx.reset_limit(limit.input_rows(), None);
         return true;
     }
-    if let Some(limit) = node.downcast_ref::<SortPreservingMergeExec>() {
-        ctx.reset_limit(limit.fetch());
+    if let Some(merge) = node.downcast_ref::<SortPreservingMergeExec>() {
+        ctx.reset_limit(merge.fetch(), Some(merge_ordering(merge)));
         return true;
     }
     false
 }
 
+fn merge_ordering(merge: &SortPreservingMergeExec) -> Vec<Arc<dyn 
PhysicalExpr>> {
+    merge
+        .expr()
+        .iter()
+        .map(|sort_expr| Arc::clone(&sort_expr.expr))
+        .collect()
+}
+
+/// Whether the ordering in hand sorts `node`'s rows into the groups its 
windows
+/// read: every `PARTITION BY` expression has to be one of the ordering's own. 
A
+/// window with no `PARTITION BY` reads one group that no ordering separates.
+fn separates_partitions(node: &Arc<dyn ExecutionPlan>, ctx: &TraverseState) -> 
bool {

Review Comment:
   Took me a while to understand it, applied.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to