Skip to content

Commit eddef43

Browse files
hzuotustvold
andauthored
Optionally require alignment when reading IPC, respect alignment when writing (#5554)
* fix * Remove redundant alignment check * fix typo * Add comment about randomized testing * add doc comment on enforce_zero_copy * address alamb feedback * be explicit * fix unit tests * fix arrow-flight tests * clippy * hide api change + add require_alignment to StreamDecoder too * Preserve docs --------- Co-authored-by: Raphael Taylor-Davies <[email protected]>
1 parent 6306df0 commit eddef43

File tree

5 files changed

+431
-76
lines changed

5 files changed

+431
-76
lines changed

arrow-buffer/src/buffer/scalar.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl<T: ArrowNativeType> ScalarBuffer<T> {
6363
/// This method will panic if
6464
///
6565
/// * `offset` or `len` would result in overflow
66-
/// * `buffer` is not aligned to a multiple of `std::mem::size_of::<T>`
66+
/// * `buffer` is not aligned to a multiple of `std::mem::align_of::<T>`
6767
/// * `bytes` is not large enough for the requested slice
6868
pub fn new(buffer: Buffer, offset: usize, len: usize) -> Self {
6969
let size = std::mem::size_of::<T>();

arrow-flight/src/encode.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ mod tests {
627627
use arrow_array::{cast::downcast_array, types::*};
628628
use arrow_buffer::Buffer;
629629
use arrow_cast::pretty::pretty_format_batches;
630+
use arrow_ipc::MetadataVersion;
630631
use arrow_schema::UnionMode;
631632
use std::collections::HashMap;
632633

@@ -638,7 +639,8 @@ mod tests {
638639
/// ensure only the batch's used data (not the allocated data) is sent
639640
/// <https://github.com/apache/arrow-rs/issues/208>
640641
fn test_encode_flight_data() {
641-
let options = IpcWriteOptions::default();
642+
// use 8-byte alignment - default alignment is 64 which produces bigger ipc data
643+
let options = IpcWriteOptions::try_new(8, false, MetadataVersion::V5).unwrap();
642644
let c1 = UInt32Array::from(vec![1, 2, 3, 4, 5, 6]);
643645

644646
let batch = RecordBatch::try_from_iter(vec![("a", Arc::new(c1) as ArrayRef)])
@@ -1343,6 +1345,8 @@ mod tests {
13431345

13441346
let mut stream = FlightDataEncoderBuilder::new()
13451347
.with_max_flight_data_size(max_flight_data_size)
1348+
// use 8-byte alignment - default alignment is 64 which produces bigger ipc data
1349+
.with_options(IpcWriteOptions::try_new(8, false, MetadataVersion::V5).unwrap())
13461350
.build(futures::stream::iter([Ok(batch.clone())]));
13471351

13481352
let mut i = 0;

0 commit comments

Comments
 (0)