diff --git a/rust/datafusion/src/execution/context.rs b/rust/datafusion/src/execution/context.rs index 763d2564cf518..69ba27582dad3 100644 --- a/rust/datafusion/src/execution/context.rs +++ b/rust/datafusion/src/execution/context.rs @@ -279,10 +279,18 @@ impl ExecutionContext { let it = p.execute().unwrap(); let mut it = it.lock().unwrap(); let mut results: Vec = vec![]; - while let Ok(Some(batch)) = it.next() { - results.push(batch); + loop { + match it.next() { + Ok(Some(batch)) => { + results.push(batch); + } + Ok(None) => { + // end of result set + return Ok(results); + } + Err(e) => return Err(e), + } } - Ok(results) }) }) .collect();