You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by tu...@apache.org on 2023/03/26 21:22:19 UTC
[arrow-rs] branch master updated: Zero-copy conversion from Vec to PrimitiveArray (#3917)
This is an automated email from the ASF dual-hosted git repository.
tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/master by this push:
new 9bd2bae58 Zero-copy conversion from Vec to PrimitiveArray (#3917)
9bd2bae58 is described below
commit 9bd2bae586ed5b0edfd699f89a0855d79f61b611
Author: Raphael Taylor-Davies <17...@users.noreply.github.com>
AuthorDate: Sun Mar 26 22:22:13 2023 +0100
Zero-copy conversion from Vec to PrimitiveArray (#3917)
* Zero-copy conversion from Vec to PrimitiveArray
* Further tweaks
---
arrow-array/src/array/binary_array.rs | 4 ++--
arrow-array/src/array/primitive_array.rs | 2 +-
arrow-array/src/record_batch.rs | 2 +-
arrow-string/src/substring.rs | 4 ++--
4 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/arrow-array/src/array/binary_array.rs b/arrow-array/src/array/binary_array.rs
index b965279fb..5a07f9a0a 100644
--- a/arrow-array/src/array/binary_array.rs
+++ b/arrow-array/src/array/binary_array.rs
@@ -209,8 +209,8 @@ where
let data_len = offsets.len() - 1;
let array_data = ArrayData::builder(Self::DATA_TYPE)
.len(data_len)
- .add_buffer(Buffer::from_slice_ref(&offsets))
- .add_buffer(Buffer::from_slice_ref(&values))
+ .add_buffer(Buffer::from_vec(offsets))
+ .add_buffer(Buffer::from_vec(values))
.null_bit_buffer(Some(null_buf.into()));
let array_data = unsafe { array_data.build_unchecked() };
Self::from(array_data)
diff --git a/arrow-array/src/array/primitive_array.rs b/arrow-array/src/array/primitive_array.rs
index bc62677c7..c6ae27585 100644
--- a/arrow-array/src/array/primitive_array.rs
+++ b/arrow-array/src/array/primitive_array.rs
@@ -971,7 +971,7 @@ macro_rules! def_numeric_from_vec {
fn from(data: Vec<<$ty as ArrowPrimitiveType>::Native>) -> Self {
let array_data = ArrayData::builder($ty::DATA_TYPE)
.len(data.len())
- .add_buffer(Buffer::from_slice_ref(&data));
+ .add_buffer(Buffer::from_vec(data));
let array_data = unsafe { array_data.build_unchecked() };
PrimitiveArray::from(array_data)
}
diff --git a/arrow-array/src/record_batch.rs b/arrow-array/src/record_batch.rs
index 9e9f15dae..02ced1a0b 100644
--- a/arrow-array/src/record_batch.rs
+++ b/arrow-array/src/record_batch.rs
@@ -603,7 +603,7 @@ mod tests {
let record_batch =
RecordBatch::try_new(Arc::new(schema), vec![Arc::new(a), Arc::new(b)])
.unwrap();
- assert_eq!(record_batch.get_array_memory_size(), 672);
+ assert_eq!(record_batch.get_array_memory_size(), 628);
}
fn check_batch(record_batch: RecordBatch, num_rows: usize) {
diff --git a/arrow-string/src/substring.rs b/arrow-string/src/substring.rs
index 7ee33f7fc..997b26361 100644
--- a/arrow-string/src/substring.rs
+++ b/arrow-string/src/substring.rs
@@ -296,7 +296,7 @@ fn binary_substring<OffsetSize: OffsetSizeTrait>(
None,
array.nulls().map(|b| b.inner().sliced()),
0,
- vec![Buffer::from_slice_ref(&new_offsets), new_values.into()],
+ vec![Buffer::from_vec(new_offsets), new_values.into()],
vec![],
)
};
@@ -420,7 +420,7 @@ fn utf8_substring<OffsetSize: OffsetSizeTrait>(
None,
array.nulls().map(|b| b.inner().sliced()),
0,
- vec![Buffer::from_slice_ref(&new_offsets), new_values.into()],
+ vec![Buffer::from_vec(new_offsets), new_values.into()],
vec![],
)
};