Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic on nullif empty array (#3261) #3263

Merged
merged 2 commits into from
Dec 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions arrow-select/src/nullif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ pub fn nullif(left: &dyn Array, right: &BooleanArray) -> Result<ArrayRef, ArrowE
let len = left_data.len();
let left_offset = left_data.offset();

if len == 0 {
return Ok(make_array(left_data.clone()));
}

// left=0 (null) right=null output bitmap=null
// left=0 right=1 output bitmap=null
// left=1 (set) right=null output bitmap=set (passthrough)
Expand Down Expand Up @@ -119,6 +123,7 @@ mod tests {
use arrow_array::cast::{as_boolean_array, as_primitive_array, as_string_array};
use arrow_array::types::Int32Type;
use arrow_array::{Int32Array, StringArray, StructArray};
use arrow_data::ArrayData;
use arrow_schema::{DataType, Field};

#[test]
Expand Down Expand Up @@ -451,4 +456,12 @@ mod tests {
let expected = Int32Array::from(vec![Some(15), Some(7), None, Some(1), Some(9)]);
assert_eq!(res, &expected);
}

#[test]
fn nullif_empty() {
let a = Int32Array::from(ArrayData::new_empty(&DataType::Int32));
let mask = BooleanArray::from(ArrayData::new_empty(&DataType::Boolean));
let res = nullif(&a, &mask).unwrap();
assert_eq!(res.as_ref(), &a);
}
}