Dandandan commented on a change in pull request #9293:
URL: https://github.com/apache/arrow/pull/9293#discussion_r563150837
##########
File path: rust/arrow/src/array/array_primitive.rs
##########
@@ -94,6 +94,32 @@ impl<T: ArrowPrimitiveType> PrimitiveArray<T> {
let offset = i + self.offset();
unsafe { *self.raw_values.as_ptr().add(offset) }
}
+
+ /// Creates a PrimitiveArray based on an iterator of values without nulls
+ pub fn from_iter_values<I: IntoIterator<Item = T::Native>>(iter: I) ->
Self {
+ let iter = iter.into_iter();
+ let (_, data_len) = iter.size_hint();
+ let data_len = data_len.expect("Iterator must be sized"); // panic if
no upper bound.
+
+ let mut val_buf = MutableBuffer::new(
+ data_len * mem::size_of::<<T as ArrowPrimitiveType>::Native>(),
+ );
+
+ iter.for_each(|item| {
+ val_buf.push(item);
+ });
Review comment:
Ah with just `Buffer` and `collect` this is even more clean. I adapted
the code with the new API.
----------------------------------------------------------------
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:
[email protected]