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

Function test_string_data_from_foreign

arrow/tests/array_validation.rs:1016–1059  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1014
1015#[test]
1016fn test_string_data_from_foreign() {
1017 let mut strings = "foobarfoobar".to_owned();
1018 let mut offsets = vec![0_i32, 0, 3, 6, 12];
1019 let mut bitmap = vec![0b1110_u8];
1020
1021 let strings_buffer = unsafe {
1022 Buffer::from_custom_allocation(
1023 NonNull::new_unchecked(strings.as_mut_ptr()),
1024 strings.len(),
1025 Arc::new(strings),
1026 )
1027 };
1028 let offsets_buffer = unsafe {
1029 Buffer::from_custom_allocation(
1030 NonNull::new_unchecked(offsets.as_mut_ptr() as *mut u8),
1031 offsets.len() * std::mem::size_of::<i32>(),
1032 Arc::new(offsets),
1033 )
1034 };
1035 let null_buffer = unsafe {
1036 Buffer::from_custom_allocation(
1037 NonNull::new_unchecked(bitmap.as_mut_ptr()),
1038 bitmap.len(),
1039 Arc::new(bitmap),
1040 )
1041 };
1042
1043 let data = ArrayData::try_new(
1044 DataType::Utf8,
1045 4,
1046 Some(null_buffer),
1047 0,
1048 vec![offsets_buffer, strings_buffer],
1049 vec![],
1050 )
1051 .unwrap();
1052
1053 let array = make_array(data);
1054 let array = array.as_any().downcast_ref::<StringArray>().unwrap();
1055
1056 let expected = StringArray::from(vec![None, Some("foo"), Some("bar"), Some("foobar")]);
1057
1058 assert_eq!(array, &expected);
1059}
1060
1061#[test]
1062fn test_decimal_full_validation() {

Callers

nothing calls this directly

Calls 5

try_newFunction · 0.85
as_mut_ptrMethod · 0.80
make_arrayFunction · 0.50
lenMethod · 0.45
as_anyMethod · 0.45

Tested by

no test coverage detected