Cast this [ColumnarValue] to the specified `DataType` # Struct Casting Behavior When casting struct types, fields are matched **by name** rather than position: - Source fields are matched to target fields using case-sensitive name comparison - Fields are reordered to match the target schema - Missing target fields are filled with null arrays - Extra source fields are ignored For non-struct type
(
&self,
cast_type: &DataType,
cast_options: Option<&CastOptions<'static>>,
)
| 286 | /// |
| 287 | /// For non-struct types, uses Arrow's standard positional casting. |
| 288 | pub fn cast_to( |
| 289 | &self, |
| 290 | cast_type: &DataType, |
| 291 | cast_options: Option<&CastOptions<'static>>, |
| 292 | ) -> Result<ColumnarValue> { |
| 293 | let cast_options = cast_options.cloned().unwrap_or(DEFAULT_CAST_OPTIONS); |
| 294 | match self { |
| 295 | ColumnarValue::Array(array) => { |
| 296 | let casted = cast_array_by_name(array, cast_type, &cast_options)?; |
| 297 | Ok(ColumnarValue::Array(casted)) |
| 298 | } |
| 299 | ColumnarValue::Scalar(scalar) => Ok(ColumnarValue::Scalar( |
| 300 | scalar.cast_to_with_options(cast_type, &cast_options)?, |
| 301 | )), |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | fn cast_array_by_name( |