diff --git a/arrow-flight/src/lib.rs b/arrow-flight/src/lib.rs index 738bd7e74b0..54f4d24b65a 100644 --- a/arrow-flight/src/lib.rs +++ b/arrow-flight/src/lib.rs @@ -452,16 +452,16 @@ mod tests { Field::new("c5", DataType::Timestamp(TimeUnit::Millisecond, None), true), Field::new("c6", DataType::Time32(TimeUnit::Second), false), ]); - // V5 + // V5 with write_legacy_ipc_format = false + // this will write the continuation marker let option = IpcWriteOptions::default(); let schema_ipc = SchemaAsIpc::new(&schema, &option); let result: SchemaResult = schema_ipc.try_into().unwrap(); - // let des_schema: Schema = (&result).try_into().unwrap(); assert_eq!(schema, des_schema); // V4 with write_legacy_ipc_format = true - // This will write the continuation marker + // this will not write the continuation marker let option = IpcWriteOptions::try_new(8, true, MetadataVersion::V4).unwrap(); let schema_ipc = SchemaAsIpc::new(&schema, &option); let result: SchemaResult = schema_ipc.try_into().unwrap(); diff --git a/arrow/src/ipc/convert.rs b/arrow/src/ipc/convert.rs index 158a756ce4d..30080bd0a7e 100644 --- a/arrow/src/ipc/convert.rs +++ b/arrow/src/ipc/convert.rs @@ -156,7 +156,7 @@ pub fn try_schema_from_flatbuffer_bytes(bytes: &[u8]) -> Result { /// Try deserialize the IPC format bytes into a schema pub fn try_schema_from_ipc_buffer(buffer: &[u8]) -> Result { - // There are two type of protocal: https://issues.apache.org/jira/browse/ARROW-6313 + // There are two protocal types: https://issues.apache.org/jira/browse/ARROW-6313 // The original protocal is: // 4 bytes - the byte length of the payload // a flatbuffer Message whose header is the Schema @@ -169,9 +169,14 @@ pub fn try_schema_from_ipc_buffer(buffer: &[u8]) -> Result { // check continuation maker let continuation_maker = &buffer[0..4]; let begin_offset: usize = if continuation_maker.eq(&CONTINUATION_MARKER) { + // 4 bytes: CONTINUATION_MARKER + // 4 bytes: length + // buffer 4 } else { // backward compatibility for buffer without the continuation maker + // 4 bytes: length + // buffer 0 }; let msg = @@ -188,9 +193,9 @@ pub fn try_schema_from_ipc_buffer(buffer: &[u8]) -> Result { })?; Ok(fb_to_schema(ipc_schema)) } else { - Err(ArrowError::ParseError(format!( - "The buffer length is less than 4, parser buffer to Schema" - ))) + Err(ArrowError::ParseError( + "The buffer length is less than 4 and missing the continuation maker or length of buffer".to_string() + )) } }