/// Convert a vector of RecordBatches and a cmd to a stream of flights
/// If there are no batches (empty vec), a flight with an empty schema is sent
Convert a vector of RecordBatches and a cmd to a stream of flights
If there are no batches (empty vec), a flight with an empty schema is sent
Convert a vector of RecordBatches and a cmd to a stream of flights If there are no batches ( empty vec ) a flight with an empty schema is sent
pub async fn batch_vec_to_flight(
    cmd: &str,
    batches: Vec<RecordBatch>,
) -> Result<impl Stream<Item = FlightData>, Box<dyn Error>> {
    let schema;
    if batches.len() == 0 {
        schema = Arc::new(Schema::empty());
    } else {
        schema = batches[0].schema();
    }
    // create an initial FlightData message that sends schema
    let options = IpcWriteOptions::default();
    let mut flight_schema = flight_data_from_arrow_schema(&schema, &options);
    flight_schema.flight_descriptor = cmd_to_descriptor(&cmd);
    let mut flight_vec = vec![flight_schema];
    let mut batches: Vec<FlightData> = batches
        .iter()
        .flat_map(|batch| {
            let (dicts, data) = flight_data_from_arrow_batch(batch, &options);
            dicts.into_iter().chain(std::iter::once(data))
        })
        .collect();
    // append batch vector to schema vector, so that the first message sent is the schema
    flight_vec.append(&mut batches);
    Ok(futures::stream::iter(flight_vec))
}
pub async fn batch_vec_to_flight ( cmd : & str , batches : Vec < RecordBatch > , ) -> Result < impl Stream < Item = FlightData > , Box < dyn Error > > { let schema ; if batches . len ( ) == 0 { schema = Arc :: new ( Schema :: empty ( ) ) ; } else { schema = batches [ 0 ] . schema ( ) ; } // create an initial FlightData message that sends schema let options = IpcWriteOptions :: default ( ) ; let mut flight_schema = flight_data_from_arrow_schema ( & schema , & options ) ; flight_schema . flight_descriptor = cmd_to_descriptor ( & cmd ) ; let mut flight_vec = vec ! [ flight_schema ] ; let mut batches : Vec < FlightData > = batches . iter ( ) . flat_map ( | batch | { let ( dicts , data ) = flight_data_from_arrow_batch ( batch , & options ) ; dicts . into_iter ( ) . chain ( std :: iter :: once ( data ) ) } ) . collect ( ) ; // append batch vector to schema vector, so that the first message sent is the schema flight_vec . append ( & mut batches ) ; Ok ( futures :: stream :: iter ( flight_vec ) ) }
Convert a vector of RecordBatches and a cmd to a stream of flights
If there are no batches (empty vec), a flight with an empty schema is sent
Convert a vector of RecordBatches and a cmd to a stream of flights If there are no batches ( empty vec ) a flight with an empty schema is sent
cmd
&str
batches
Vec<RecordBatch>