| 741 | } |
| 742 | |
| 743 | fn _length_dictionary<K: ArrowDictionaryKeyType>() { |
| 744 | const TOTAL: i32 = 100; |
| 745 | |
| 746 | let v = ["aaaa", "bb", "ccccc", "ddd", "eeeeee"]; |
| 747 | let data: Vec<Option<&str>> = (0..TOTAL) |
| 748 | .map(|n| { |
| 749 | let i = n % 5; |
| 750 | if i == 3 { None } else { Some(v[i as usize]) } |
| 751 | }) |
| 752 | .collect(); |
| 753 | |
| 754 | let dict_array: DictionaryArray<K> = data.clone().into_iter().collect(); |
| 755 | |
| 756 | let expected: Vec<Option<i32>> = |
| 757 | data.iter().map(|opt| opt.map(|s| s.len() as i32)).collect(); |
| 758 | |
| 759 | let res = length(&dict_array).unwrap(); |
| 760 | let actual = res.as_any().downcast_ref::<DictionaryArray<K>>().unwrap(); |
| 761 | let actual: Vec<Option<i32>> = actual |
| 762 | .values() |
| 763 | .as_any() |
| 764 | .downcast_ref::<Int32Array>() |
| 765 | .unwrap() |
| 766 | .take_iter(dict_array.keys_iter()) |
| 767 | .collect(); |
| 768 | |
| 769 | for i in 0..TOTAL as usize { |
| 770 | assert_eq!(expected[i], actual[i],); |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | #[test] |
| 775 | fn bit_length_dictionary() { |