NoahKusaba commented on code in PR #2914:
URL: 
https://github.com/apache/datafusion-ballista/pull/2914#discussion_r4684804393


##########
ballista/scheduler/src/state/aqe/optimizer_rule/distributed_exchange.rs:
##########
@@ -183,11 +186,54 @@ impl DistributedExchangeRule {
                             execution_plan.name()
                         );
                     }
+                    if execution_plan.is::<UnionExec>() {
+                        return 
self.stage_unsplittable_branches(execution_plan);
+                    }
                 }
             }
         }
         Ok(Transformed::no(execution_plan))
     }
+
+    /// Give each branch of `union` that a task can't run its share of a stage
+    /// of its own, as the static planner does (`can_stay_inline`).
+    ///
+    /// A task running some of the union's partitions restricts every other
+    /// branch to none. A branch that keeps a partition anyway, such as one
+    /// that merges its input through a `SortExec` or a global aggregate, would
+    /// run whole in every task, and restriction refuses such a task. Behind
+    /// an exchange the branch is a shuffle reader, which restricts cleanly, 
and
+    /// the merge runs once.
+    ///
+    /// A branch is judged as the stage's tasks would run it, its exchanges
+    /// replaced by readers, so one over an exchange that hasn't run is left
+    /// for a later pass: the union's stage can't start before then.
+    fn stage_unsplittable_branches(
+        &self,
+        union: Arc<dyn ExecutionPlan>,
+    ) -> datafusion::error::Result<Transformed<Arc<dyn ExecutionPlan>>> {
+        let mut branches: Vec<_> = 
union.children().into_iter().cloned().collect();
+        let mut staged = false;
+        for branch in &mut branches {
+            if matches!(nearest_exchange_status(branch), 
ExchangeStatus::Unresolved)
+                || 
branch_splits(&BallistaAdapter::with_readers(Arc::clone(branch))?)

Review Comment:
   Opened #2938. The resolver is new in 56 too, so in 55.0.0 such a branch 
never stayed inline. The extra stage is relative to `main`. I've fixed the PR 
body to say so.



-- 
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