Skip to content

Commit

Permalink
test for array indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Dec 1, 2021
1 parent 6a19930 commit 76baca1
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions arrow/src/array/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2097,6 +2097,32 @@ mod tests {
.unwrap();
}

#[test]
fn test_validate_dictionary_index_negative_but_not_referenced() {
let values: StringArray = [Some("foo"), Some("bar")].into_iter().collect();

// -1 is not a valid index at all, but the array is length 1
// so the -1 should not be looked at
let keys: Int32Array = [Some(1), Some(-1)].into_iter().collect();

let data_type = DataType::Dictionary(
Box::new(keys.data_type().clone()),
Box::new(values.data_type().clone()),
);

// Expect this not to panic
ArrayData::try_new(
data_type,
1,
None,
None,
0,
vec![keys.data().buffers[0].clone()],
vec![values.data().clone()],
)
.unwrap();
}

#[test]
#[should_panic(
expected = "Value at position 0 out of bounds: 18446744073709551615 (can not convert to i64)"
Expand Down

0 comments on commit 76baca1

Please sign in to comment.