Skip to content

Commit 59d3eae

Browse files
committed
Refactor cast-target-field path in cast.rs
Eliminate unnecessary DataType clone and simplify the cast-validity branches into a single boolean expression. Ensure that the behavior and public surface remain unchanged while improving code efficiency.
1 parent a7a7738 commit 59d3eae

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

  • datafusion/physical-expr/src/expressions

datafusion/physical-expr/src/expressions/cast.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,18 +337,16 @@ pub(crate) fn cast_with_target_field_and_options(
337337
cast_options: Option<CastOptions<'static>>,
338338
) -> Result<Arc<dyn PhysicalExpr>> {
339339
let expr_type = expr.data_type(input_schema)?;
340-
let cast_type = target_field.data_type().clone();
341-
let is_valid_cast = if expr_type == cast_type {
342-
true
343-
} else if matches!((&expr_type, &cast_type), (Struct(_), Struct(_))) {
340+
let cast_type = target_field.data_type();
341+
let is_valid_cast = expr_type == *cast_type
342+
|| match (&expr_type, cast_type) {
344343
// Allow struct-to-struct casts that pass name-based compatibility validation.
345344
// This validation is applied at planning time (now) to fail fast, rather than
346345
// deferring errors to execution time. The name-based casting logic will be
347346
// executed at runtime via ColumnarValue::cast_to.
348-
can_cast_struct_types(&expr_type, &cast_type)
349-
} else {
350-
can_cast_types(&expr_type, &cast_type)
351-
};
347+
(Struct(_), Struct(_)) => can_cast_struct_types(&expr_type, cast_type),
348+
_ => can_cast_types(&expr_type, cast_type),
349+
};
352350

353351
if !is_valid_cast {
354352
not_impl_err!("Unsupported CAST from {expr_type} to {cast_type}")

0 commit comments

Comments
 (0)