Repository navigation
fix(scheduler): fix split UNION ALL stages over custom sources or with merging branches #2852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NoahKusaba
wants to merge
21
commits into
apache:main
Choose a base branch
from
NoahKusaba:feat/empty-unknown-leaf
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,019
−134
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
bb3a717
Restrict any leaf a task runs no partition of to an empty node
NoahKusaba 4578b2f
Keep an empty union branch empty on the executor, and check branch co…
NoahKusaba 0f1edff
Empty every leaf a task runs none of, in one place
NoahKusaba 68b0c96
fix(scheduler): cut multi-partition EmptyExec and PlaceholderRowExec …
NoahKusaba 9deee18
Explain the union branch check by what the executor runs, and name th…
NoahKusaba e20dbd2
Merge remote-tracking branch 'upstream/main' into feat/empty-unknown-…
NoahKusaba ff20be8
Empty an unknown leaf after Ballista's own leaves restrict themselves…
NoahKusaba c835de7
Give the adaptive-planner union failure its own upgrade note, and tid…
NoahKusaba ae852ec
Merge branch 'main' into feat/empty-unknown-leaf
NoahKusaba fce4eff
Name each cause of a refused union branch, and test the empty unknown…
NoahKusaba 1848783
docs: say a node with inputs is still asked to restrict a union branc…
NoahKusaba 14af6e2
Give a union branch over a multi-partition unknown leaf its own stage…
NoahKusaba 859d070
Merge remote-tracking branch 'upstream/main' into feat/empty-unknown-…
NoahKusaba 35e9ea5
Run a stage with an unsplittable union branch as one task instead of …
NoahKusaba bc1470d
Merge remote-tracking branch 'upstream/main' into feat/empty-unknown-…
NoahKusaba 7c27114
Share one split check between planning and binding, and simplify the …
NoahKusaba e648599
Tidy the split-union tests
NoahKusaba efb3b25
Log a union stage that runs as one task, naming the branch
NoahKusaba a819eff
Keep main's stage for a union branch over a shuffle
NoahKusaba 695e29b
Say which planner runs a union stage as one task, and pin the one-par…
NoahKusaba 5ac2f36
Cache on the running stage which union branch can't be split
NoahKusaba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| mod common; | ||
|
|
||
| /// End-to-end tests of `UNION ALL` queries whose stages are split between | ||
| /// tasks. Each task runs only the union branches it owns, so every other | ||
| /// branch is restricted to the task's share of it, often none. They must | ||
| /// return the rows DataFusion returns. | ||
| #[cfg(test)] | ||
| #[cfg(feature = "standalone")] | ||
| mod split_union { | ||
| use crate::common::{ | ||
| ballista_state, collect_lines, datafusion_context, orders_customers_dir, | ||
| register_alltypes, register_orders_customers, | ||
| }; | ||
| use ballista::prelude::SessionContextExt; | ||
| use ballista_core::config::{ | ||
| BALLISTA_ADAPTIVE_PLANNER_ENABLED, BALLISTA_SCHEDULER_MAX_PARTITIONS_PER_TASK, | ||
| }; | ||
| use datafusion::prelude::SessionContext; | ||
| use rstest::rstest; | ||
| use std::path::Path; | ||
|
|
||
| /// Unions whose branches each give a task a different share: none, part | ||
| /// or all of them. | ||
| const QUERIES: &[&str] = &[ | ||
| // Branches that give no rows. The adaptive planner replaces the stage | ||
| // of such a branch with an `EmptyExec` of that stage's partition | ||
| // count, which each task cuts down to its share. | ||
| // | ||
| // An aggregate that matches nothing, beside one that matches all. | ||
| "SELECT id % 2 AS k, count(*) AS c FROM test WHERE id > 100 GROUP BY id % 2 \ | ||
| UNION ALL SELECT id % 2, count(*) FROM test GROUP BY id % 2", | ||
| // The same, the other way round. | ||
| "SELECT id % 2 AS k, count(*) AS c FROM test GROUP BY id % 2 \ | ||
| UNION ALL SELECT id % 2, count(*) FROM test WHERE id > 100 GROUP BY id % 2", | ||
| // An empty middle branch of three. | ||
| "SELECT o_cust AS k, count(*) AS c FROM orders GROUP BY o_cust \ | ||
| UNION ALL SELECT o_cust, count(*) FROM orders WHERE o_id < 0 GROUP BY o_cust \ | ||
| UNION ALL SELECT c_id, 1 FROM customers WHERE c_id < 5", | ||
| // An aggregate over a union with an empty branch. | ||
| "SELECT k, sum(c) AS s FROM ( \ | ||
| SELECT o_cust AS k, count(*) AS c FROM orders WHERE o_id < 0 GROUP BY o_cust \ | ||
| UNION ALL SELECT o_cust, count(*) FROM orders GROUP BY o_cust) \ | ||
| GROUP BY k", | ||
| // A join that matches nothing below an aggregate. | ||
| "SELECT c_region AS r, count(*) AS n FROM orders JOIN customers ON o_cust = c_id \ | ||
| WHERE o_id < 0 GROUP BY c_region \ | ||
| UNION ALL SELECT c_region, count(*) FROM customers GROUP BY c_region", | ||
| // A literal beside an empty aggregate. | ||
| "SELECT 7 AS k, 7 AS c \ | ||
| UNION ALL SELECT id % 2, count(*) FROM test WHERE id > 100 GROUP BY id % 2", | ||
| // A union with an empty branch joined to a table. | ||
| "SELECT x.k, t.c_name FROM ( \ | ||
| SELECT o_cust AS k FROM orders WHERE o_id < 0 GROUP BY o_cust \ | ||
| UNION ALL SELECT c_id FROM customers WHERE c_id < 3) x \ | ||
| JOIN customers t ON x.k = t.c_id", | ||
| // A window over a union with an empty branch. | ||
| "SELECT k, sum(c) OVER (PARTITION BY k) AS s FROM ( \ | ||
| SELECT id % 2 AS k, count(*) AS c FROM test WHERE id > 100 GROUP BY id % 2 \ | ||
| UNION ALL SELECT id % 2, count(*) FROM test GROUP BY id % 2)", | ||
| // Scans, literals and values. | ||
| "SELECT id FROM test UNION ALL SELECT id FROM test", | ||
| "SELECT 1 AS a UNION ALL SELECT 2 UNION ALL SELECT 3", | ||
| "SELECT 100 AS id UNION ALL SELECT id FROM test", | ||
| "SELECT column1 AS id FROM (VALUES (10), (11)) UNION ALL SELECT id FROM test", | ||
| // Branches that merge their input into one partition, which the | ||
| // adaptive planner leaves in the union's stage. Every task would run | ||
| // such a branch, so the stage runs as one task. | ||
| "SELECT id FROM test UNION ALL SELECT id FROM test ORDER BY id", | ||
| "SELECT o_id FROM orders UNION ALL SELECT c_id FROM customers ORDER BY o_id", | ||
| "(SELECT id FROM test ORDER BY id LIMIT 3) UNION ALL SELECT id FROM test", | ||
| "(SELECT o_id FROM orders ORDER BY o_id LIMIT 3) \ | ||
| UNION ALL SELECT o_id FROM orders", | ||
| "SELECT count(*) AS c FROM orders UNION ALL SELECT count(*) FROM customers", | ||
| // A filter over a one-row source, below a round-robin repartition | ||
| // that keeps its four partitions in every task: the stage runs as one | ||
| // task too. | ||
| "SELECT column1 AS id FROM (VALUES (10), (11)) WHERE column1 > 10 \ | ||
| UNION ALL SELECT id FROM test", | ||
| ]; | ||
|
|
||
| async fn register(ctx: &SessionContext, dir: &Path) { | ||
| register_alltypes(ctx, "test").await; | ||
| register_orders_customers(ctx, dir).await; | ||
| } | ||
|
|
||
| /// The formatted rows of `sql`, sorted, since a union's rows come in no | ||
| /// particular order. | ||
| async fn sorted_lines(ctx: &SessionContext, sql: &str) -> Vec<String> { | ||
| let mut lines = collect_lines(ctx, sql).await; | ||
| lines.sort(); | ||
| lines | ||
| } | ||
|
|
||
| #[rstest] | ||
| #[tokio::test] | ||
| async fn split_unions_return_the_rows_datafusion_returns( | ||
| #[values(false, true)] adaptive: bool, | ||
| #[values(1, 2)] max_partitions_per_task: usize, | ||
| ) { | ||
| let dir = orders_customers_dir(); | ||
| let reference = datafusion_context(); | ||
| register(&reference, dir.path()).await; | ||
| let ctx = SessionContext::standalone_with_state(ballista_state(&[ | ||
| (BALLISTA_ADAPTIVE_PLANNER_ENABLED, &adaptive.to_string()), | ||
| ( | ||
| BALLISTA_SCHEDULER_MAX_PARTITIONS_PER_TASK, | ||
| &max_partitions_per_task.to_string(), | ||
| ), | ||
| ])) | ||
| .await | ||
| .unwrap(); | ||
| register(&ctx, dir.path()).await; | ||
|
|
||
| for sql in QUERIES { | ||
| assert_eq!( | ||
| sorted_lines(&ctx, sql).await, | ||
| sorted_lines(&reference, sql).await, | ||
| "adaptive={adaptive} max_partitions_per_task={max_partitions_per_task} \ | ||
| differs for: {sql}" | ||
| ); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.