diff --git a/src/tui/execution.rs b/src/tui/execution.rs index 2cf34b2..08a4d11 100644 --- a/src/tui/execution.rs +++ b/src/tui/execution.rs @@ -279,37 +279,42 @@ impl TuiExecution { if let Some(streams) = self.flightsql_result_stream.lock().await.as_mut() { - match streams.next().await { - Some((ticket, Ok(batch))) => { - info!("Received batch for {ticket}"); - let duration = start.elapsed(); - let results = ExecutionResultsBatch { - batch, - duration, - query: sql.to_string(), - }; - sender.send( - AppEvent::FlightSQLExecutionResultsNextBatch( - results, - ), - )?; + // Collect all batches from the stream + while let Some((ticket, result)) = + streams.next().await + { + match result { + Ok(batch) => { + info!("Received batch for {ticket}"); + let duration = start.elapsed(); + let results = ExecutionResultsBatch { + batch, + duration, + query: sql.to_string(), + }; + sender.send( + AppEvent::FlightSQLExecutionResultsNextBatch( + results, + ), + )?; + } + Err(e) => { + error!( + "Error executing stream for ticket {ticket}: {:?}", + e + ); + let elapsed = start.elapsed(); + let e = ExecutionError { + query: sql.to_string(), + error: e.to_string(), + duration: elapsed, + }; + sender.send( + AppEvent::FlightSQLExecutionResultsError(e), + )?; + break; + } } - Some((ticket, Err(e))) => { - error!( - "Error executing stream for ticket {ticket}: {:?}", - e - ); - let elapsed = start.elapsed(); - let e = ExecutionError { - query: sql.to_string(), - error: e.to_string(), - duration: elapsed, - }; - sender.send( - AppEvent::FlightSQLExecutionResultsError(e), - )?; - } - None => {} } } } diff --git a/src/tui/state/tabs/flightsql.rs b/src/tui/state/tabs/flightsql.rs index c3389fa..31a0f2d 100644 --- a/src/tui/state/tabs/flightsql.rs +++ b/src/tui/state/tabs/flightsql.rs @@ -21,7 +21,7 @@ use std::sync::Arc; use color_eyre::Result; use datafusion::arrow::{ array::{Array, RecordBatch, UInt32Array}, - compute::take_record_batch, + compute::{concat_batches, take_record_batch}, datatypes::Schema, error::ArrowError, }; @@ -316,7 +316,11 @@ fn take_record_batches( match batches.len() { 0 => Ok(RecordBatch::new_empty(Arc::new(Schema::empty()))), 1 => take_record_batch(&batches[0], indices), - // For now we just get the first batch - _ => take_record_batch(&batches[0], indices), + _ => { + // Concatenate all batches into a single batch before taking indices + let schema = batches[0].schema(); + let concatenated = concat_batches(&schema, batches)?; + take_record_batch(&concatenated, indices) + } } }