@@ -1012,13 +1012,14 @@ pub struct Cast {
10121012 /// The expression being cast
10131013 pub expr : Box < Expr > ,
10141014 /// The `DataType` the expression will yield
1015- pub data_type : DataType ,
1015+ // pub data_type: DataType,
1016+ pub field : FieldRef ,
10161017}
10171018
10181019impl Cast {
10191020 /// Create a new Cast expression
1020- pub fn new ( expr : Box < Expr > , data_type : DataType ) -> Self {
1021- Self { expr, data_type }
1021+ pub fn new ( expr : Box < Expr > , field : FieldRef ) -> Self {
1022+ Self { expr, field }
10221023 }
10231024}
10241025
@@ -1028,13 +1029,13 @@ pub struct TryCast {
10281029 /// The expression being cast
10291030 pub expr : Box < Expr > ,
10301031 /// The `DataType` the expression will yield
1031- pub data_type : DataType ,
1032+ pub field : FieldRef ,
10321033}
10331034
10341035impl TryCast {
10351036 /// Create a new TryCast expression
1036- pub fn new ( expr : Box < Expr > , data_type : DataType ) -> Self {
1037- Self { expr, data_type }
1037+ pub fn new ( expr : Box < Expr > , field : FieldRef ) -> Self {
1038+ Self { expr, field }
10381039 }
10391040}
10401041
@@ -2460,23 +2461,26 @@ impl NormalizeEq for Expr {
24602461 (
24612462 Expr :: Cast ( Cast {
24622463 expr : self_expr,
2463- data_type : self_data_type ,
2464+ field : self_field ,
24642465 } ) ,
24652466 Expr :: Cast ( Cast {
24662467 expr : other_expr,
2467- data_type : other_data_type ,
2468+ field : other_field ,
24682469 } ) ,
24692470 )
24702471 | (
24712472 Expr :: TryCast ( TryCast {
24722473 expr : self_expr,
2473- data_type : self_data_type ,
2474+ field : self_field ,
24742475 } ) ,
24752476 Expr :: TryCast ( TryCast {
24762477 expr : other_expr,
2477- data_type : other_data_type ,
2478+ field : other_field ,
24782479 } ) ,
2479- ) => self_data_type == other_data_type && self_expr. normalize_eq ( other_expr) ,
2480+ ) => {
2481+ self_field. data_type ( ) == other_field. data_type ( )
2482+ && self_expr. normalize_eq ( other_expr)
2483+ }
24802484 (
24812485 Expr :: ScalarFunction ( ScalarFunction {
24822486 func : self_func,
@@ -2792,15 +2796,9 @@ impl HashNode for Expr {
27922796 when_then_expr : _when_then_expr,
27932797 else_expr : _else_expr,
27942798 } ) => { }
2795- Expr :: Cast ( Cast {
2796- expr : _expr,
2797- data_type,
2798- } )
2799- | Expr :: TryCast ( TryCast {
2800- expr : _expr,
2801- data_type,
2802- } ) => {
2803- data_type. hash ( state) ;
2799+ Expr :: Cast ( Cast { expr : _expr, field } )
2800+ | Expr :: TryCast ( TryCast { expr : _expr, field } ) => {
2801+ field. data_type ( ) . hash ( state) ;
28042802 }
28052803 Expr :: ScalarFunction ( ScalarFunction { func, args : _args } ) => {
28062804 func. hash ( state) ;
@@ -3487,11 +3485,11 @@ impl Display for Expr {
34873485 }
34883486 write ! ( f, "END" )
34893487 }
3490- Expr :: Cast ( Cast { expr, data_type } ) => {
3491- write ! ( f, "CAST({expr} AS {data_type })" )
3488+ Expr :: Cast ( Cast { expr, field } ) => {
3489+ write ! ( f, "CAST({expr} AS {})" , field . data_type ( ) )
34923490 }
3493- Expr :: TryCast ( TryCast { expr, data_type } ) => {
3494- write ! ( f, "TRY_CAST({expr} AS {data_type })" )
3491+ Expr :: TryCast ( TryCast { expr, field } ) => {
3492+ write ! ( f, "TRY_CAST({expr} AS {})" , field . data_type ( ) )
34953493 }
34963494 Expr :: Not ( expr) => write ! ( f, "NOT {expr}" ) ,
34973495 Expr :: Negative ( expr) => write ! ( f, "(- {expr})" ) ,
@@ -3844,7 +3842,7 @@ mod test {
38443842 fn format_cast ( ) -> Result < ( ) > {
38453843 let expr = Expr :: Cast ( Cast {
38463844 expr : Box :: new ( Expr :: Literal ( ScalarValue :: Float32 ( Some ( 1.23 ) ) , None ) ) ,
3847- data_type : DataType :: Utf8 ,
3845+ field : Arc :: new ( Field :: new ( "cast" , DataType :: Utf8 , false ) ) ,
38483846 } ) ;
38493847 let expected_canonical = "CAST(Float32(1.23) AS Utf8)" ;
38503848 assert_eq ! ( expected_canonical, format!( "{expr}" ) ) ;
@@ -3871,7 +3869,10 @@ mod test {
38713869 fn test_collect_expr ( ) -> Result < ( ) > {
38723870 // single column
38733871 {
3874- let expr = & Expr :: Cast ( Cast :: new ( Box :: new ( col ( "a" ) ) , DataType :: Float64 ) ) ;
3872+ let expr = & Expr :: Cast ( Cast :: new (
3873+ Box :: new ( col ( "a" ) ) ,
3874+ Arc :: new ( Field :: new ( "cast" , DataType :: Float64 , false ) ) ,
3875+ ) ) ;
38753876 let columns = expr. column_refs ( ) ;
38763877 assert_eq ! ( 1 , columns. len( ) ) ;
38773878 assert ! ( columns. contains( & Column :: from_name( "a" ) ) ) ;
0 commit comments