pub fn cast_column(
source_col: &ArrayRef,
target_field: &Field,
) -> Result<ArrayRef>
Expand description
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 standard
cast
function for primitive type conversions
§Struct Casting Requirements
The struct casting logic requires that the source column must already be a struct type. This makes the function useful for:
- Schema evolution scenarios where struct layouts change over time
- Data migration between different struct schemas
- Type-safe data processing pipelines that maintain struct type integrity
§Arguments
source_col
- The source array to casttarget_field
- The target field definition (including type and metadata)
§Returns
A Result<ArrayRef>
containing the cast array
§Errors
Returns an error if:
- Attempting to cast a non-struct column to a struct type
- Arrow’s cast function fails for non-struct types
- Memory allocation fails during struct construction
- Invalid data type combinations are encountered