tustvold commented on code in PR #5798:
URL: https://github.com/apache/arrow-rs/pull/5798#discussion_r1613560755
##########
arrow-array/src/array/primitive_array.rs:
##########
@@ -480,6 +480,19 @@ pub use crate::types::ArrowPrimitiveType;
/// assert_eq!(array.values(), &[1, 0, 2]);
/// assert!(array.is_null(1));
/// ```
+///
+/// # Example: Get a `PrimitiveArray` from an [`ArrayRef`]
+/// ```
+/// # use std::sync::Arc;
+/// # use arrow_array::{Array, ArrayRef, Float32Array, PrimitiveArray};
+/// # use arrow_array::types::{Float32Type};
+/// # use arrow_schema::DataType;
+/// # let array: ArrayRef = Arc::new(Float32Array::from(vec![1.2, 2.3]));
+/// // will panic if the array is not a Float32Array
+/// assert_eq!(&DataType::Float32, array.data_type());
+/// let f32_array = PrimitiveArray::<Float32Type>::from(array.into_data());
Review Comment:
It's likely marginal, but it avoids a fair amount of data marshalling so
should be faster to not go via ArrayData
Edit: You could also use
https://docs.rs/arrow-array/latest/arrow_array/cast/fn.downcast_array.html but
that is just a wrapper around using into_data
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]