Skip to content

Commit

Permalink
Add tests for limit and filter with BinaryArray
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Trinquier committed Feb 24, 2019
1 parent 728884b commit f0578f6
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion rust/arrow/src/compute/array_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ pub fn limit(array: &Array, num_elements: usize) -> Result<ArrayRef> {
DataType::Boolean => limit_array!(array, num_elements_safe, BooleanArray),
DataType::Utf8 => {
let b = array.as_any().downcast_ref::<BinaryArray>().unwrap();
let mut values: Vec<&[u8]> = Vec::with_capacity(num_elements_safe as usize);
let mut values: Vec<&[u8]> = Vec::with_capacity(num_elements_safe);
for i in 0..num_elements_safe {
values.push(b.value(i));
}
Expand Down Expand Up @@ -463,6 +463,17 @@ mod tests {
assert_eq!(8, d.value(1));
}

#[test]
fn test_filter_binary_array() {
let a = BinaryArray::from(vec!["hello", " ", "world", "!"]);
let b = BooleanArray::from(vec![true, false, true, false]);
let c = filter(&a, &b).unwrap();
let d = c.as_ref().as_any().downcast_ref::<BinaryArray>().unwrap();
assert_eq!(2, d.len());
assert_eq!("hello", d.get_string(0));
assert_eq!("world", d.get_string(1));
}

#[test]
fn test_limit_array() {
let a = Int32Array::from(vec![5, 6, 7, 8, 9]);
Expand All @@ -474,6 +485,16 @@ mod tests {
assert_eq!(7, c.value(2));
}

#[test]
fn test_limit_binary_array() {
let a = BinaryArray::from(vec!["hello", " ", "world", "!"]);
let b = limit(&a, 2).unwrap();
let c = b.as_ref().as_any().downcast_ref::<BinaryArray>().unwrap();
assert_eq!(2, c.len());
assert_eq!("hello", c.get_string(0));
assert_eq!(" ", c.get_string(1));
}

#[test]
fn test_limit_array_with_limit_too_large() {
let a = Int32Array::from(vec![5, 6, 7, 8, 9]);
Expand Down

0 comments on commit f0578f6

Please sign in to comment.