Skip to content

Commit

Permalink
trusted flatbuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
XiangpengHao committed Feb 4, 2025
1 parent ea07927 commit be255bc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 14 additions & 0 deletions arrow-flight/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,20 @@ mod tests {
assert_eq!(actual, expected);
}

#[test]
fn test_dict_schema() {
let schema = Schema::new(vec![
Field::new_dictionary("a", DataType::UInt16, DataType::Utf8, false),
Field::new_dictionary("b", DataType::UInt16, DataType::Utf8, false),
]);

let flight_info = FlightInfo::new().try_with_schema(&schema).unwrap();

let new_schema = Schema::try_from(flight_info).unwrap();
// println!("new_schema: {:?}", new_schema);
assert_eq!(schema, new_schema);
}

#[test]
fn ser_deser_schema_result() {
let schema = Schema::new(vec![
Expand Down
6 changes: 2 additions & 4 deletions arrow-ipc/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use std::fmt::{Debug, Formatter};
use std::sync::Arc;

use crate::writer::DictionaryTracker;
use crate::{size_prefixed_root_as_message, KeyValue, Message, CONTINUATION_MARKER};
use crate::{size_prefixed_root_as_message_unchecked, KeyValue, Message, CONTINUATION_MARKER};
use DataType::*;

/// Low level Arrow [Schema] to IPC bytes converter
Expand Down Expand Up @@ -269,9 +269,7 @@ pub fn try_schema_from_ipc_buffer(buffer: &[u8]) -> Result<Schema, ArrowError> {
// buffer
0
};
let msg = size_prefixed_root_as_message(&buffer[begin_offset..]).map_err(|err| {
ArrowError::ParseError(format!("Unable to convert flight info to a message: {err}"))
})?;
let msg = unsafe { size_prefixed_root_as_message_unchecked(&buffer[begin_offset..]) };
let ipc_schema = msg.header_as_schema().ok_or_else(|| {
ArrowError::ParseError("Unable to convert flight info to a schema".to_string())
})?;
Expand Down

0 comments on commit be255bc

Please sign in to comment.