tustvold commented on code in PR #1859:
URL: https://github.com/apache/arrow-rs/pull/1859#discussion_r895548001
##########
arrow/src/array/array_primitive.rs:
##########
@@ -397,29 +397,39 @@ impl<'a, T: ArrowPrimitiveType, Ptr:
Into<NativeAdapter<T>>> FromIterator<Ptr>
let iter = iter.into_iter();
let (lower, _) = iter.size_hint();
- let mut null_buf = BooleanBufferBuilder::new(lower);
+ let mut null_builder = BooleanBufferBuilder::new(lower);
let buffer: Buffer = iter
.map(|item| {
if let Some(a) = item.into().native {
- null_buf.append(true);
+ null_builder.append(true);
a
} else {
- null_buf.append(false);
+ null_builder.append(false);
// this ensures that null items on the buffer are not
arbitrary.
- // This is important because falible operations can use
null values (e.g. a vectorized "add")
+ // This is important because fallible operations can use
null values (e.g. a vectorized "add")
// which may panic (e.g. overflow if the number on the
slots happen to be very large).
T::Native::default()
}
})
.collect();
+ let len = null_builder.len();
+ let null_buf: Buffer = null_builder.into();
+ let valid_count = null_buf.count_set_bits();
+ let null_count = len - valid_count;
+ let opt_null_buf = if null_count == 0 {
+ None
+ } else {
+ Some(null_buf)
+ };
Review Comment:
```suggestion
let opt_null_buf = (null_count != 0).then(|| null_buf);
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]