@@ -12,7 +12,7 @@ pub struct BoundBinaryOp {
12
12
pub op : BinaryOperator ,
13
13
pub left_expr : Box < BoundExpr > ,
14
14
pub right_expr : Box < BoundExpr > ,
15
- pub return_type : Option < DataType > ,
15
+ pub return_type : DataType ,
16
16
}
17
17
18
18
impl std:: fmt:: Debug for BoundBinaryOp {
@@ -45,60 +45,48 @@ impl Binder {
45
45
let mut right_bound_expr = self . bind_expr ( right) ?;
46
46
47
47
// Implicit type cast
48
- let left_data_type_kind = match (
49
- left_bound_expr. return_type ( ) ,
50
- right_bound_expr. return_type ( ) ,
51
- ) {
52
- ( Some ( left_data_type) , Some ( right_data_type) ) => {
53
- let left_physical_kind = left_data_type. kind ( ) ;
54
- let right_physical_kind = right_data_type. kind ( ) ;
55
- let mut return_type_tmp = left_data_type. kind ( ) ;
56
- // Check if implicit type conversion is needed
57
- if left_physical_kind != right_physical_kind {
58
- // Insert type cast expr
59
- match ( left_physical_kind, right_physical_kind) {
60
- ( Float64 | Decimal ( _, _) , Int32 | Int64 )
61
- | ( Int64 , Int32 )
62
- | ( Date , String )
63
- | ( Decimal ( _, _) , Float64 ) => {
64
- right_bound_expr = BoundExpr :: TypeCast ( BoundTypeCast {
65
- expr : Box :: new ( right_bound_expr) ,
66
- ty : left_data_type. kind ( ) ,
67
- } ) ;
68
- }
69
- ( Int32 | Int64 , Float64 | Decimal ( _, _) )
70
- | ( Int32 , Int64 )
71
- | ( String , Date )
72
- | ( Float64 , Decimal ( _, _) ) => {
73
- left_bound_expr = BoundExpr :: TypeCast ( BoundTypeCast {
74
- expr : Box :: new ( left_bound_expr) ,
75
- ty : right_data_type. kind ( ) ,
76
- } ) ;
77
- return_type_tmp = right_data_type. kind ( ) ;
78
- }
79
- ( Date , Interval ) => { }
80
- ( left_kind, right_kind) => todo ! (
81
- "Support implicit conversion of {:?} and {:?}" ,
82
- left_kind,
83
- right_kind
84
- ) ,
48
+ let left_data_type_kind = {
49
+ let left_kind = left_bound_expr. return_type ( ) . kind ( ) ;
50
+ let right_kind = right_bound_expr. return_type ( ) . kind ( ) ;
51
+ let mut return_type_tmp = left_kind;
52
+ // Check if implicit type conversion is needed
53
+ if left_kind != right_kind {
54
+ // Insert type cast expr
55
+ match ( left_kind, right_kind) {
56
+ ( Float64 | Decimal ( _, _) , Int32 | Int64 )
57
+ | ( Int64 , Int32 )
58
+ | ( Date , String )
59
+ | ( Decimal ( _, _) , Float64 ) => {
60
+ right_bound_expr = BoundExpr :: TypeCast ( BoundTypeCast {
61
+ expr : Box :: new ( right_bound_expr) ,
62
+ ty : left_kind,
63
+ } ) ;
85
64
}
65
+ ( Int32 | Int64 , Float64 | Decimal ( _, _) )
66
+ | ( Int32 , Int64 )
67
+ | ( String , Date )
68
+ | ( Float64 , Decimal ( _, _) ) => {
69
+ left_bound_expr = BoundExpr :: TypeCast ( BoundTypeCast {
70
+ expr : Box :: new ( left_bound_expr) ,
71
+ ty : right_kind,
72
+ } ) ;
73
+ return_type_tmp = right_kind;
74
+ }
75
+ ( Date , Interval ) => { }
76
+ _ => todo ! (
77
+ "Support implicit conversion of {:?} and {:?}" ,
78
+ left_kind,
79
+ right_kind
80
+ ) ,
86
81
}
87
- Some ( return_type_tmp. nullable ( ) )
88
- }
89
- ( None , None ) => None ,
90
- ( left, right) => {
91
- return Err ( BindError :: BinaryOpTypeMismatch (
92
- format ! ( "{:?}" , left) ,
93
- format ! ( "{:?}" , right) ,
94
- ) )
95
82
}
83
+ return_type_tmp. nullable ( )
96
84
} ;
97
85
98
86
let return_type = match op {
99
87
Op :: Plus | Op :: Minus | Op :: Multiply | Op :: Divide | Op :: Modulo => left_data_type_kind,
100
88
Op :: Gt | Op :: GtEq | Op :: Lt | Op :: LtEq | Op :: Eq | Op :: NotEq | Op :: And | Op :: Or => {
101
- Some ( DataTypeKind :: Bool . nullable ( ) )
89
+ DataTypeKind :: Bool . nullable ( )
102
90
}
103
91
_ => todo ! ( "Support more binary operators" ) ,
104
92
} ;
0 commit comments