MCPcopy Create free account
hub / github.com/apache/arrow-rs / test_decimal128_under_aligned_round_trip

Function test_decimal128_under_aligned_round_trip

arrow-array/src/ffi.rs:692–722  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

690 #[test]
691 #[cfg(not(feature = "force_validate"))]
692 fn test_decimal128_under_aligned_round_trip() -> Result<()> {
693 // Construct an 8-aligned-but-not-16-aligned i128 data buffer to model
694 // an FFI producer that only guarantees the C Data Interface's
695 // recommended 8-byte alignment (e.g. arrow-java).
696 let aligned = Buffer::from_vec(vec![0_i128, 1_i128, 2_i128]);
697 let under_aligned = aligned.slice(8);
698 assert_eq!(under_aligned.as_ptr().align_offset(8), 0);
699 assert_ne!(under_aligned.as_ptr().align_offset(16), 0);
700
701 // SAFETY: buffer is large enough for 2 i128 elements; misaligned
702 // input is the condition under test.
703 let data = unsafe {
704 ArrayData::builder(DataType::Decimal128(10, 2))
705 .len(2)
706 .add_buffer(under_aligned)
707 .build_unchecked()
708 };
709
710 let schema = FFI_ArrowSchema::try_from(data.data_type()).unwrap();
711 let array = FFI_ArrowArray::new(&data);
712
713 let imported = unsafe { from_ffi(array, &schema) }?;
714 let array = Decimal128Array::from(imported);
715
716 // The little-endian byte layout of [0i128, 1, 2] sliced 8 bytes in
717 // yields elements `1 << 64` and `2 << 64`.
718 assert_eq!(array.len(), 2);
719 assert_eq!(array.value(0), 1_i128 << 64);
720 assert_eq!(array.value(1), 2_i128 << 64);
721 Ok(())
722 }
723
724 #[test]
725 fn test_null_count_handling() {

Callers

nothing calls this directly

Calls 6

from_ffiFunction · 0.85
add_bufferMethod · 0.80
sliceMethod · 0.45
build_uncheckedMethod · 0.45
lenMethod · 0.45
data_typeMethod · 0.45

Tested by

no test coverage detected