Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Fixed failing to accept dictionary full of nulls #1312

Merged
merged 1 commit into from Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/array/dictionary/mod.rs
Expand Up @@ -119,7 +119,9 @@ impl<K: DictionaryKey> DictionaryArray<K> {
) -> Result<Self, Error> {
check_data_type(K::KEY_TYPE, &data_type, values.data_type())?;

check_indexes(keys.values(), values.len())?;
if keys.null_count() != keys.len() {
check_indexes(keys.values(), values.len())?;
jorgecarleitao marked this conversation as resolved.
Show resolved Hide resolved
}

Ok(Self {
data_type,
Expand Down
14 changes: 14 additions & 0 deletions tests/it/array/dictionary/mod.rs
Expand Up @@ -40,6 +40,20 @@ fn try_new_incorrect_key() {
assert!(r);
}

#[test]
fn try_new_nulls() {
let key: Option<u32> = None;
let keys = PrimitiveArray::from_iter([key]);
let value: &[&str] = &[];
let values = Utf8Array::<i32>::from_slice(value);

let data_type =
DataType::Dictionary(u32::KEY_TYPE, Box::new(values.data_type().clone()), false);
let r = DictionaryArray::try_new(data_type, keys, values.boxed()).is_ok();

assert!(r);
}

#[test]
fn try_new_incorrect_dt() {
let values = Utf8Array::<i32>::from_slice(["a", "aa"]);
Expand Down