1use std::sync::Arc;
5
6use arrow_array::{Array, ArrayRef, FixedSizeListArray};
7use arrow_cast::CastOptions;
8use arrow_schema::{ArrowError, DataType};
9
10pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
12 use DataType::*;
13 match (from_type, to_type) {
14 (FixedSizeList(from_field, size_from), FixedSizeList(to_field, size_to)) => {
17 size_from == size_to && can_cast_types(from_field.data_type(), to_field.data_type())
18 }
19 _ => arrow_cast::can_cast_types(from_type, to_type),
21 }
22}
23
24pub fn cast_with_options(
26 array: &dyn Array,
27 to_type: &DataType,
28 cast_options: &CastOptions,
29) -> Result<ArrayRef, ArrowError> {
30 use DataType::*;
31 match (array.data_type(), to_type) {
32 (FixedSizeList(_, size_from), FixedSizeList(to_field, size_to)) if size_from == size_to => {
33 let array = array.as_any().downcast_ref::<FixedSizeListArray>().unwrap();
34 let values = cast_with_options(array.values(), to_field.data_type(), cast_options)?;
35 Ok(Arc::new(FixedSizeListArray::try_new(
36 to_field.clone(),
37 *size_from,
38 values,
39 array.nulls().cloned(),
40 )?))
41 }
42 _ => arrow_cast::cast_with_options(array, to_type, cast_options),
43 }
44}