tustvold commented on code in PR #3115:
URL: https://github.com/apache/arrow-rs/pull/3115#discussion_r1024531019
##########
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();
Review Comment:
We need to bit_slice this to be consistent with the values buffer
##########
arrow-array/src/builder/boolean_buffer_builder.rs:
##########
@@ -33,6 +33,10 @@ impl BooleanBufferBuilder {
Self { buffer, len: 0 }
}
+ pub fn new_from_buffer(buffer: MutableBuffer, len: usize) -> Self {
+ Self { buffer, len }
Review Comment:
I think we need to assert that `len <= buffer.len() * 8`
##########
arrow-buffer/src/buffer/immutable.rs:
##########
@@ -227,6 +227,28 @@ impl Buffer {
pub fn count_set_bits_offset(&self, offset: usize, len: usize) -> usize {
UnalignedBitChunk::new(self.as_slice(), offset, len).count_ones()
}
+
+ /// Returns `MutableBuffer` for mutating the buffer if this buffer is not
shared.
+ pub fn into_mutable(self, len: usize) -> Result<MutableBuffer, Self> {
+ let offset_ptr = self.as_ptr();
+ let offset = self.offset;
+ let length = self.length;
+ Arc::try_unwrap(self.data)
+ .map(|bytes| {
+ // The pointer of underlying buffer should not be offset.
Review Comment:
We would likely need to update the kernels to make use of this, but
theoretically. Whether this will make a major difference in practice I'm not
sure, sorts, aggregates and joins, tend to dominate queries in my experience
--
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]