| 1488 | |
| 1489 | #[test] |
| 1490 | fn test_logical_nulls() -> Result<(), ArrowError> { |
| 1491 | let values = Arc::new(RunArray::try_new( |
| 1492 | &Int32Array::from(vec![1, 3, 7]), |
| 1493 | &Int32Array::from(vec![Some(1), None, Some(3)]), |
| 1494 | )?) as ArrayRef; |
| 1495 | |
| 1496 | // For this test to be meaningful, the values array need to have different nulls and logical nulls |
| 1497 | assert_eq!(values.null_count(), 0); |
| 1498 | assert_eq!(values.logical_null_count(), 2); |
| 1499 | |
| 1500 | // Construct a trivial dictionary with 1-1 mapping to underlying array |
| 1501 | let dictionary = DictionaryArray::<Int8Type>::try_new( |
| 1502 | Int8Array::from((0..values.len()).map(|i| i as i8).collect::<Vec<_>>()), |
| 1503 | Arc::clone(&values), |
| 1504 | )?; |
| 1505 | |
| 1506 | // No keys are null |
| 1507 | assert_eq!(dictionary.null_count(), 0); |
| 1508 | // Dictionary array values are logically nullable |
| 1509 | assert_eq!(dictionary.logical_null_count(), values.logical_null_count()); |
| 1510 | assert_eq!(dictionary.logical_nulls(), values.logical_nulls()); |
| 1511 | assert!(dictionary.is_nullable()); |
| 1512 | |
| 1513 | // Construct a trivial dictionary with 1-1 mapping to underlying array except that key 0 is nulled out |
| 1514 | let dictionary = DictionaryArray::<Int8Type>::try_new( |
| 1515 | Int8Array::from( |
| 1516 | (0..values.len()) |
| 1517 | .map(|i| i as i8) |
| 1518 | .map(|i| if i == 0 { None } else { Some(i) }) |
| 1519 | .collect::<Vec<_>>(), |
| 1520 | ), |
| 1521 | Arc::clone(&values), |
| 1522 | )?; |
| 1523 | |
| 1524 | // One key is null |
| 1525 | assert_eq!(dictionary.null_count(), 1); |
| 1526 | |
| 1527 | // Dictionary array values are logically nullable |
| 1528 | assert_eq!( |
| 1529 | dictionary.logical_null_count(), |
| 1530 | values.logical_null_count() + 1 |
| 1531 | ); |
| 1532 | assert!(dictionary.is_nullable()); |
| 1533 | |
| 1534 | Ok(()) |
| 1535 | } |
| 1536 | |
| 1537 | #[test] |
| 1538 | fn test_normalized_keys() { |