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 a498a0342 Return ScalarBuffer from PrimitiveArray::values (#3879)
(#3896)
a498a0342 is described below
commit a498a0342a15a7ddfa10c17752b0cc258bd80afd
Author: Raphael Taylor-Davies <[email protected]>
AuthorDate: Wed Mar 22 10:01:53 2023 +0000
Return ScalarBuffer from PrimitiveArray::values (#3879) (#3896)
* Return ScalarBuffer from PrimitiveArray::values (#3879)
* Fix docs
* Review feedback
---
arrow-array/src/array/primitive_array.rs | 4 ++--
arrow-buffer/src/buffer/scalar.rs | 33 ++++++++++++++++++++++++++++++++
arrow/src/lib.rs | 6 +++---
3 files changed, 38 insertions(+), 5 deletions(-)
diff --git a/arrow-array/src/array/primitive_array.rs
b/arrow-array/src/array/primitive_array.rs
index 78859bd59..241e2a051 100644
--- a/arrow-array/src/array/primitive_array.rs
+++ b/arrow-array/src/array/primitive_array.rs
@@ -275,9 +275,9 @@ impl<T: ArrowPrimitiveType> PrimitiveArray<T> {
self.data.is_empty()
}
- /// Returns a slice of the values of this array
+ /// Returns the values of this array
#[inline]
- pub fn values(&self) -> &[T::Native] {
+ pub fn values(&self) -> &ScalarBuffer<T::Native> {
&self.raw_values
}
diff --git a/arrow-buffer/src/buffer/scalar.rs
b/arrow-buffer/src/buffer/scalar.rs
index 9b3a47785..04c6d9dcc 100644
--- a/arrow-buffer/src/buffer/scalar.rs
+++ b/arrow-buffer/src/buffer/scalar.rs
@@ -114,6 +114,39 @@ impl<T: ArrowNativeType> From<Vec<T>> for ScalarBuffer<T> {
}
}
+impl<'a, T: ArrowNativeType> IntoIterator for &'a ScalarBuffer<T> {
+ type Item = &'a T;
+ type IntoIter = std::slice::Iter<'a, T>;
+
+ fn into_iter(self) -> Self::IntoIter {
+ self.as_ref().iter()
+ }
+}
+
+impl<T: ArrowNativeType, S: AsRef<[T]> + ?Sized> PartialEq<S> for
ScalarBuffer<T> {
+ fn eq(&self, other: &S) -> bool {
+ self.as_ref().eq(other.as_ref())
+ }
+}
+
+impl<T: ArrowNativeType, const N: usize> PartialEq<ScalarBuffer<T>> for [T; N]
{
+ fn eq(&self, other: &ScalarBuffer<T>) -> bool {
+ self.as_ref().eq(other.as_ref())
+ }
+}
+
+impl<T: ArrowNativeType> PartialEq<ScalarBuffer<T>> for [T] {
+ fn eq(&self, other: &ScalarBuffer<T>) -> bool {
+ self.as_ref().eq(other.as_ref())
+ }
+}
+
+impl<T: ArrowNativeType> PartialEq<ScalarBuffer<T>> for Vec<T> {
+ fn eq(&self, other: &ScalarBuffer<T>) -> bool {
+ self.as_slice().eq(other.as_ref())
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/arrow/src/lib.rs b/arrow/src/lib.rs
index 3d1bced29..4b1251ebc 100644
--- a/arrow/src/lib.rs
+++ b/arrow/src/lib.rs
@@ -69,7 +69,7 @@
//!
//! let collected: Vec<_> = array.iter().collect();
//! assert_eq!(collected, vec![Some(1), None, Some(3)]);
-//! assert_eq!(array.values(), [1, 0, 3])
+//! assert_eq!(array.values(), &[1, 0, 3])
//! ```
//!
//! It is also possible to write generic code. For example, the following is
generic over
@@ -168,7 +168,7 @@
//!
//! let array = parse_strings(["1", "2", "3"], DataType::Int32);
//! let integers = array.as_any().downcast_ref::<Int32Array>().unwrap();
-//! assert_eq!(integers.values(), [1, 2, 3])
+//! assert_eq!(integers.values(), &[1, 2, 3])
//! ```
//!
//! # Compute Kernels
@@ -192,7 +192,7 @@
//!
//! let array = parse_strings(["1", "2", "3"], &DataType::UInt32).unwrap();
//! let integers = array.as_any().downcast_ref::<UInt32Array>().unwrap();
-//! assert_eq!(integers.values(), [1, 2, 3])
+//! assert_eq!(integers.values(), &[1, 2, 3])
//! ```
//!
//! This module also implements many common vertical operations: