Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
cast_column in datafusion::common::nested_struct - Rust
[go: Go Back, main page]

Function cast_column

Source
pub fn cast_column(
    source_col: &Arc<dyn Array>,
    target_field: &Field,
) -> Result<Arc<dyn Array>, DataFusionError>
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 cast
  • target_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