From 8c60882c989fefd2c5df8a90a0af18479539cd61 Mon Sep 17 00:00:00 2001 From: Raphael Taylor-Davies Date: Tue, 21 Mar 2023 19:16:18 +0000 Subject: [PATCH] Return ScalarBuffer from PrimitiveArray::values (#3879) --- arrow-array/src/array/primitive_array.rs | 2 +- arrow-buffer/src/buffer/scalar.rs | 33 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/arrow-array/src/array/primitive_array.rs b/arrow-array/src/array/primitive_array.rs index 78859bd5956f..9e1bf5b7db8e 100644 --- a/arrow-array/src/array/primitive_array.rs +++ b/arrow-array/src/array/primitive_array.rs @@ -277,7 +277,7 @@ impl PrimitiveArray { /// Returns a slice of the values of this array #[inline] - pub fn values(&self) -> &[T::Native] { + pub fn values(&self) -> &ScalarBuffer { &self.raw_values } diff --git a/arrow-buffer/src/buffer/scalar.rs b/arrow-buffer/src/buffer/scalar.rs index 9b3a47785098..04c6d9dcc7ac 100644 --- a/arrow-buffer/src/buffer/scalar.rs +++ b/arrow-buffer/src/buffer/scalar.rs @@ -114,6 +114,39 @@ impl From> for ScalarBuffer { } } +impl<'a, T: ArrowNativeType> IntoIterator for &'a ScalarBuffer { + type Item = &'a T; + type IntoIter = std::slice::Iter<'a, T>; + + fn into_iter(self) -> Self::IntoIter { + self.as_ref().iter() + } +} + +impl + ?Sized> PartialEq for ScalarBuffer { + fn eq(&self, other: &S) -> bool { + self.as_ref().eq(other.as_ref()) + } +} + +impl PartialEq> for [T; N] { + fn eq(&self, other: &ScalarBuffer) -> bool { + self.as_ref().eq(other.as_ref()) + } +} + +impl PartialEq> for [T] { + fn eq(&self, other: &ScalarBuffer) -> bool { + self.as_ref().eq(other.as_ref()) + } +} + +impl PartialEq> for Vec { + fn eq(&self, other: &ScalarBuffer) -> bool { + self.as_slice().eq(other.as_ref()) + } +} + #[cfg(test)] mod tests { use super::*;