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

nullif panics on empty array #3261

Closed
bjchambers opened this issue Dec 2, 2022 · 2 comments · Fixed by #3263
Closed

nullif panics on empty array #3261

bjchambers opened this issue Dec 2, 2022 · 2 comments · Fixed by #3263
Labels
arrow Changes to the arrow crate bug

Comments

@bjchambers
Copy link
Contributor

Describe the bug

#[test]
fn test_null_if_len_0() {
    let primitive_array = arrow::array::new_empty_array(&DataType::Int64);
    let condition: Vec<bool> = vec![];
    let condition_array = BooleanArray::from(condition);
    nullif(primitive_array.as_ref(), &condition_array).unwrap();
}

To Reproduce
Run the above test. Observe a panic.

Expected behavior
No panic. Result should be an empty array.

Additional context

@bjchambers bjchambers added the bug label Dec 2, 2022
@bjchambers
Copy link
Contributor Author

@tustvold In debugging, it looks like it still executes the closure in the bitwise unary operator once, and in my case it had 64 ones, so it incremented the valid count by 64. But then len - valid_count causes a panic.

        None => {
            let buffer = arrow::buffer::bitwise_unary_op_helper(&right, right_offset, len, |b| {
                let t = !b;
                valid_count += t.count_ones() as usize;
                t
            });
            // We need to compensate for the additional bits read from the end
            let remainder_len = len % 64;
            if remainder_len != 0 {
                valid_count -= 64 - remainder_len
            }
            buffer
        }

tustvold added a commit to tustvold/arrow-rs that referenced this issue Dec 3, 2022
tustvold added a commit that referenced this issue Dec 3, 2022
* Fix panic on nullif empty array (#3261)

* Format
@alamb alamb added the arrow Changes to the arrow crate label Dec 9, 2022
@alamb
Copy link
Contributor

alamb commented Dec 9, 2022

label_issue.py automatically added labels {'arrow'} from #3263

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants