Dandandan commented on a change in pull request #9293: URL: https://github.com/apache/arrow/pull/9293#discussion_r563147945
########## 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: @jorgecarleitao is the new usage with `extend` what you meant? We also have to know the final count for creating the array, are you thinking of calculating that with `val_buf.len() / mem::size_of::<<T as ArrowPrimitiveType>::Native>()` or is there an other way? ---------------------------------------------------------------- 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