@@ -324,45 +324,40 @@ pub fn cast_with_options(
324324 cast_type : DataType ,
325325 cast_options : Option < CastOptions < ' static > > ,
326326) -> Result < Arc < dyn PhysicalExpr > > {
327- // borrow expr and temporary field reference; the helper clones as needed
328327 cast_with_target_field_and_options (
329- & expr,
328+ expr,
330329 input_schema,
331- & cast_type. into_nullable_field_ref ( ) ,
330+ cast_type. into_nullable_field_ref ( ) ,
332331 cast_options,
333332 )
334333}
335334
336335/// Return a [`PhysicalExpr`] representing `expr` casted to `target_field`,
337336/// preserving the field metadata in the resulting expression.
338337pub ( crate ) fn cast_with_target_field_and_options (
339- expr : & Arc < dyn PhysicalExpr > ,
338+ expr : Arc < dyn PhysicalExpr > ,
340339 input_schema : & Schema ,
341- target_field : & FieldRef ,
340+ target_field : FieldRef ,
342341 cast_options : Option < CastOptions < ' static > > ,
343342) -> Result < Arc < dyn PhysicalExpr > > {
344- // borrow inputs to satisfy clippy
345343 let expr_type = expr. data_type ( input_schema) ?;
346- let cast_type = target_field. data_type ( ) ;
347- let candidate = CastExpr :: new_with_target_field (
348- Arc :: clone ( expr) ,
349- Arc :: clone ( target_field) ,
350- cast_options. clone ( ) ,
351- ) ;
352-
353- if expr_type == * cast_type
344+ let cast_type = target_field. data_type ( ) . clone ( ) ;
345+ let candidate =
346+ CastExpr :: new_with_target_field ( Arc :: clone ( & expr) , target_field, cast_options) ;
347+
348+ if expr_type == cast_type
354349 && candidate. preserves_child_field_semantics ( input_schema) ?
355350 {
356- return Ok ( Arc :: clone ( expr) ) ;
351+ return Ok ( expr) ;
357352 }
358353
359- let is_valid_cast = match ( & expr_type, cast_type) {
354+ let is_valid_cast = match ( & expr_type, & cast_type) {
360355 // Allow struct-to-struct casts that pass name-based compatibility validation.
361356 // This validation is applied at planning time (now) to fail fast, rather than
362357 // deferring errors to execution time. The name-based casting logic will be
363358 // executed at runtime via ColumnarValue::cast_to.
364- ( Struct ( _) , Struct ( _) ) => can_cast_struct_types ( & expr_type, cast_type) ,
365- _ => can_cast_types ( & expr_type, cast_type) ,
359+ ( Struct ( _) , Struct ( _) ) => can_cast_struct_types ( & expr_type, & cast_type) ,
360+ _ => can_cast_types ( & expr_type, & cast_type) ,
366361 } ;
367362
368363 if !is_valid_cast {
@@ -940,7 +935,7 @@ mod tests {
940935 HashMap :: from ( [ ( "target_meta" . to_string ( ) , "1" . to_string ( ) ) ] ) ,
941936 ) ) ;
942937 let expr =
943- cast_with_target_field_and_options ( & a_col, & schema, & logical_field, None ) ?;
938+ cast_with_target_field_and_options ( a_col, & schema, logical_field, None ) ?;
944939
945940 let cast_expr = expr
946941 . as_any ( )
@@ -964,7 +959,7 @@ mod tests {
964959 let a_col = col ( "a" , & schema) ?;
965960 let target_field = Int32 . into_nullable_field_ref ( ) ;
966961 let expr =
967- cast_with_target_field_and_options ( & a_col, & schema, & target_field, None ) ?;
962+ cast_with_target_field_and_options ( a_col, & schema, target_field, None ) ?;
968963
969964 assert ! ( expr. as_any( ) . downcast_ref:: <Column >( ) . is_some( ) ) ;
970965 assert ! ( expr. as_any( ) . downcast_ref:: <CastExpr >( ) . is_none( ) ) ;
0 commit comments