validate_struct_compatibility

Function validate_struct_compatibility 

Source
pub fn validate_struct_compatibility(
    source_fields: &[FieldRef],
    target_fields: &[FieldRef],
) -> Result<bool>
Expand description

Validates compatibility between source and target struct fields for casting operations.

This function implements comprehensive struct compatibility checking by examining:

  • Field name matching between source and target structs
  • Type castability for each matching field (including recursive struct validation)
  • Proper handling of missing fields (target fields not in source are allowed - filled with nulls)
  • Proper handling of extra fields (source fields not in target are allowed - ignored)

§Compatibility Rules

  • Field Matching: Fields are matched by name (case-sensitive)
  • Missing Target Fields: Allowed - will be filled with null values during casting
  • Extra Source Fields: Allowed - will be ignored during casting
  • Type Compatibility: Each matching field must be castable using Arrow’s type system
  • Nested Structs: Recursively validates nested struct compatibility

§Arguments

  • source_fields - Fields from the source struct type
  • target_fields - Fields from the target struct type

§Returns

  • Ok(true) if the structs are compatible for casting
  • Err(DataFusionError) with detailed error message if incompatible

§Examples

// Compatible: source has extra field, target has missing field
// Source: {a: i32, b: string, c: f64}  
// Target: {a: i64, d: bool}
// Result: Ok(true) - 'a' can cast i32->i64, 'b','c' ignored, 'd' filled with nulls

// Incompatible: matching field has incompatible types
// Source: {a: string}
// Target: {a: binary}
// Result: Err(...) - string cannot cast to binary