This is an automated email from the ASF dual-hosted git repository.

viirya pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new c92943cee Fix list equal for empty offset list array (#1818)
c92943cee is described below

commit c92943cee1d93c234b4003c6ae5e4f68edc1e063
Author: Liang-Chi Hsieh <[email protected]>
AuthorDate: Thu Jun 9 09:17:24 2022 -0700

    Fix list equal for empty offset list array (#1818)
    
    * Fix list equal for empty offset list array
    
    * For review
---
 arrow/src/array/equal/list.rs |  5 +++++
 arrow/src/array/equal/mod.rs  | 51 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+)

diff --git a/arrow/src/array/equal/list.rs b/arrow/src/array/equal/list.rs
index 65d320c00..0feefa7aa 100644
--- a/arrow/src/array/equal/list.rs
+++ b/arrow/src/array/equal/list.rs
@@ -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();
 
diff --git a/arrow/src/array/equal/mod.rs b/arrow/src/array/equal/mod.rs
index b89a8fa53..c3b0bbc95 100644
--- a/arrow/src/array/equal/mod.rs
+++ b/arrow/src/array/equal/mod.rs
@@ -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() {

Reply via email to