diff --git a/arrow-array/src/builder/generic_bytes_view_builder.rs b/arrow-array/src/builder/generic_bytes_view_builder.rs index deaf447d0e6e..770b5c8aae67 100644 --- a/arrow-array/src/builder/generic_bytes_view_builder.rs +++ b/arrow-array/src/builder/generic_bytes_view_builder.rs @@ -707,7 +707,7 @@ mod tests { exp_builder.flush_in_progress(); assert_eq!( exp_builder.completed.last().unwrap().capacity(), - MAX_BLOCK_SIZE as usize + STARTING_BLOCK_SIZE as usize ); } } diff --git a/arrow-buffer/src/buffer/immutable.rs b/arrow-buffer/src/buffer/immutable.rs index c53ef18ba58f..a8659ea64077 100644 --- a/arrow-buffer/src/buffer/immutable.rs +++ b/arrow-buffer/src/buffer/immutable.rs @@ -729,7 +729,7 @@ mod tests { let b = Buffer::from_vec(a); let back = b.into_vec::().unwrap(); assert_eq!(back.len(), 0); - assert_eq!(back.capacity(), 20); + assert_eq!(back.capacity(), 0); // Test vec with values let mut a: Vec = Vec::with_capacity(3); @@ -745,7 +745,7 @@ mod tests { let b = Buffer::from_vec(a); let back = b.into_vec::().unwrap(); assert_eq!(back.len(), 7); - assert_eq!(back.capacity(), 20); + assert_eq!(back.capacity(), 8); // Test incorrect alignment let a: Vec = Vec::new(); @@ -779,7 +779,9 @@ mod tests { let mut b: Vec = Vec::with_capacity(5); b.extend_from_slice(&[1, 2, 3, 4]); let b = Buffer::from_vec(b); - b.into_vec::().unwrap_err(); + assert_eq!(b.len(), 64); + assert_eq!(b.capacity(), 64); + b.into_vec::().unwrap(); // Truncates length // This is an implementation quirk, but isn't harmful @@ -808,7 +810,7 @@ mod tests { // Succeeds as no outstanding shared reference let back = slice.into_vec::().unwrap(); assert_eq!(&back, &[1, 4, 7, 8]); - assert_eq!(back.capacity(), 20); + assert_eq!(back.capacity(), 8); // Slicing by non-multiple length truncates let mut a: Vec = Vec::with_capacity(8); @@ -820,7 +822,7 @@ mod tests { let back = slice.into_vec::().unwrap(); assert_eq!(&back, &[1, 4]); - assert_eq!(back.capacity(), 8); + assert_eq!(back.capacity(), 4); // Offset prevents conversion let a: Vec = vec![1, 3, 4, 6]; diff --git a/arrow-buffer/src/buffer/mutable.rs b/arrow-buffer/src/buffer/mutable.rs index 7fcbd89dd262..5e6cae9fd0f5 100644 --- a/arrow-buffer/src/buffer/mutable.rs +++ b/arrow-buffer/src/buffer/mutable.rs @@ -341,7 +341,10 @@ impl MutableBuffer { } #[inline] - pub(super) fn into_buffer(self) -> Buffer { + pub(super) fn into_buffer(mut self) -> Buffer { + // Don't leak our extra capacity into the final buffer. + self.shrink_to_fit(); + let bytes = unsafe { Bytes::new(self.data, self.len, Deallocation::Standard(self.layout)) }; std::mem::forget(self); Buffer::from_bytes(bytes) diff --git a/arrow-flight/src/encode.rs b/arrow-flight/src/encode.rs index 59fa8afd58d5..1804727edb76 100644 --- a/arrow-flight/src/encode.rs +++ b/arrow-flight/src/encode.rs @@ -1428,7 +1428,7 @@ mod tests { ]) .unwrap(); - verify_encoded_split(batch, 112).await; + verify_encoded_split(batch, 392).await; } #[tokio::test]