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 list equal for empty offset list array #1818

Merged
merged 2 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions arrow/src/array/equal/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ pub(super) fn list_equal<T: OffsetSizeTrait>(
// however, one is more likely to slice into a list array and get a region that has 0
// child values.
// The test that triggered this behaviour had [4, 4] as a slice of 1 value slot.
viirya marked this conversation as resolved.
Show resolved Hide resolved
// For the edge case that zero length list arrays are always equal.
if len == 0 {
return true;
}

let lhs_child_length = lhs_offsets[lhs_start + len].to_usize().unwrap()
- lhs_offsets[lhs_start].to_usize().unwrap();

Expand Down
51 changes: 51 additions & 0 deletions arrow/src/array/equal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,57 @@ mod tests {
test_equal(&a, &b, false);
}

#[test]
viirya marked this conversation as resolved.
Show resolved Hide resolved
fn test_empty_offsets_list_equal() {
let empty: Vec<i32> = vec![];
let values = Int32Array::from(empty);
let empty_offsets: [u8; 0] = [];

let a = ArrayDataBuilder::new(DataType::List(Box::new(Field::new(
"item",
DataType::Int32,
true,
))))
.len(0)
.add_buffer(Buffer::from(&empty_offsets))
.add_child_data(values.data().clone())
.null_bit_buffer(Some(Buffer::from(&empty_offsets)))
.build()
.unwrap();

let b = ArrayDataBuilder::new(DataType::List(Box::new(Field::new(
"item",
DataType::Int32,
true,
))))
.len(0)
.add_buffer(Buffer::from(&empty_offsets))
.add_child_data(values.data().clone())
.null_bit_buffer(Some(Buffer::from(&empty_offsets)))
.build()
.unwrap();

test_equal(&a, &b, true);

let c = ArrayDataBuilder::new(DataType::List(Box::new(Field::new(
"item",
DataType::Int32,
true,
))))
.len(0)
.add_buffer(Buffer::from(vec![0i32, 2, 3, 4, 6, 7, 8].to_byte_slice()))
.add_child_data(
Int32Array::from(vec![1, 2, -1, -2, 3, 4, -3, -4])
.data()
.clone(),
)
.null_bit_buffer(Some(Buffer::from(vec![0b00001001])))
.build()
.unwrap();

test_equal(&a, &c, true);
}

// Test the case where null_count > 0
#[test]
fn test_list_null() {
Expand Down