sweb commented on a change in pull request #8640:
URL: https://github.com/apache/arrow/pull/8640#discussion_r524925542



##########
File path: rust/arrow/src/array/equal/mod.rs
##########
@@ -604,6 +613,76 @@ mod tests {
         test_equal(&a_slice, &b_slice, true);
     }
 
+    fn create_decimal_array(data: &[Option<i128>]) -> ArrayDataRef {
+        let mut builder = DecimalBuilder::new(20, 23, 6);
+
+        for d in data {
+            if let Some(v) = d {
+                builder.append_value(*v).unwrap();
+            } else {
+                builder.append_null().unwrap();
+            }
+        }
+        builder.finish().data()
+    }
+
+    #[test]
+    fn test_decimal_equal() {
+        let a = create_decimal_array(&[Some(8_887_000_000), 
Some(-8_887_000_000)]);
+        let b = create_decimal_array(&[Some(8_887_000_000), 
Some(-8_887_000_000)]);
+        test_equal(a.as_ref(), b.as_ref(), true);
+
+        let b = create_decimal_array(&[Some(15_887_000_000), 
Some(-8_887_000_000)]);
+        test_equal(a.as_ref(), b.as_ref(), false);
+    }
+
+    // Test the case where null_count > 0
+    #[test]
+    fn test_decimal_null() {
+        let a = create_decimal_array(&[Some(8_887_000_000), None, 
Some(-8_887_000_000)]);
+        let b = create_decimal_array(&[Some(8_887_000_000), None, 
Some(-8_887_000_000)]);
+        test_equal(a.as_ref(), b.as_ref(), true);
+
+        let b = create_decimal_array(&[Some(8_887_000_000), 
Some(-8_887_000_000), None]);
+        test_equal(a.as_ref(), b.as_ref(), false);
+
+        let b = create_decimal_array(&[Some(15_887_000_000), None, 
Some(-8_887_000_000)]);
+        test_equal(a.as_ref(), b.as_ref(), false);
+    }
+
+    #[test]
+    fn test_decimal_offsets() {
+        // Test the case where offset != 0
+        let a = create_decimal_array(&[
+            Some(8_887_000_000),
+            None,
+            None,
+            Some(-8_887_000_000),
+            None,
+            None,
+        ]);
+        let b = create_decimal_array(&[
+            Some(8_887_000_000),
+            None,
+            None,
+            Some(15_887_000_000),
+            None,
+            None,
+        ]);
+
+        let a_slice = a.slice(0, 3);
+        let b_slice = b.slice(0, 3);
+        test_equal(&a_slice, &b_slice, true);
+
+        let a_slice = a.slice(0, 5);
+        let b_slice = b.slice(0, 5);
+        test_equal(&a_slice, &b_slice, false);
+
+        let a_slice = a.slice(4, 1);
+        let b_slice = b.slice(4, 1);
+        test_equal(&a_slice, &b_slice, true);

Review comment:
       I think you found something. This fails:
   
   ```
           let a_slice = a.slice(3, 3);
           let b_slice = b.slice(3, 3);
           test_equal(&a_slice, &b_slice, false);
   ```
   
   I will try to fix it today.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to