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 min/max computation for sliced arrays (#2779) #2780

Merged
merged 2 commits into from
Sep 26, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 20 additions & 4 deletions arrow/src/compute/kernels/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,7 @@ where
.map(|i| unsafe { array.value_unchecked(i) })
.reduce(|acc, item| if cmp(&acc, &item) { item } else { acc })
} else {
let null_buffer = array
.data_ref()
.null_buffer()
.map(|b| b.bit_slice(array.offset(), array.len()));
let null_buffer = array.data_ref().null_buffer();
Copy link
Contributor Author

@tustvold tustvold Sep 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an added bonus this will be faster. The bug is that BitIndexIterator is already applying the offset, and so it gets applied twice and we iterate a somewhat arbitrary part of the null mask.

(Note the way BitIndexIterator is written is that len acts to truncate the iteration, if len exceeds the data it doesn't panic it just stops early, perhaps it should)

tustvold marked this conversation as resolved.
Show resolved Hide resolved
let iter = BitIndexIterator::new(
null_buffer.as_deref().unwrap(),
array.offset(),
Expand Down Expand Up @@ -681,6 +678,7 @@ where

#[cfg(test)]
mod tests {
use arrow_array::types::Float64Type;
use super::*;
use crate::array::*;
use crate::compute::add;
Expand Down Expand Up @@ -1130,4 +1128,22 @@ mod tests {
let array = dict_array.downcast_dict::<Float32Array>().unwrap();
assert_eq!(2.0_f32, min_array::<Float32Type, _>(array).unwrap());
}

#[test]
fn test_min_max_sliced() {
tustvold marked this conversation as resolved.
Show resolved Hide resolved
let expected_min = Some(4.0);
let input: Float64Array = vec![None, Some(4.0)].into_iter().collect();
let actual = min(&input);

assert_eq!(actual, expected_min);

let sliced_input: Float64Array = vec![None, None, None, None, None, Some(4.0)].into_iter().collect();
let sliced_input = sliced_input.slice(4, 2);
let sliced_input = as_primitive_array::<Float64Type>(&sliced_input);

assert_eq!(sliced_input, &input);

let actual = min(&sliced_input);
assert_eq!(actual, expected_min);
}
}