datafusion icon indicating copy to clipboard operation
datafusion copied to clipboard

minor: `UnionExec` inputs validation

Open gruuya opened this issue 1 year ago • 1 comments

Is your feature request related to a problem or challenge?

When physical plans are directly constructed (i.e. skipping over logical plans/dataframes) in a dynamical manner, UnionExecs inputs can end up being an empty vector.

In turn, this causes a panic such as

thread '...' panicked at datafusion/physical-plan/src/union.rs:542:24:
index out of bounds: the len is 0 but the index is 0

Describe the solution you'd like

Along the lines of the existing validation for the logical union plan maybe this should be an error instead https://github.com/apache/datafusion/blob/79c4c057e67623e86a7cbe2abb1210fc71fa94e3/datafusion/expr/src/logical_plan/plan.rs#L2733-L2735

Otherwise (since that would entail changing the signature of UnionExec::new), at least the panic can be made to have a clearer message, e.g.

--- a/datafusion/physical-plan/src/union.rs
+++ b/datafusion/physical-plan/src/union.rs
@@ -538,8 +538,11 @@ pub fn can_interleave<T: Borrow<Arc<dyn ExecutionPlan>>>(
             .all(|partition| partition == *reference)
 }
 
-fn union_schema(inputs: &[Arc<dyn ExecutionPlan>]) -> SchemaRef {
-    let first_schema = inputs[0].schema();
+fn union_schema(inputs: &[Arc<dyn ExecutionPlan>]) -> Result<SchemaRef> {
+    let first_schema = inputs
+        .get(0)
+        .expect("No union input plans provided")
+        .schema();

Describe alternatives you've considered

No response

Additional context

No response

gruuya avatar Aug 06 '25 07:08 gruuya

take

EeshanBembi avatar Sep 05 '25 20:09 EeshanBembi