(
source_field: &Field,
target_field: &Field,
)
| 381 | } |
| 382 | |
| 383 | fn 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. |
no test coverage detected
searching dependent graphs…