File tree 5 files changed +34
-16
lines changed
5 files changed +34
-16
lines changed Original file line number Diff line number Diff line change @@ -331,6 +331,27 @@ impl DFSchema {
331
331
}
332
332
}
333
333
334
+ /// Find if the field exists with the given name
335
+ pub fn has_column_with_unqualified_name ( & self , name : & str ) -> bool {
336
+ self . fields ( ) . iter ( ) . any ( |field| field. name ( ) == name)
337
+ }
338
+
339
+ /// Find if the field exists with the given qualified name
340
+ pub fn has_column_with_qualified_name ( & self , qualifier : & str , name : & str ) -> bool {
341
+ self . fields ( ) . iter ( ) . any ( |field| {
342
+ field. qualifier ( ) . map ( |q| q. eq ( qualifier) ) . unwrap_or ( false )
343
+ && field. name ( ) == name
344
+ } )
345
+ }
346
+
347
+ /// Find if the field exists with the given qualified column
348
+ pub fn has_column ( & self , column : & Column ) -> bool {
349
+ match & column. relation {
350
+ Some ( r) => self . has_column_with_qualified_name ( r, & column. name ) ,
351
+ None => self . has_column_with_unqualified_name ( & column. name ) ,
352
+ }
353
+ }
354
+
334
355
/// Check to see if unqualified field names matches field names in Arrow schema
335
356
pub fn matches_arrow_schema ( & self , arrow_schema : & Schema ) -> bool {
336
357
self . fields
Original file line number Diff line number Diff line change @@ -377,10 +377,7 @@ impl LogicalPlanBuilder {
377
377
input,
378
378
mut expr,
379
379
schema : _,
380
- } ) if missing_cols
381
- . iter ( )
382
- . all ( |c| input. schema ( ) . field_from_column ( c) . is_ok ( ) ) =>
383
- {
380
+ } ) if missing_cols. iter ( ) . all ( |c| input. schema ( ) . has_column ( c) ) => {
384
381
let mut missing_exprs = missing_cols
385
382
. iter ( )
386
383
. map ( |c| normalize_col ( Expr :: Column ( c. clone ( ) ) , & input) )
@@ -723,13 +720,13 @@ impl LogicalPlanBuilder {
723
720
let mut join_on: Vec < ( Expr , Expr ) > = vec ! [ ] ;
724
721
let mut filters: Option < Expr > = None ;
725
722
for ( l, r) in & on {
726
- if self . plan . schema ( ) . field_from_column ( l ) . is_ok ( )
727
- && right. schema ( ) . field_from_column ( r ) . is_ok ( )
723
+ if self . plan . schema ( ) . has_column ( l )
724
+ && right. schema ( ) . has_column ( r )
728
725
&& can_hash ( self . plan . schema ( ) . field_from_column ( l) ?. data_type ( ) )
729
726
{
730
727
join_on. push ( ( Expr :: Column ( l. clone ( ) ) , Expr :: Column ( r. clone ( ) ) ) ) ;
731
- } else if self . plan . schema ( ) . field_from_column ( r ) . is_ok ( )
732
- && right. schema ( ) . field_from_column ( l ) . is_ok ( )
728
+ } else if self . plan . schema ( ) . has_column ( l )
729
+ && right. schema ( ) . has_column ( r )
733
730
&& can_hash ( self . plan . schema ( ) . field_from_column ( r) ?. data_type ( ) )
734
731
{
735
732
join_on. push ( ( Expr :: Column ( r. clone ( ) ) , Expr :: Column ( l. clone ( ) ) ) ) ;
Original file line number Diff line number Diff line change @@ -172,7 +172,7 @@ fn optimize_exists(
172
172
let using_cols: Vec < Column > = expr
173
173
. to_columns ( ) ?
174
174
. into_iter ( )
175
- . filter ( |col| input_schema. field_from_column ( col) . is_ok ( ) )
175
+ . filter ( |col| input_schema. has_column ( col) )
176
176
. collect :: < _ > ( ) ;
177
177
178
178
cols. extend ( using_cols) ;
Original file line number Diff line number Diff line change @@ -166,7 +166,7 @@ fn optimize_where_in(
166
166
let using_cols: Vec < Column > = expr
167
167
. to_columns ( ) ?
168
168
. into_iter ( )
169
- . filter ( |col| input_schema. field_from_column ( col) . is_ok ( ) )
169
+ . filter ( |col| input_schema. has_column ( col) )
170
170
. collect :: < _ > ( ) ;
171
171
172
172
cols. extend ( using_cols) ;
Original file line number Diff line number Diff line change @@ -84,10 +84,10 @@ impl OptimizerRule for EliminateOuterJoin {
84
84
let mut left_non_nullable = false ;
85
85
let mut right_non_nullable = false ;
86
86
for col in non_nullable_cols. iter ( ) {
87
- if join. left . schema ( ) . field_from_column ( col) . is_ok ( ) {
87
+ if join. left . schema ( ) . has_column ( col) {
88
88
left_non_nullable = true ;
89
89
}
90
- if join. right . schema ( ) . field_from_column ( col) . is_ok ( ) {
90
+ if join. right . schema ( ) . has_column ( col) {
91
91
right_non_nullable = true ;
92
92
}
93
93
}
@@ -251,10 +251,10 @@ fn extract_non_nullable_columns(
251
251
{
252
252
for left_col in & left_non_nullable_cols {
253
253
for right_col in & right_non_nullable_cols {
254
- if ( left_schema. field_from_column ( left_col) . is_ok ( )
255
- && left_schema. field_from_column ( right_col) . is_ok ( ) )
256
- || ( right_schema. field_from_column ( left_col) . is_ok ( )
257
- && right_schema. field_from_column ( right_col) . is_ok ( ) )
254
+ if ( left_schema. has_column ( left_col)
255
+ && left_schema. has_column ( right_col) )
256
+ || ( right_schema. has_column ( left_col)
257
+ && right_schema. has_column ( right_col) )
258
258
{
259
259
non_nullable_cols. push ( left_col. clone ( ) ) ;
260
260
break ;
You can’t perform that action at this time.
0 commit comments