Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 12 additions & 1 deletion arrow-cast/src/cast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ mod list;
mod map;
mod run_array;
mod string;
mod union;

use crate::cast::decimal::*;
use crate::cast::dictionary::*;
use crate::cast::list::*;
use crate::cast::map::*;
use crate::cast::run_array::*;
use crate::cast::string::*;
pub use crate::cast::union::*;

use arrow_buffer::IntervalMonthDayNano;
use arrow_data::ByteView;
Expand Down Expand Up @@ -108,6 +110,8 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
can_cast_types(from_value_type, to_value_type)
}
(Dictionary(_, value_type), _) => can_cast_types(value_type, to_type),
(Union(fields, _), _) => union::resolve_child_array(fields, to_type).is_some(),
(_, Union(_, _)) => false,
(RunEndEncoded(_, value_type), _) => can_cast_types(value_type.data_type(), to_type),
(_, RunEndEncoded(_, value_type)) => can_cast_types(from_type, value_type.data_type()),
(_, Dictionary(_, value_type)) => can_cast_types(from_type, value_type),
Expand Down Expand Up @@ -230,7 +234,6 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
}
(Struct(_), _) => false,
(_, Struct(_)) => false,

(_, Boolean) => from_type.is_integer() || from_type.is_floating() || from_type.is_string(),
(Boolean, _) => to_type.is_integer() || to_type.is_floating() || to_type.is_string(),

Expand Down Expand Up @@ -781,6 +784,14 @@ pub fn cast_with_options(
))),
}
}
(Union(_, _), _) => union_extract_by_type(
array.as_any().downcast_ref::<UnionArray>().unwrap(),
to_type,
cast_options,
),
(_, Union(_, _)) => Err(ArrowError::CastError(format!(
"Casting from {from_type} to {to_type} not supported"
))),
(Dictionary(index_type, _), _) => match **index_type {
Int8 => dictionary_cast::<Int8Type>(array, to_type, cast_options),
Int16 => dictionary_cast::<Int16Type>(array, to_type, cast_options),
Expand Down
Loading
Loading