@@ -439,6 +439,15 @@ mod tests {
439439
440440 use super :: * ;
441441
442+ fn test_cast_schema ( ) -> Schema {
443+ Schema :: new ( vec ! [ Field :: new( "a" , DataType :: Int32 , false ) ] )
444+ }
445+
446+ fn lower_cast_expr ( expr : & Expr , schema : & Schema ) -> Result < Arc < dyn PhysicalExpr > > {
447+ let df_schema = DFSchema :: try_from ( schema. clone ( ) ) ?;
448+ create_physical_expr ( expr, & df_schema, & ExecutionProps :: new ( ) )
449+ }
450+
442451 #[ test]
443452 fn test_create_physical_expr_scalar_input_output ( ) -> Result < ( ) > {
444453 let expr = col ( "letter" ) . eq ( lit ( "A" ) ) ;
@@ -466,8 +475,7 @@ mod tests {
466475
467476 #[ test]
468477 fn test_cast_lowering_preserves_target_field_metadata ( ) -> Result < ( ) > {
469- let schema = Schema :: new ( vec ! [ Field :: new( "a" , DataType :: Int32 , false ) ] ) ;
470- let df_schema = DFSchema :: try_from ( schema. clone ( ) ) ?;
478+ let schema = test_cast_schema ( ) ;
471479 let target_field = Arc :: new (
472480 Field :: new ( "cast_target" , DataType :: Int64 , true ) . with_metadata (
473481 [ ( "target_meta" . to_string ( ) , "1" . to_string ( ) ) ] . into ( ) ,
@@ -478,8 +486,7 @@ mod tests {
478486 Arc :: clone ( & target_field) ,
479487 ) ) ;
480488
481- let physical =
482- create_physical_expr ( & cast_expr, & df_schema, & ExecutionProps :: new ( ) ) ?;
489+ let physical = lower_cast_expr ( & cast_expr, & schema) ?;
483490 let cast = physical
484491 . as_any ( )
485492 . downcast_ref :: < expressions:: CastExpr > ( )
@@ -494,29 +501,27 @@ mod tests {
494501
495502 #[ test]
496503 fn test_cast_lowering_preserves_standard_cast_semantics ( ) -> Result < ( ) > {
497- let schema = Schema :: new ( vec ! [ Field :: new( "a" , DataType :: Int32 , false ) ] ) ;
498- let df_schema = DFSchema :: try_from ( schema. clone ( ) ) ?;
504+ let schema = test_cast_schema ( ) ;
499505 let cast_expr = Expr :: Cast ( Cast :: new ( Box :: new ( col ( "a" ) ) , DataType :: Int64 ) ) ;
500506
501- let physical =
502- create_physical_expr ( & cast_expr, & df_schema, & ExecutionProps :: new ( ) ) ?;
507+ let physical = lower_cast_expr ( & cast_expr, & schema) ?;
503508 let cast = physical
504509 . as_any ( )
505510 . downcast_ref :: < expressions:: CastExpr > ( )
506511 . expect ( "planner should lower ordinary CAST to CastExpr" ) ;
512+ let returned_field = physical. return_field ( & schema) ?;
507513
508514 assert_eq ! ( cast. cast_type( ) , & DataType :: Int64 ) ;
509- assert_eq ! ( physical . return_field ( & schema ) ? . name( ) , "a" ) ;
510- assert_eq ! ( physical . return_field ( & schema ) ? . data_type( ) , & DataType :: Int64 ) ;
515+ assert_eq ! ( returned_field . name( ) , "a" ) ;
516+ assert_eq ! ( returned_field . data_type( ) , & DataType :: Int64 ) ;
511517 assert ! ( !physical. nullable( & schema) ?) ;
512518
513519 Ok ( ( ) )
514520 }
515521
516522 #[ test]
517523 fn test_cast_lowering_preserves_same_type_field_semantics ( ) -> Result < ( ) > {
518- let schema = Schema :: new ( vec ! [ Field :: new( "a" , DataType :: Int32 , false ) ] ) ;
519- let df_schema = DFSchema :: try_from ( schema. clone ( ) ) ?;
524+ let schema = test_cast_schema ( ) ;
520525 let target_field = Arc :: new (
521526 Field :: new ( "same_type_cast" , DataType :: Int32 , true ) . with_metadata (
522527 [ ( "target_meta" . to_string ( ) , "same-type" . to_string ( ) ) ] . into ( ) ,
@@ -527,8 +532,7 @@ mod tests {
527532 Arc :: clone ( & target_field) ,
528533 ) ) ;
529534
530- let physical =
531- create_physical_expr ( & cast_expr, & df_schema, & ExecutionProps :: new ( ) ) ?;
535+ let physical = lower_cast_expr ( & cast_expr, & schema) ?;
532536 let cast = physical
533537 . as_any ( )
534538 . downcast_ref :: < expressions:: CastExpr > ( )
0 commit comments