Skip to content
Open
Show file tree
Hide file tree
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 Nov 11, 2026
4578b2f
Keep an empty union branch empty on the executor, and check branch co…
NoahKusaba Nov 11, 2026
0f1edff
Empty every leaf a task runs none of, in one place
NoahKusaba Nov 11, 2026
68b0c96
fix(scheduler): cut multi-partition EmptyExec and PlaceholderRowExec …
NoahKusaba Nov 11, 2026
9deee18
Explain the union branch check by what the executor runs, and name th…
NoahKusaba Nov 12, 2026
e20dbd2
Merge remote-tracking branch 'upstream/main' into feat/empty-unknown-…
NoahKusaba Nov 12, 2026
ff20be8
Empty an unknown leaf after Ballista's own leaves restrict themselves…
NoahKusaba Nov 12, 2026
c835de7
Give the adaptive-planner union failure its own upgrade note, and tid…
NoahKusaba Nov 12, 2026
ae852ec
Merge branch 'main' into feat/empty-unknown-leaf
NoahKusaba Nov 14, 2026
fce4eff
Name each cause of a refused union branch, and test the empty unknown…
NoahKusaba Nov 16, 2026
1848783
docs: say a node with inputs is still asked to restrict a union branc…
NoahKusaba Nov 16, 2026
14af6e2
Give a union branch over a multi-partition unknown leaf its own stage…
NoahKusaba Nov 16, 2026
859d070
Merge remote-tracking branch 'upstream/main' into feat/empty-unknown-…
NoahKusaba Nov 16, 2026
35e9ea5
Run a stage with an unsplittable union branch as one task instead of …
NoahKusaba Nov 16, 2026
bc1470d
Merge remote-tracking branch 'upstream/main' into feat/empty-unknown-…
NoahKusaba Nov 17, 2026
7c27114
Share one split check between planning and binding, and simplify the …
NoahKusaba Nov 17, 2026
e648599
Tidy the split-union tests
NoahKusaba Nov 17, 2026
efb3b25
Log a union stage that runs as one task, naming the branch
NoahKusaba Nov 17, 2026
a819eff
Keep main's stage for a union branch over a shuffle
NoahKusaba Nov 17, 2026
695e29b
Say which planner runs a union stage as one task, and pin the one-par…
NoahKusaba Nov 17, 2026
5ac2f36
Cache on the running stage which union branch can't be split
NoahKusaba Nov 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 140 additions & 0 deletions ballista/client/tests/split_union.rs
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(
Comment thread
NoahKusaba marked this conversation as resolved.
Resolved
#[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}"
);
}
}
}
Loading
Loading