@@ -456,13 +456,10 @@ impl ExprSchemable for Expr {
456456 Expr :: ScalarVariable ( ty, _) => {
457457 Ok ( Arc :: new ( Field :: new ( & schema_name, ty. clone ( ) , true ) ) )
458458 }
459- Expr :: Literal ( l, metadata) => {
460- let mut field = Field :: new ( & schema_name, l. data_type ( ) , l. is_null ( ) ) ;
461- if let Some ( metadata) = metadata {
462- field = metadata. add_to_field ( field) ;
463- }
464- Ok ( Arc :: new ( field) )
465- }
459+ Expr :: Literal ( l, metadata) => Ok ( Arc :: new (
460+ Field :: new ( & schema_name, l. data_type ( ) , l. is_null ( ) )
461+ . with_field_metadata_opt ( metadata. as_ref ( ) ) ,
462+ ) ) ,
466463 Expr :: IsNull ( _)
467464 | Expr :: IsNotNull ( _)
468465 | Expr :: IsTrue ( _)
@@ -564,8 +561,7 @@ impl ExprSchemable for Expr {
564561 let new_fields = fields
565562 . into_iter ( )
566563 . zip ( new_data_types)
567- . map ( |( f, d) | f. as_ref ( ) . clone ( ) . with_data_type ( d) )
568- . map ( Arc :: new)
564+ . map ( |( f, d) | f. retyped ( d) )
569565 . collect :: < Vec < FieldRef > > ( ) ;
570566
571567 let arguments = args
@@ -585,12 +581,11 @@ impl ExprSchemable for Expr {
585581 // _ => Ok((self.get_type(schema)?, self.nullable(schema)?)),
586582 Expr :: Cast ( Cast { expr, data_type } ) => expr
587583 . to_field ( schema)
588- . map ( |( _, f) | f. as_ref ( ) . clone ( ) . with_data_type ( data_type. clone ( ) ) )
589- . map ( Arc :: new) ,
584+ . map ( |( _, f) | f. retyped ( data_type. clone ( ) ) ) ,
590585 Expr :: Placeholder ( Placeholder {
591586 id : _,
592587 field : Some ( field) ,
593- } ) => Ok ( field . as_ref ( ) . clone ( ) . with_name ( & schema_name) . into ( ) ) ,
588+ } ) => Ok ( Arc :: clone ( field ) . renamed ( & schema_name) ) ,
594589 Expr :: Like ( _)
595590 | Expr :: SimilarTo ( _)
596591 | Expr :: Not ( _)
0 commit comments