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

Function validate_field_compatibility

datafusion/common/src/nested_struct.rs:383–415  ·  view source on GitHub ↗
(
    source_field: &Field,
    target_field: &Field,
)

Source from the content-addressed store, hash-verified

381}
382
383fn validate_field_compatibility(
384 source_field: &Field,
385 target_field: &Field,
386) -> Result<()> {
387 if source_field.data_type() == &DataType::Null {
388 // Validate that target allows nulls before returning early.
389 // It is invalid to cast a NULL source field to a non-nullable target field.
390 if !target_field.is_nullable() {
391 return _plan_err!(
392 "Cannot cast NULL struct field '{}' to non-nullable field '{}'",
393 source_field.name(),
394 target_field.name()
395 );
396 }
397 return Ok(());
398 }
399
400 // Ensure nullability is compatible. It is invalid to cast a nullable
401 // source field to a non-nullable target field as this may discard
402 // null values.
403 if source_field.is_nullable() && !target_field.is_nullable() {
404 return _plan_err!(
405 "Cannot cast nullable struct field '{}' to non-nullable field",
406 target_field.name()
407 );
408 }
409
410 validate_data_type_compatibility(
411 target_field.name(),
412 source_field.data_type(),
413 target_field.data_type(),
414 )
415}
416
417/// Validates that `source_type` can be cast to `target_type`, recursively
418/// handling container types that wrap structs.

Callers 2

Calls 4

data_typeMethod · 0.45
is_nullableMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…