Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return ScalarBuffer from PrimitiveArray::values (#3879) #3896

Merged
merged 3 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion arrow-array/src/array/primitive_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl<T: ArrowPrimitiveType> PrimitiveArray<T> {

/// Returns a slice of the values of this array
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also update the doc?

#[inline]
pub fn values(&self) -> &[T::Native] {
pub fn values(&self) -> &ScalarBuffer<T::Native> {
&self.raw_values
}

Expand Down
33 changes: 33 additions & 0 deletions arrow-buffer/src/buffer/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
6 changes: 3 additions & 3 deletions arrow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't work out how to make this work as before, tbh I'm somewhat confused how it was working before...

//! ```
//!
//! It is also possible to write generic code. For example, the following is generic over
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down