Cast a column to match the target field type, with special handling for nested structs. This function serves as the main entry point for column casting operations. For struct types, it enforces that **only struct columns can be cast to struct types**. ## Casting Behavior - **Struct Types**: Delegates to `cast_struct_column` for struct-to-struct casting only - **Non-Struct Types**: Uses Arrow's s
(
source_col: &ArrayRef,
target_type: &DataType,
cast_options: &CastOptions,
)
| 169 | /// - Memory allocation fails during struct construction |
| 170 | /// - Invalid data type combinations are encountered |
| 171 | pub fn cast_column( |
| 172 | source_col: &ArrayRef, |
| 173 | target_type: &DataType, |
| 174 | cast_options: &CastOptions, |
| 175 | ) -> Result<ArrayRef> { |
| 176 | match (source_col.data_type(), target_type) { |
| 177 | (_, Struct(target_fields)) => { |
| 178 | cast_struct_column(source_col, target_fields, cast_options) |
| 179 | } |
| 180 | (DataType::List(_), DataType::List(target_inner)) => { |
| 181 | cast_list_column::<i32>(source_col, target_inner, cast_options) |
| 182 | } |
| 183 | (DataType::LargeList(_), DataType::LargeList(target_inner)) => { |
| 184 | cast_list_column::<i64>(source_col, target_inner, cast_options) |
| 185 | } |
| 186 | (DataType::ListView(_), DataType::ListView(target_inner)) => { |
| 187 | cast_list_view_column::<i32>(source_col, target_inner, cast_options) |
| 188 | } |
| 189 | (DataType::LargeListView(_), DataType::LargeListView(target_inner)) => { |
| 190 | cast_list_view_column::<i64>(source_col, target_inner, cast_options) |
| 191 | } |
| 192 | ( |
| 193 | DataType::Dictionary(source_key_type, _), |
| 194 | DataType::Dictionary(target_key_type, target_value_type), |
| 195 | ) => cast_dictionary_column( |
| 196 | source_col, |
| 197 | source_key_type, |
| 198 | target_key_type, |
| 199 | target_value_type, |
| 200 | cast_options, |
| 201 | ), |
| 202 | _ => Ok(cast_with_options(source_col, target_type, cast_options)?), |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | fn cast_list_column<O: arrow::array::OffsetSizeTrait>( |
| 207 | source_col: &ArrayRef, |
searching dependent graphs…