tustvold commented on code in PR #3115:
URL: https://github.com/apache/arrow-rs/pull/3115#discussion_r1024535110
##########
arrow-array/src/array/primitive_array.rs:
##########
@@ -489,6 +519,62 @@ impl<T: ArrowPrimitiveType> PrimitiveArray<T> {
)
}
}
+
+ /// Returns `PrimitiveBuilder` of this primitive array for mutating its
values if the underlying
+ /// data buffer is not shared by others.
+ pub fn into_builder(self) -> Result<PrimitiveBuilder<T>, Self> {
+ let len = self.len();
+ let null_bit_buffer = self.data.null_buffer().cloned();
+
+ let element_len = std::mem::size_of::<T::Native>();
+ let buffer = self.data.buffers()[0]
+ .slice_with_length(self.data.offset() * element_len, len *
element_len);
+
+ drop(self.data);
+
+ let try_mutable_null_buffer = match null_bit_buffer {
+ None => Ok(None),
+ Some(null_buffer) => {
+ // Null buffer exists, tries to make it mutable
+ null_buffer.into_mutable().map(Some)
+ }
+ };
+
+ let try_mutable_buffers =
+ if let Err(mutable_null_buffer) = try_mutable_null_buffer {
Review Comment:
A match expression might be clearer
--
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]