@@ -23,7 +23,6 @@ use crate::execution::dql::join::joins_nullable;
23
23
use crate :: expression:: agg:: AggKind ;
24
24
use crate :: expression:: simplify:: ConstantCalculator ;
25
25
use crate :: expression:: visitor_mut:: VisitorMut ;
26
- use crate :: expression:: ScalarExpression :: Constant ;
27
26
use crate :: expression:: { AliasType , BinaryOperator } ;
28
27
use crate :: planner:: operator:: aggregate:: AggregateOperator ;
29
28
use crate :: planner:: operator:: except:: ExceptOperator ;
@@ -103,7 +102,7 @@ impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'
103
102
}
104
103
plan
105
104
} ;
106
- let mut select_list = self . normalize_select_item ( & select. projection , & plan) ?;
105
+ let mut select_list = self . normalize_select_item ( & select. projection , & mut plan) ?;
107
106
108
107
if let Some ( predicate) = & select. selection {
109
108
plan = self . bind_where ( plan, predicate) ?;
@@ -159,6 +158,7 @@ impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'
159
158
Ok ( plan)
160
159
}
161
160
161
+ /// FIXME: temp values need to register BindContext.bind_table
162
162
fn bind_temp_values ( & mut self , expr_rows : & [ Vec < Expr > ] ) -> Result < LogicalPlan , DatabaseError > {
163
163
let values_len = expr_rows[ 0 ] . len ( ) ;
164
164
@@ -176,7 +176,7 @@ impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'
176
176
let mut expression = self . bind_expr ( expr) ?;
177
177
ConstantCalculator . visit ( & mut expression) ?;
178
178
179
- if let Constant ( value) = expression {
179
+ if let ScalarExpression :: Constant ( value) = expression {
180
180
let value_type = value. logical_type ( ) ;
181
181
182
182
inferred_types[ col_index] = match & inferred_types[ col_index] {
@@ -230,19 +230,19 @@ impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'
230
230
LogicalType :: max_logical_type ( left_schema. datatype ( ) , right_schema. datatype ( ) ) ?;
231
231
if & cast_type != left_schema. datatype ( ) {
232
232
left_cast. push ( ScalarExpression :: TypeCast {
233
- expr : Box :: new ( ScalarExpression :: ColumnRef ( left_schema. clone ( ) ) ) ,
233
+ expr : Box :: new ( ScalarExpression :: column_expr ( left_schema. clone ( ) ) ) ,
234
234
ty : cast_type. clone ( ) ,
235
235
} ) ;
236
236
} else {
237
- left_cast. push ( ScalarExpression :: ColumnRef ( left_schema. clone ( ) ) ) ;
237
+ left_cast. push ( ScalarExpression :: column_expr ( left_schema. clone ( ) ) ) ;
238
238
}
239
239
if & cast_type != right_schema. datatype ( ) {
240
240
right_cast. push ( ScalarExpression :: TypeCast {
241
- expr : Box :: new ( ScalarExpression :: ColumnRef ( right_schema. clone ( ) ) ) ,
241
+ expr : Box :: new ( ScalarExpression :: column_expr ( right_schema. clone ( ) ) ) ,
242
242
ty : cast_type. clone ( ) ,
243
243
} ) ;
244
244
} else {
245
- right_cast. push ( ScalarExpression :: ColumnRef ( right_schema. clone ( ) ) ) ;
245
+ right_cast. push ( ScalarExpression :: column_expr ( right_schema. clone ( ) ) ) ;
246
246
}
247
247
}
248
248
@@ -312,7 +312,7 @@ impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'
312
312
let distinct_exprs = left_schema
313
313
. iter ( )
314
314
. cloned ( )
315
- . map ( ScalarExpression :: ColumnRef )
315
+ . map ( ScalarExpression :: column_expr )
316
316
. collect_vec ( ) ;
317
317
318
318
let union_op = Operator :: Union ( UnionOperator {
@@ -344,7 +344,7 @@ impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'
344
344
let distinct_exprs = left_schema
345
345
. iter ( )
346
346
. cloned ( )
347
- . map ( ScalarExpression :: ColumnRef )
347
+ . map ( ScalarExpression :: column_expr )
348
348
. collect_vec ( ) ;
349
349
350
350
let except_op = Operator :: Except ( ExceptOperator {
@@ -492,8 +492,8 @@ impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'
492
492
) ;
493
493
494
494
let alias_column_expr = ScalarExpression :: Alias {
495
- expr : Box :: new ( ScalarExpression :: ColumnRef ( column) ) ,
496
- alias : AliasType :: Expr ( Box :: new ( ScalarExpression :: ColumnRef ( ColumnRef :: from (
495
+ expr : Box :: new ( ScalarExpression :: column_expr ( column) ) ,
496
+ alias : AliasType :: Expr ( Box :: new ( ScalarExpression :: column_expr ( ColumnRef :: from (
497
497
alias_column,
498
498
) ) ) ) ,
499
499
} ;
@@ -548,7 +548,7 @@ impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'
548
548
fn normalize_select_item (
549
549
& mut self ,
550
550
items : & [ SelectItem ] ,
551
- plan : & LogicalPlan ,
551
+ plan : & mut LogicalPlan ,
552
552
) -> Result < Vec < ScalarExpression > , DatabaseError > {
553
553
let mut select_items = vec ! [ ] ;
554
554
@@ -624,8 +624,8 @@ impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'
624
624
. expr_aliases
625
625
. iter ( )
626
626
. filter ( |( _, expr) | {
627
- if let ScalarExpression :: ColumnRef ( col ) = expr. unpack_alias_ref ( ) {
628
- if fn_not_on_using ( col ) {
627
+ if let ScalarExpression :: ColumnRef { column , .. } = expr. unpack_alias_ref ( ) {
628
+ if fn_not_on_using ( column ) {
629
629
exprs. push ( ScalarExpression :: clone ( expr) ) ;
630
630
return true ;
631
631
}
@@ -651,7 +651,7 @@ impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'
651
651
if !fn_not_on_using ( column) {
652
652
continue ;
653
653
}
654
- exprs. push ( ScalarExpression :: ColumnRef ( column. clone ( ) ) ) ;
654
+ exprs. push ( ScalarExpression :: column_expr ( column. clone ( ) ) ) ;
655
655
}
656
656
Ok ( ( ) )
657
657
}
@@ -751,7 +751,7 @@ impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'
751
751
} else {
752
752
BinaryOperator :: Eq
753
753
} ,
754
- left_expr : Box :: new ( ScalarExpression :: ColumnRef (
754
+ left_expr : Box :: new ( ScalarExpression :: column_expr (
755
755
agg. output_schema ( ) [ 0 ] . clone ( ) ,
756
756
) ) ,
757
757
right_expr : Box :: new ( ScalarExpression :: Constant ( DataValue :: Int32 (
@@ -928,7 +928,7 @@ impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'
928
928
}
929
929
930
930
for column in select_items {
931
- if let ScalarExpression :: ColumnRef ( col ) = column {
931
+ if let ScalarExpression :: ColumnRef { column , .. } = column {
932
932
let _ = table_force_nullable
933
933
. iter ( )
934
934
. find ( |( table_name, source, _) | {
@@ -937,11 +937,11 @@ impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'
937
937
. entry ( ( * table_name) . clone ( ) )
938
938
. or_default ( ) ;
939
939
940
- source. column ( col . name ( ) , schema_buf) . is_some ( )
940
+ source. column ( column . name ( ) , schema_buf) . is_some ( )
941
941
} )
942
942
. map ( |( _, _, nullable) | {
943
- if let Some ( new_column) = col . nullable_for_join ( * nullable) {
944
- * col = new_column;
943
+ if let Some ( new_column) = column . nullable_for_join ( * nullable) {
944
+ * column = new_column;
945
945
}
946
946
} ) ;
947
947
}
@@ -1003,8 +1003,8 @@ impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'
1003
1003
} ;
1004
1004
self . context . add_using ( join_type, left_column, right_column) ;
1005
1005
on_keys. push ( (
1006
- ScalarExpression :: ColumnRef ( left_column. clone ( ) ) ,
1007
- ScalarExpression :: ColumnRef ( right_column. clone ( ) ) ,
1006
+ ScalarExpression :: column_expr ( left_column. clone ( ) ) ,
1007
+ ScalarExpression :: column_expr ( right_column. clone ( ) ) ,
1008
1008
) ) ;
1009
1009
}
1010
1010
Ok ( JoinCondition :: On {
@@ -1024,8 +1024,8 @@ impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'
1024
1024
left_schema. iter ( ) . find ( |column| column. name ( ) == * name) ,
1025
1025
right_schema. iter ( ) . find ( |column| column. name ( ) == * name) ,
1026
1026
) {
1027
- let left_expr = ScalarExpression :: ColumnRef ( left_column. clone ( ) ) ;
1028
- let right_expr = ScalarExpression :: ColumnRef ( right_column. clone ( ) ) ;
1027
+ let left_expr = ScalarExpression :: column_expr ( left_column. clone ( ) ) ;
1028
+ let right_expr = ScalarExpression :: column_expr ( right_column. clone ( ) ) ;
1029
1029
1030
1030
self . context . add_using ( join_type, left_column, right_column) ;
1031
1031
on_keys. push ( ( left_expr, right_expr) ) ;
@@ -1077,7 +1077,10 @@ impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'
1077
1077
BinaryOperator :: Eq => {
1078
1078
match ( left_expr. unpack_alias_ref ( ) , right_expr. unpack_alias_ref ( ) ) {
1079
1079
// example: foo = bar
1080
- ( ScalarExpression :: ColumnRef ( l) , ScalarExpression :: ColumnRef ( r) ) => {
1080
+ (
1081
+ ScalarExpression :: ColumnRef { column : l, .. } ,
1082
+ ScalarExpression :: ColumnRef { column : r, .. } ,
1083
+ ) => {
1081
1084
// reorder left and right joins keys to pattern: (left, right)
1082
1085
if fn_contains ( left_schema, l. summary ( ) )
1083
1086
&& fn_contains ( right_schema, r. summary ( ) )
@@ -1099,8 +1102,8 @@ impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'
1099
1102
} ) ;
1100
1103
}
1101
1104
}
1102
- ( ScalarExpression :: ColumnRef ( column) , _)
1103
- | ( _, ScalarExpression :: ColumnRef ( column) ) => {
1105
+ ( ScalarExpression :: ColumnRef { column, .. } , _)
1106
+ | ( _, ScalarExpression :: ColumnRef { column, .. } ) => {
1104
1107
if fn_or_contains ( left_schema, right_schema, column. summary ( ) ) {
1105
1108
accum_filter. push ( ScalarExpression :: Binary {
1106
1109
left_expr,
0 commit comments