NoahKusaba commented on code in PR #2914:
URL:
https://github.com/apache/datafusion-ballista/pull/2914#discussion_r4684803111
##########
docs/source/upgrading/56.0.0.md:
##########
@@ -243,25 +243,22 @@ each task emitted its own copy of the build rows. These
joins now run as a
single task, so queries that use them may be slower. Other nested-loop joins
are unchanged.
-#### A split `UNION ALL` with a branch that merges its input runs as one task
+#### A `UNION ALL` branch that merges its input gets a stage of its own
When a stage is split between tasks, each task restricts the `UnionExec`
-branches other tasks own to no partitions. The adaptive planner can leave a
-branch that merges its input into one partition in the union's stage: in a
+branches other tasks own to no partitions. The adaptive planner used to leave
+a branch that merges its input into one partition in the union's stage: in a
`UNION ALL ... ORDER BY`, a branch with a `LIMIT` or an `ORDER BY ... LIMIT`,
or
a `UNION ALL` of aggregates without `GROUP BY`. Such a branch reads its input
whole and keeps its one partition, so every task of the stage ran it, and the
query returned wrong rows, over any source including Parquet.
-The scheduler now runs such a stage as one task, as it does a stage that
-collapses its input, so each branch runs once. The same goes for a branch that
-reads a broadcast, holds a node that sets its own partition count, or reads a
-leaf of several partitions that nothing can restrict. The task
-ignores `ballista.scheduler.max_partitions_per_task` and takes one vcore for
-each of the stage's partitions, up to what its executor has free, so the stage
-runs with less parallelism than before. The scheduler logs each such stage at
-`info` level, naming the branch. The static planner gives such a branch a stage
-of its own and is unaffected.
+The adaptive planner now gives such a branch a stage of its own, as the static
+planner does, so the union's stage reads the branch through a shuffle reader
and
+still splits between tasks. The same goes for a branch that reads a broadcast,
+holds a node that sets its own partition count, or reads a leaf of several
+partitions that nothing but a resolver can restrict. Each such branch adds a
Review Comment:
`AdaptiveRules` (#2743) and #2852 both landed after 55.0.0, so no upgrade
path goes from working to an error. I put the constraint in the `replan_rules`
rustdoc in 89ec07b63 instead.
##########
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(
Review Comment:
Will do: `main` vs this branch, 19 queries at SF1, adaptive,
`max_partitions_per_task=1`, with stage counts. I'll post the numbers here.
##########
ballista/scheduler/src/state/aqe/adapter.rs:
##########
@@ -248,6 +248,15 @@ impl BallistaAdapter {
Ok(Transformed::no(plan))
}
+ /// `plan` as its stage's tasks would see it: each `ExchangeExec`, which
+ /// must already be resolved, replaced by the reader the stage would get.
+ pub(crate) fn with_readers(
Review Comment:
Added in 89ec07b63. It's harmless today because the skipped passes only set
value bounds, not partition counts, which is all `branch_splits` checks.
##########
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:
Will open it. 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]