Skip to content

Commit

Permalink
refactor(rust): Remove use of cast in ArrowArray::new (#19899)
Browse files Browse the repository at this point in the history
  • Loading branch information
nameexhaustion authored Nov 21, 2024
1 parent bbb4b2b commit 502377e
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions crates/polars-arrow/src/ffi/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,35 +99,26 @@ impl ArrowArray {
/// This method releases `buffers`. Consumers of this struct *must* call `release` before
/// releasing this struct, or contents in `buffers` leak.
pub(crate) fn new(array: Box<dyn Array>) -> Self {
let needs_variadic_buffer_sizes = matches!(
array.dtype(),
ArrowDataType::BinaryView | ArrowDataType::Utf8View
);

#[allow(unused_mut)]
let (offset, mut buffers, children, dictionary) =
offset_buffers_children_dictionary(array.as_ref());

let variadic_buffer_sizes = if needs_variadic_buffer_sizes {
#[cfg(feature = "compute_cast")]
{
let arr = crate::compute::cast::cast_unchecked(
array.as_ref(),
&ArrowDataType::BinaryView,
)
.unwrap();
let arr = arr.as_any().downcast_ref::<BinaryViewArray>().unwrap();
let variadic_buffer_sizes = match array.dtype() {
ArrowDataType::BinaryView => {
let arr = array.as_any().downcast_ref::<BinaryViewArray>().unwrap();
let boxed = arr.variadic_buffer_lengths().into_boxed_slice();
let ptr = boxed.as_ptr().cast::<u8>();
buffers.push(Some(ptr));
boxed
}
#[cfg(not(feature = "compute_cast"))]
{
panic!("activate 'compute_cast' feature")
}
} else {
Box::from([])
},
ArrowDataType::Utf8View => {
let arr = array.as_any().downcast_ref::<Utf8ViewArray>().unwrap();
let boxed = arr.variadic_buffer_lengths().into_boxed_slice();
let ptr = boxed.as_ptr().cast::<u8>();
buffers.push(Some(ptr));
boxed
},
_ => Box::new([]),
};

let buffers_ptr = buffers
Expand Down

0 comments on commit 502377e

Please sign in to comment.