Skip to content

Commit

Permalink
Fix list equal for empty offset list array (#1818)
Browse files Browse the repository at this point in the history
* Fix list equal for empty offset list array

* For review
  • Loading branch information
viirya committed Jun 9, 2022
1 parent 8f1fd12 commit c92943c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
5 changes: 5 additions & 0 deletions arrow/src/array/equal/list.rs
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.
// 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
Expand Up @@ -629,6 +629,57 @@ mod tests {
test_equal(&a, &b, false);
}

#[test]
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

0 comments on commit c92943c

Please sign in to comment.