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

Commit

Permalink
Fixed failing to accept dictionary full of nulls (#1312)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Dec 6, 2022
1 parent fc212a0 commit 7f4a289
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/array/dictionary/mod.rs
Original file line number Diff line number Diff line change
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())?;
}

Ok(Self {
data_type,
Expand Down
14 changes: 14 additions & 0 deletions tests/it/array/dictionary/mod.rs
Original file line number Diff line number Diff line change
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

0 comments on commit 7f4a289

Please sign in to comment.