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

Function test_string_view

arrow/tests/array_transform.rs:1032–1067  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1030
1031#[test]
1032fn test_string_view() {
1033 let a1 =
1034 StringViewArray::from(vec!["foo", "very long string over 12 bytes", "bar"]).into_data();
1035 let a2 = StringViewArray::from_iter(vec![
1036 Some("bar"),
1037 None,
1038 Some("long string also over 12 bytes"),
1039 ])
1040 .into_data();
1041
1042 a1.validate_full().unwrap();
1043 a2.validate_full().unwrap();
1044
1045 let mut mutable = MutableArrayData::new(vec![&a1, &a2], false, 4);
1046 mutable.extend(1, 0, 1);
1047 mutable.extend(0, 1, 2);
1048 mutable.extend(0, 0, 1);
1049 mutable.extend(1, 2, 3);
1050
1051 let array = StringViewArray::from(mutable.freeze());
1052 assert_eq!(array.data_buffers().len(), 2);
1053 // Should have reused data buffers
1054 assert_eq!(array.data_buffers()[0].as_ptr(), a1.buffers()[1].as_ptr());
1055 assert_eq!(array.data_buffers()[1].as_ptr(), a2.buffers()[1].as_ptr());
1056
1057 let v = array.iter().collect::<Vec<_>>();
1058 assert_eq!(
1059 v,
1060 vec![
1061 Some("bar"),
1062 Some("very long string over 12 bytes"),
1063 Some("foo"),
1064 Some("long string also over 12 bytes")
1065 ]
1066 )
1067}
1068
1069#[test]
1070#[should_panic(expected = "Arrays with inconsistent types passed to MutableArrayData")]

Callers

nothing calls this directly

Calls 6

validate_fullMethod · 0.80
freezeMethod · 0.80
from_iterFunction · 0.50
into_dataMethod · 0.45
extendMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected