Skip to content

Commit c92943c

Browse files
authored
Fix list equal for empty offset list array (#1818)
* Fix list equal for empty offset list array * For review
1 parent 8f1fd12 commit c92943c

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

arrow/src/array/equal/list.rs

+5
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ pub(super) fn list_equal<T: OffsetSizeTrait>(
7373
// however, one is more likely to slice into a list array and get a region that has 0
7474
// child values.
7575
// The test that triggered this behaviour had [4, 4] as a slice of 1 value slot.
76+
// For the edge case that zero length list arrays are always equal.
77+
if len == 0 {
78+
return true;
79+
}
80+
7681
let lhs_child_length = lhs_offsets[lhs_start + len].to_usize().unwrap()
7782
- lhs_offsets[lhs_start].to_usize().unwrap();
7883

arrow/src/array/equal/mod.rs

+51
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,57 @@ mod tests {
629629
test_equal(&a, &b, false);
630630
}
631631

632+
#[test]
633+
fn test_empty_offsets_list_equal() {
634+
let empty: Vec<i32> = vec![];
635+
let values = Int32Array::from(empty);
636+
let empty_offsets: [u8; 0] = [];
637+
638+
let a = ArrayDataBuilder::new(DataType::List(Box::new(Field::new(
639+
"item",
640+
DataType::Int32,
641+
true,
642+
))))
643+
.len(0)
644+
.add_buffer(Buffer::from(&empty_offsets))
645+
.add_child_data(values.data().clone())
646+
.null_bit_buffer(Some(Buffer::from(&empty_offsets)))
647+
.build()
648+
.unwrap();
649+
650+
let b = ArrayDataBuilder::new(DataType::List(Box::new(Field::new(
651+
"item",
652+
DataType::Int32,
653+
true,
654+
))))
655+
.len(0)
656+
.add_buffer(Buffer::from(&empty_offsets))
657+
.add_child_data(values.data().clone())
658+
.null_bit_buffer(Some(Buffer::from(&empty_offsets)))
659+
.build()
660+
.unwrap();
661+
662+
test_equal(&a, &b, true);
663+
664+
let c = ArrayDataBuilder::new(DataType::List(Box::new(Field::new(
665+
"item",
666+
DataType::Int32,
667+
true,
668+
))))
669+
.len(0)
670+
.add_buffer(Buffer::from(vec![0i32, 2, 3, 4, 6, 7, 8].to_byte_slice()))
671+
.add_child_data(
672+
Int32Array::from(vec![1, 2, -1, -2, 3, 4, -3, -4])
673+
.data()
674+
.clone(),
675+
)
676+
.null_bit_buffer(Some(Buffer::from(vec![0b00001001])))
677+
.build()
678+
.unwrap();
679+
680+
test_equal(&a, &c, true);
681+
}
682+
632683
// Test the case where null_count > 0
633684
#[test]
634685
fn test_list_null() {

0 commit comments

Comments
 (0)