Skip to content
This repository was archived by the owner on Oct 21, 2024. It is now read-only.

Commit 459bef3

Browse files
committed
client parses schema from ipc batches
1 parent 31c894b commit 459bef3

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

rust/arrow/src/ipc/reader.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use crate::compute::cast;
2929
use crate::datatypes::{DataType, IntervalUnit, Schema, SchemaRef};
3030
use crate::error::{ArrowError, Result};
3131
use crate::ipc;
32+
use crate::ipc::convert::fb_to_schema;
3233
use crate::record_batch::{RecordBatch, RecordBatchReader};
3334
use DataType::*;
3435

@@ -663,6 +664,11 @@ impl<R: Read> RecordBatchReader for StreamReader<R> {
663664
}
664665
}
665666

667+
pub fn schema_from_bytes(bytes: &[u8]) -> Option<Schema> {
668+
let ipc = ipc::get_root_as_message(&bytes[..]);
669+
ipc.header_as_schema().map(|schema| fb_to_schema(schema))
670+
}
671+
666672
#[cfg(test)]
667673
mod tests {
668674
use super::*;

rust/datafusion/examples/flight-client.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
use arrow::ipc::reader;
1819
use flight::flight_service_client::FlightServiceClient;
19-
2020
use flight::Ticket;
2121

2222
#[tokio::main]
@@ -31,6 +31,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
3131

3232
while let Some(batch) = stream.message().await? {
3333
println!("BATCH = {:?}", batch);
34+
35+
let schema = reader::schema_from_bytes(&batch.data_header);
36+
37+
println!("SCHEMA = {:?}", schema);
3438
}
3539

3640
Ok(())

0 commit comments

Comments
 (0)