Skip to content

Commit

Permalink
Add unit tests and fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
RinChanNOWWW committed Apr 11, 2024
1 parent deb1de3 commit dd74d49
Showing 1 changed file with 64 additions and 1 deletion.
65 changes: 64 additions & 1 deletion arrow-select/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ fn filter_array(values: &dyn Array, predicate: &FilterPredicate) -> Result<Array
Ok(Arc::new(filter_bytes(values.as_binary::<i64>(), predicate)))
}
DataType::BinaryView => {
Ok(Arc::new(filter_byte_view(values.as_string_view(), predicate)))
Ok(Arc::new(filter_byte_view(values.as_binary_view(), predicate)))
}
DataType::RunEndEncoded(_, _) => {
downcast_run_array!{
Expand Down Expand Up @@ -919,6 +919,69 @@ mod tests {
assert!(d.is_null(1));
}

fn _test_filter_byte_view<T>()
where
T: ByteViewType,
str: AsRef<T::Native>,
T::Native: PartialEq,
{
let array = {
// ["hello", "world", null, "large payload over 12 bytes", "lulu"]
let mut builder = GenericByteViewBuilder::<T>::new();
builder.append_value("hello");
builder.append_value("world");
builder.append_null();
builder.append_value("large payload over 12 bytes");
builder.append_value("lulu");
builder.finish()
};

{
let predicate = BooleanArray::from(vec![true, false, true, true, false]);
let actual = filter(&array, &predicate).unwrap();

assert_eq!(actual.len(), 3);

let expected = {
// ["hello", null, "large payload over 12 bytes"]
let mut builder = GenericByteViewBuilder::<T>::new();
builder.append_value("hello");
builder.append_null();
builder.append_value("large payload over 12 bytes");
builder.finish()
};

assert_eq!(actual.as_ref(), &expected);
}

{
let predicate = BooleanArray::from(vec![true, false, false, false, true]);
let actual = filter(&array, &predicate).unwrap();

assert_eq!(actual.len(), 2);

let expected = {
// ["hello", "lulu"]
let mut builder = GenericByteViewBuilder::<T>::new();
builder.append_value("hello");
builder.append_value("lulu");
builder.finish()
};

assert_eq!(actual.as_ref(), &expected);
}
}

#[test]
fn test_filter_string_view() {
_test_filter_byte_view::<StringViewType>()
}

#[test]
fn test_filter_binary_view() {
_test_filter_byte_view::<BinaryViewType>()
}

#[test]
fn test_filter_array_slice_with_null() {
let a = Int32Array::from(vec![Some(5), None, Some(7), Some(8), Some(9)]).slice(1, 4);
Expand Down

0 comments on commit dd74d49

Please sign in to comment.