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

Function _dictionary

arrow-string/src/substring.rs:931–959  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

929 }
930
931 fn _dictionary<K: ArrowDictionaryKeyType>() {
932 const TOTAL: i32 = 100;
933
934 let v = ["aaa", "bbb", "ccc", "ddd", "eee"];
935 let data: Vec<Option<&str>> = (0..TOTAL)
936 .map(|n| {
937 let i = n % 5;
938 if i == 3 { None } else { Some(v[i as usize]) }
939 })
940 .collect();
941
942 let dict_array: DictionaryArray<K> = data.clone().into_iter().collect();
943
944 let expected: Vec<Option<&str>> = data.iter().map(|opt| opt.map(|s| &s[1..3])).collect();
945
946 let res = substring(&dict_array, 1, Some(2)).unwrap();
947 let actual = res.as_any().downcast_ref::<DictionaryArray<K>>().unwrap();
948 let actual: Vec<Option<&str>> = actual
949 .values()
950 .as_any()
951 .downcast_ref::<GenericStringArray<i32>>()
952 .unwrap()
953 .take_iter(actual.keys_iter())
954 .collect();
955
956 for i in 0..TOTAL as usize {
957 assert_eq!(expected[i], actual[i],);
958 }
959 }
960
961 #[test]
962 fn check_invalid_array_type() {

Callers

nothing calls this directly

Calls 9

collectMethod · 0.80
keys_iterMethod · 0.80
substringFunction · 0.70
into_iterMethod · 0.45
cloneMethod · 0.45
iterMethod · 0.45
as_anyMethod · 0.45
take_iterMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected