Skip to content

Commit

Permalink
For review
Browse files Browse the repository at this point in the history
  • Loading branch information
viirya committed Jun 8, 2022
1 parent 1a66136 commit fbead0d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
21 changes: 9 additions & 12 deletions arrow/src/array/equal/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,16 @@ 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.
let lhs_child_length = if len == 0 {
0
} else {
lhs_offsets[lhs_start + len].to_usize().unwrap()
- lhs_offsets[lhs_start].to_usize().unwrap()
};
// For the edge case that zero length list arrays are always equal.
if len == 0 {
return true;
}

let rhs_child_length = if len == 0 {
0
} else {
rhs_offsets[rhs_start + len].to_usize().unwrap()
- rhs_offsets[rhs_start].to_usize().unwrap()
};
let lhs_child_length = lhs_offsets[lhs_start + len].to_usize().unwrap()
- lhs_offsets[lhs_start].to_usize().unwrap();

let rhs_child_length = rhs_offsets[rhs_start + len].to_usize().unwrap()
- rhs_offsets[rhs_start].to_usize().unwrap();

if lhs_child_length == 0 && lhs_child_length == rhs_child_length {
return true;
Expand Down
18 changes: 18 additions & 0 deletions arrow/src/array/equal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,24 @@ mod tests {
.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
Expand Down

0 comments on commit fbead0d

Please sign in to comment.