viirya commented on code in PR #3207: URL: https://github.com/apache/arrow-rs/pull/3207#discussion_r1043820506
########## arrow-flight/src/utils.rs: ########## @@ -111,3 +142,39 @@ pub fn ipc_message_from_arrow_schema( let IpcMessage(vals) = message; Ok(vals) } + +/// Convert `RecordBatch`es to wire protocol `FlightData`s +pub fn batches_to_flight_data( + schema: Schema, + batches: Vec<RecordBatch>, +) -> Result<Vec<FlightData>, ArrowError> { + let options = IpcWriteOptions::default(); + let schema_flight_data: FlightData = SchemaAsIpc::new(&schema, &options).into(); + let mut dictionaries = vec![]; + let mut flight_data = vec![]; + for batch in batches.iter() { + let (flight_dictionaries, flight_datum) = + flight_data_from_arrow_batch(batch, &options); + dictionaries.extend(flight_dictionaries); + flight_data.push(flight_datum); + } + let mut stream = vec![schema_flight_data]; + stream.extend(dictionaries.into_iter()); + stream.extend(flight_data.into_iter()); + let flight_data: Vec<_> = stream.into_iter().collect(); + Ok(flight_data) +} + +/// Extract and convert an Arrow `Schema` from `FlightInfo` +pub fn arrow_schema_from_flight_info(fi: &FlightInfo) -> Result<Schema, ArrowError> { Review Comment: Is this function used? Seems I cannot find it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org