You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/11/09 09:17:56 UTC

[GitHub] [arrow-rs] jhorstmann commented on a diff in pull request #3062: Fix null_count computation in binary

jhorstmann commented on code in PR #3062:
URL: https://github.com/apache/arrow-rs/pull/3062#discussion_r1017668466


##########
arrow/src/compute/kernels/arithmetic.rs:
##########
@@ -3044,4 +3044,61 @@ mod tests {
         let c = add(&a, &b).unwrap();
         assert_eq!(c, expected);
     }
+
+    #[test]
+    fn test_resize_builder() {
+        let mut null_buffer_builder = BooleanBufferBuilder::new(16);
+        null_buffer_builder.append_slice(&[
+            false, false, false, false, false, false, false, false, false, false, false,
+            false, false, true, true, true,
+        ]);
+        // `resize` resizes the buffer length to the ceil of byte numbers.
+        // So the underlying buffer is not changed.
+        null_buffer_builder.resize(13);
+        assert_eq!(null_buffer_builder.len(), 13);
+
+        let null_buffer = null_buffer_builder.finish();
+
+        // `count_set_bits` counts 1-bits in entire buffer. Because above `resize` doesn't
+        // actually truncate the buffer, `count_set_bits` still return 3.
+        assert_eq!(null_buffer.count_set_bits(), 3);
+        // `count_set_bits_offset` takes len in bits as parameter.
+        assert_eq!(null_buffer.count_set_bits_offset(0, 13), 0);
+
+        let mut data_buffer_builder = BufferBuilder::<i32>::new(13);
+        data_buffer_builder.append_slice(&[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
+        let data_buffer = data_buffer_builder.finish();
+
+        let arg1: Int32Array = ArrayDataBuilder::new(DataType::Int32)
+            .len(13)
+            .null_count(13)

Review Comment:
   Should the test skip setting the null count explicitly and instead let the ArrayDataBuilder calculate it?



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

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