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

Function test_try_new

arrow-array/src/array/dictionary_array.rs:1348–1374  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1346
1347 #[test]
1348 fn test_try_new() {
1349 let values: StringArray = [Some("foo"), Some("bar"), Some("baz")]
1350 .into_iter()
1351 .collect();
1352 let keys: Int32Array = [Some(0), Some(2), None, Some(1)].into_iter().collect();
1353
1354 let array = DictionaryArray::new(keys, Arc::new(values));
1355 assert_eq!(array.keys().data_type(), &DataType::Int32);
1356 assert_eq!(array.values().data_type(), &DataType::Utf8);
1357
1358 assert_eq!(array.null_count(), 1);
1359 assert_eq!(array.logical_null_count(), 1);
1360
1361 assert!(array.keys().is_valid(0));
1362 assert!(array.keys().is_valid(1));
1363 assert!(array.keys().is_null(2));
1364 assert!(array.keys().is_valid(3));
1365
1366 assert_eq!(array.keys().value(0), 0);
1367 assert_eq!(array.keys().value(1), 2);
1368 assert_eq!(array.keys().value(3), 1);
1369
1370 assert_eq!(
1371 "DictionaryArray {keys: PrimitiveArray<Int32>\n[\n 0,\n 2,\n null,\n 1,\n] values: StringArray\n[\n \"foo\",\n \"bar\",\n \"baz\",\n]}\n",
1372 format!("{array:?}")
1373 );
1374 }
1375
1376 #[test]
1377 #[should_panic(expected = "Invalid dictionary key 3 at index 1, expected 0 <= key < 2")]

Callers

nothing calls this directly

Calls 2

collectMethod · 0.80
into_iterMethod · 0.45

Tested by

no test coverage detected