Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
remove T
  • Loading branch information
Weijun-H committed Jul 19, 2023
commit e76f7f5e0f6666045b933e413b09de2db7ed3b06
20 changes: 6 additions & 14 deletions arrow-string/src/length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

//! Defines kernel for length of string arrays and binary arrays

use arrow_array::types::*;
use arrow_array::*;
use arrow_array::{cast::AsArray, types::*};
use arrow_buffer::Buffer;
use arrow_data::ArrayData;
use arrow_schema::{ArrowError, DataType};
Expand Down Expand Up @@ -88,18 +88,12 @@ where
unary_offsets!(array, T::DATA_TYPE, |x| x)
}

fn length_list_fixed_size<T>(array: &dyn Array, length: i32) -> ArrayRef
where
T: ArrowPrimitiveType,
{
let array = array.as_any().downcast_ref::<FixedSizeListArray>().unwrap();
fn length_list_fixed_size(array: &dyn Array, length: i32) -> ArrayRef {
let array = array.as_fixed_size_list();
let length_list = array.len();
let buffer = Buffer::from_vec(vec![length; length_list]);
Copy link
Contributor

Choose a reason for hiding this comment

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

This assumes T::Native is i32


let data: PrimitiveArray<T> =
PrimitiveArray::new(buffer.into(), array.nulls().cloned());

make_array(data.into())
let data = Int32Array::new(buffer.into(), array.nulls().cloned());
Arc::new(data)
}

fn length_binary<O, T>(array: &dyn Array) -> ArrayRef
Expand Down Expand Up @@ -186,9 +180,7 @@ pub fn length(array: &dyn Array) -> Result<ArrayRef, ArrowError> {
DataType::LargeUtf8 => Ok(length_string::<i64, Int64Type>(array)),
DataType::Binary => Ok(length_binary::<i32, Int32Type>(array)),
DataType::LargeBinary => Ok(length_binary::<i64, Int64Type>(array)),
DataType::FixedSizeList(_, len) => {
Ok(length_list_fixed_size::<Int32Type>(array, *len))
}
DataType::FixedSizeList(_, len) => Ok(length_list_fixed_size(array, *len)),
other => Err(ArrowError::ComputeError(format!(
"length not supported for {other:?}"
))),
Expand Down