MCPcopy Create free account
hub / github.com/apache/datafusion / validate_struct_compatibility

Function validate_struct_compatibility

datafusion/common/src/nested_struct.rs:345–381  ·  view source on GitHub ↗

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 wit

(
    source_fields: &[FieldRef],
    target_fields: &[FieldRef],
)

Source from the content-addressed store, hash-verified

343/// ```
344///
345pub fn validate_struct_compatibility(
346 source_fields: &[FieldRef],
347 target_fields: &[FieldRef],
348) -> Result<()> {
349 let has_overlap = has_one_of_more_common_fields(source_fields, target_fields);
350 if !has_overlap {
351 return _plan_err!(
352 "Cannot cast struct with {} fields to {} fields because there is no field name overlap",
353 source_fields.len(),
354 target_fields.len()
355 );
356 }
357
358 // Check compatibility for each target field
359 for target_field in target_fields {
360 // Look for matching field in source by name
361 if let Some(source_field) = source_fields
362 .iter()
363 .find(|f| f.name() == target_field.name())
364 {
365 validate_field_compatibility(source_field, target_field)?;
366 } else {
367 // Target field is missing from source
368 // If it's non-nullable, we cannot fill it with NULL
369 if !target_field.is_nullable() {
370 return _plan_err!(
371 "Cannot cast struct: target field '{}' is non-nullable but missing from source. \
372 Cannot fill with NULL.",
373 target_field.name()
374 );
375 }
376 }
377 }
378
379 // Extra fields in source are OK - they'll be ignored
380 Ok(())
381}
382
383fn validate_field_compatibility(
384 source_field: &Field,

Calls 5

iterMethod · 0.45
nameMethod · 0.45
is_nullableMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…