Repository navigation
Description
Describe the bug
MaterializingSortMergeJoinStream calls .expect("Failed to push output batch") on BatchCoalescer::push_batch in on_children_exhausted and in stage_filtered_output. push_batch returns an error when it cannot concatenate the batches it holds, so the join panics where it should return that error. Both functions return Result, so ? would propagate it.
To Reproduce
A filtered left join whose output coalescer combines two staged batches whose Dictionary(Int8, Utf8) columns hold 200 values between them. Each build batch holds 101 values, and the filter keeps half of each batch's pairs, so neither stage fills an output batch by itself. Added to datafusion/physical-plan/src/joins/sort_merge_join/tests.rs:
#[tokio::test]
async fn coalescer_error_panics() -> Result<()> {
use arrow::datatypes::Int8Type;
let left_schema = Arc::new(Schema::new(vec![
Field::new("lk", DataType::Int32, false),
Field::new("lx", DataType::Int32, false),
]));
let right_schema = Arc::new(Schema::new(vec![
Field::new("rk", DataType::Int32, false),
Field::new("rx", DataType::Int32, false),
Field::new(
"p",
DataType::Dictionary(Box::new(DataType::Int8), Box::new(DataType::Utf8)),
false,
),
]));
let left = RecordBatch::try_new(
Arc::clone(&left_schema),
vec![
Arc::new(Int32Array::from((0..200).collect::<Vec<_>>())),
Arc::new(Int32Array::from(vec![0; 200])),
],
)?;
// Each key has one row that fails `lx <= rx` and one that passes
let right_batch = |base: i32, tag: &str| -> Result<RecordBatch> {
let (mut k, mut x, mut p) = (vec![], vec![], vec![]);
for i in 0..100 {
k.extend([base + i, base + i]);
x.extend([-1, 0]);
p.extend([format!("{tag}-fails"), format!("{tag}{i}")]);
}
Ok(RecordBatch::try_new(
Arc::clone(&right_schema),
vec![
Arc::new(Int32Array::from(k)),
Arc::new(Int32Array::from(x)),
Arc::new(p.iter().map(String::as_str).collect::<DictionaryArray<Int8Type>>()),
],
)?)
};
let right = vec![right_batch(0, "a")?, right_batch(100, "b")?];
let left_exec = TestMemoryExec::try_new_exec(&[vec![left]], Arc::clone(&left_schema), None)?;
let right_exec = TestMemoryExec::try_new_exec(&[right], Arc::clone(&right_schema), None)?;
let on: JoinOn = vec![(
Arc::new(Column::new_with_schema("lk", &left_schema)?) as _,
Arc::new(Column::new_with_schema("rk", &right_schema)?) as _,
)];
let filter = JoinFilter::new(
Arc::new(BinaryExpr::new(
Arc::new(Column::new("lx", 0)),
Operator::LtEq,
Arc::new(Column::new("rx", 1)),
)),
vec![
ColumnIndex { index: 1, side: JoinSide::Left },
ColumnIndex { index: 1, side: JoinSide::Right },
],
Arc::new(Schema::new(vec![
Field::new("lx", DataType::Int32, false),
Field::new("rx", DataType::Int32, false),
])),
);
let join = SortMergeJoinExec::try_new(
left_exec,
right_exec,
on,
Some(filter),
Left,
vec![SortOptions::default()],
NullEquality::NullEqualsNothing,
)?;
let ctx = Arc::new(
TaskContext::default().with_session_config(SessionConfig::new().with_batch_size(200)),
);
let _ = common::collect(join.execute(0, ctx)?).await;
Ok(())
}It panics:
panicked at datafusion/physical-plan/src/joins/sort_merge_join/materializing_stream.rs:988:22:
Failed to push output batch: ComputeError("Failed to concatenate column 'p': Dictionary key bigger than the key type")
Expected behavior
The join returns the error. HashJoinExec returns the same overflow as an error: the same tables joined with a hash join in datafusion-cli fail with Execution error: Dictionary key type Int8 cannot represent 200 distinct values.
Activity
mbutrovich commentedon Nov 24, 2026
The same stream has three more
expectcalls on its coalescer, with the messageFailed to push batch to BatchCoalescer: inpush_batch_with_null_metadata,push_batch_with_filter_metadata, andpush_batch_without_metadata. Property-based tests reached the last one:A fix for this issue should cover all five.