You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by vi...@apache.org on 2022/11/25 05:49:25 UTC
[arrow-rs] branch master updated: Derive clone for arrays (#3184)
This is an automated email from the ASF dual-hosted git repository.
viirya 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 2c86895f3 Derive clone for arrays (#3184)
2c86895f3 is described below
commit 2c86895f3672af9a0d835204ccc03108d342361e
Author: Raphael Taylor-Davies <17...@users.noreply.github.com>
AuthorDate: Fri Nov 25 05:49:19 2022 +0000
Derive clone for arrays (#3184)
* Derive clone for arrays
* Also derive DictionaryArray
* Sidestep derive trait constraints
* Clippy
---
arrow-array/src/array/boolean_array.rs | 1 +
arrow-array/src/array/byte_array.rs | 10 ++++++++++
arrow-array/src/array/dictionary_array.rs | 11 +++++++++++
arrow-array/src/array/fixed_size_binary_array.rs | 1 +
arrow-array/src/array/fixed_size_list_array.rs | 1 +
arrow-array/src/array/list_array.rs | 10 ++++++++++
arrow-array/src/array/map_array.rs | 1 +
arrow-array/src/array/null_array.rs | 1 +
arrow-array/src/array/primitive_array.rs | 9 +++++++++
arrow-array/src/array/struct_array.rs | 1 +
arrow-array/src/array/union_array.rs | 1 +
arrow-array/src/raw_pointer.rs | 8 ++++++++
12 files changed, 55 insertions(+)
diff --git a/arrow-array/src/array/boolean_array.rs b/arrow-array/src/array/boolean_array.rs
index 83af9760d..e166f467a 100644
--- a/arrow-array/src/array/boolean_array.rs
+++ b/arrow-array/src/array/boolean_array.rs
@@ -63,6 +63,7 @@ use std::any::Any;
/// assert!(arr.is_valid(3));
/// assert_eq!(true, arr.value(3));
/// ```
+#[derive(Clone)]
pub struct BooleanArray {
data: ArrayData,
/// Pointer to the value array. The lifetime of this must be <= to the value buffer
diff --git a/arrow-array/src/array/byte_array.rs b/arrow-array/src/array/byte_array.rs
index 8c2616624..f846499ee 100644
--- a/arrow-array/src/array/byte_array.rs
+++ b/arrow-array/src/array/byte_array.rs
@@ -42,6 +42,16 @@ pub struct GenericByteArray<T: ByteArrayType> {
value_data: RawPtrBox<u8>,
}
+impl<T: ByteArrayType> Clone for GenericByteArray<T> {
+ fn clone(&self) -> Self {
+ Self {
+ data: self.data.clone(),
+ value_offsets: self.value_offsets,
+ value_data: self.value_data,
+ }
+ }
+}
+
impl<T: ByteArrayType> GenericByteArray<T> {
/// Data type of the array.
pub const DATA_TYPE: DataType = T::DATA_TYPE;
diff --git a/arrow-array/src/array/dictionary_array.rs b/arrow-array/src/array/dictionary_array.rs
index 002ee6f47..6cff5bfdc 100644
--- a/arrow-array/src/array/dictionary_array.rs
+++ b/arrow-array/src/array/dictionary_array.rs
@@ -222,6 +222,17 @@ pub struct DictionaryArray<K: ArrowPrimitiveType> {
is_ordered: bool,
}
+impl<K: ArrowPrimitiveType> Clone for DictionaryArray<K> {
+ fn clone(&self) -> Self {
+ Self {
+ data: self.data.clone(),
+ keys: self.keys.clone(),
+ values: self.values.clone(),
+ is_ordered: self.is_ordered,
+ }
+ }
+}
+
impl<K: ArrowPrimitiveType> DictionaryArray<K> {
/// Attempt to create a new DictionaryArray with a specified keys
/// (indexes into the dictionary) and values (dictionary)
diff --git a/arrow-array/src/array/fixed_size_binary_array.rs b/arrow-array/src/array/fixed_size_binary_array.rs
index 245cf5228..0d63fdded 100644
--- a/arrow-array/src/array/fixed_size_binary_array.rs
+++ b/arrow-array/src/array/fixed_size_binary_array.rs
@@ -47,6 +47,7 @@ use std::any::Any;
///
/// ```
///
+#[derive(Clone)]
pub struct FixedSizeBinaryArray {
data: ArrayData,
value_data: RawPtrBox<u8>,
diff --git a/arrow-array/src/array/fixed_size_list_array.rs b/arrow-array/src/array/fixed_size_list_array.rs
index ca1dee35c..e9ceb556c 100644
--- a/arrow-array/src/array/fixed_size_list_array.rs
+++ b/arrow-array/src/array/fixed_size_list_array.rs
@@ -60,6 +60,7 @@ use std::any::Any;
///
/// For non generic lists, you may wish to consider using
/// [crate::array::FixedSizeBinaryArray]
+#[derive(Clone)]
pub struct FixedSizeListArray {
data: ArrayData,
values: ArrayRef,
diff --git a/arrow-array/src/array/list_array.rs b/arrow-array/src/array/list_array.rs
index 204a36c32..3f581a886 100644
--- a/arrow-array/src/array/list_array.rs
+++ b/arrow-array/src/array/list_array.rs
@@ -68,6 +68,16 @@ pub struct GenericListArray<OffsetSize> {
value_offsets: RawPtrBox<OffsetSize>,
}
+impl<OffsetSize> Clone for GenericListArray<OffsetSize> {
+ fn clone(&self) -> Self {
+ Self {
+ data: self.data.clone(),
+ values: self.values.clone(),
+ value_offsets: self.value_offsets,
+ }
+ }
+}
+
impl<OffsetSize: OffsetSizeTrait> GenericListArray<OffsetSize> {
/// The data type constructor of list array.
/// The input is the schema of the child array and
diff --git a/arrow-array/src/array/map_array.rs b/arrow-array/src/array/map_array.rs
index 0f3ae2e68..c3e6cf822 100644
--- a/arrow-array/src/array/map_array.rs
+++ b/arrow-array/src/array/map_array.rs
@@ -28,6 +28,7 @@ use std::sync::Arc;
///
/// [MapArray] is physically a [crate::array::ListArray] that has a
/// [crate::array::StructArray] with 2 child fields.
+#[derive(Clone)]
pub struct MapArray {
data: ArrayData,
values: ArrayRef,
diff --git a/arrow-array/src/array/null_array.rs b/arrow-array/src/array/null_array.rs
index d796324f6..a5ba953c2 100644
--- a/arrow-array/src/array/null_array.rs
+++ b/arrow-array/src/array/null_array.rs
@@ -36,6 +36,7 @@ use std::any::Any;
/// assert_eq!(array.len(), 10);
/// assert_eq!(array.null_count(), 10);
/// ```
+#[derive(Clone)]
pub struct NullArray {
data: ArrayData,
}
diff --git a/arrow-array/src/array/primitive_array.rs b/arrow-array/src/array/primitive_array.rs
index 42d183238..e3d14e79d 100644
--- a/arrow-array/src/array/primitive_array.rs
+++ b/arrow-array/src/array/primitive_array.rs
@@ -257,6 +257,15 @@ pub struct PrimitiveArray<T: ArrowPrimitiveType> {
raw_values: RawPtrBox<T::Native>,
}
+impl<T: ArrowPrimitiveType> Clone for PrimitiveArray<T> {
+ fn clone(&self) -> Self {
+ Self {
+ data: self.data.clone(),
+ raw_values: self.raw_values,
+ }
+ }
+}
+
impl<T: ArrowPrimitiveType> PrimitiveArray<T> {
/// Returns the length of this array.
#[inline]
diff --git a/arrow-array/src/array/struct_array.rs b/arrow-array/src/array/struct_array.rs
index 841d3235f..fcbda600f 100644
--- a/arrow-array/src/array/struct_array.rs
+++ b/arrow-array/src/array/struct_array.rs
@@ -50,6 +50,7 @@ use std::any::Any;
/// assert_eq!(0, struct_array.null_count());
/// assert_eq!(0, struct_array.offset());
/// ```
+#[derive(Clone)]
pub struct StructArray {
data: ArrayData,
pub(crate) boxed_fields: Vec<ArrayRef>,
diff --git a/arrow-array/src/array/union_array.rs b/arrow-array/src/array/union_array.rs
index c8ccfdc07..092f538bf 100644
--- a/arrow-array/src/array/union_array.rs
+++ b/arrow-array/src/array/union_array.rs
@@ -104,6 +104,7 @@ use std::any::Any;
/// let value = array.value(2).as_any().downcast_ref::<Int32Array>().unwrap().value(0);
/// assert_eq!(34, value);
/// ```
+#[derive(Clone)]
pub struct UnionArray {
data: ArrayData,
boxed_fields: Vec<ArrayRef>,
diff --git a/arrow-array/src/raw_pointer.rs b/arrow-array/src/raw_pointer.rs
index 3e4233ea1..0fea8c186 100644
--- a/arrow-array/src/raw_pointer.rs
+++ b/arrow-array/src/raw_pointer.rs
@@ -25,6 +25,14 @@ pub(super) struct RawPtrBox<T> {
ptr: NonNull<T>,
}
+impl<T> Clone for RawPtrBox<T> {
+ fn clone(&self) -> Self {
+ Self { ptr: self.ptr }
+ }
+}
+
+impl<T> Copy for RawPtrBox<T> {}
+
impl<T> RawPtrBox<T> {
/// # Safety
/// The user must guarantee that: