@@ -40,7 +40,6 @@ use crate::logical_plan::{
4040 columnize_expr, normalize_col, normalize_cols, Column , DFField , DFSchema ,
4141 DFSchemaRef , Partitioning ,
4242} ;
43- use std:: collections:: HashSet ;
4443
4544/// Default table name for unnamed table
4645pub const UNNAMED_TABLE : & str = "?table?" ;
@@ -213,7 +212,6 @@ impl LogicalPlanBuilder {
213212 /// * An invalid expression is used (e.g. a `sort` expression)
214213 pub fn project ( & self , expr : impl IntoIterator < Item = Expr > ) -> Result < Self > {
215214 let input_schema = self . plan . schema ( ) ;
216- let all_schemas = self . plan . all_schemas ( ) ;
217215 let mut projected_expr = vec ! [ ] ;
218216 for e in expr {
219217 match e {
@@ -223,10 +221,8 @@ impl LogicalPlanBuilder {
223221 . push ( Expr :: Column ( input_schema. field ( i) . qualified_column ( ) ) )
224222 } ) ;
225223 }
226- _ => projected_expr. push ( columnize_expr (
227- normalize_col ( e, & all_schemas) ?,
228- input_schema,
229- ) ) ,
224+ _ => projected_expr
225+ . push ( columnize_expr ( normalize_col ( e, & self . plan ) ?, input_schema) ) ,
230226 }
231227 }
232228
@@ -243,7 +239,7 @@ impl LogicalPlanBuilder {
243239
244240 /// Apply a filter
245241 pub fn filter ( & self , expr : Expr ) -> Result < Self > {
246- let expr = normalize_col ( expr, & self . plan . all_schemas ( ) ) ?;
242+ let expr = normalize_col ( expr, & self . plan ) ?;
247243 Ok ( Self :: from ( LogicalPlan :: Filter {
248244 predicate : expr,
249245 input : Arc :: new ( self . plan . clone ( ) ) ,
@@ -260,9 +256,8 @@ impl LogicalPlanBuilder {
260256
261257 /// Apply a sort
262258 pub fn sort ( & self , exprs : impl IntoIterator < Item = Expr > ) -> Result < Self > {
263- let schemas = self . plan . all_schemas ( ) ;
264259 Ok ( Self :: from ( LogicalPlan :: Sort {
265- expr : normalize_cols ( exprs, & schemas ) ?,
260+ expr : normalize_cols ( exprs, & self . plan ) ?,
266261 input : Arc :: new ( self . plan . clone ( ) ) ,
267262 } ) )
268263 }
@@ -288,20 +283,15 @@ impl LogicalPlanBuilder {
288283
289284 let left_keys: Vec < Column > = left_keys
290285 . into_iter ( )
291- . map ( |c| c. into ( ) . normalize ( & self . plan . all_schemas ( ) ) )
286+ . map ( |c| c. into ( ) . normalize ( & self . plan ) )
292287 . collect :: < Result < _ > > ( ) ?;
293288 let right_keys: Vec < Column > = right_keys
294289 . into_iter ( )
295- . map ( |c| c. into ( ) . normalize ( & right. all_schemas ( ) ) )
290+ . map ( |c| c. into ( ) . normalize ( right) )
296291 . collect :: < Result < _ > > ( ) ?;
297292 let on: Vec < ( _ , _ ) > = left_keys. into_iter ( ) . zip ( right_keys. into_iter ( ) ) . collect ( ) ;
298- let join_schema = build_join_schema (
299- self . plan . schema ( ) ,
300- right. schema ( ) ,
301- & on,
302- & join_type,
303- & JoinConstraint :: On ,
304- ) ?;
293+ let join_schema =
294+ build_join_schema ( self . plan . schema ( ) , right. schema ( ) , & join_type) ?;
305295
306296 Ok ( Self :: from ( LogicalPlan :: Join {
307297 left : Arc :: new ( self . plan . clone ( ) ) ,
@@ -323,21 +313,16 @@ impl LogicalPlanBuilder {
323313 let left_keys: Vec < Column > = using_keys
324314 . clone ( )
325315 . into_iter ( )
326- . map ( |c| c. into ( ) . normalize ( & self . plan . all_schemas ( ) ) )
316+ . map ( |c| c. into ( ) . normalize ( & self . plan ) )
327317 . collect :: < Result < _ > > ( ) ?;
328318 let right_keys: Vec < Column > = using_keys
329319 . into_iter ( )
330- . map ( |c| c. into ( ) . normalize ( & right. all_schemas ( ) ) )
320+ . map ( |c| c. into ( ) . normalize ( right) )
331321 . collect :: < Result < _ > > ( ) ?;
332322
333323 let on: Vec < ( _ , _ ) > = left_keys. into_iter ( ) . zip ( right_keys. into_iter ( ) ) . collect ( ) ;
334- let join_schema = build_join_schema (
335- self . plan . schema ( ) ,
336- right. schema ( ) ,
337- & on,
338- & join_type,
339- & JoinConstraint :: Using ,
340- ) ?;
324+ let join_schema =
325+ build_join_schema ( self . plan . schema ( ) , right. schema ( ) , & join_type) ?;
341326
342327 Ok ( Self :: from ( LogicalPlan :: Join {
343328 left : Arc :: new ( self . plan . clone ( ) ) ,
@@ -390,9 +375,8 @@ impl LogicalPlanBuilder {
390375 group_expr : impl IntoIterator < Item = Expr > ,
391376 aggr_expr : impl IntoIterator < Item = Expr > ,
392377 ) -> Result < Self > {
393- let schemas = self . plan . all_schemas ( ) ;
394- let group_expr = normalize_cols ( group_expr, & schemas) ?;
395- let aggr_expr = normalize_cols ( aggr_expr, & schemas) ?;
378+ let group_expr = normalize_cols ( group_expr, & self . plan ) ?;
379+ let aggr_expr = normalize_cols ( aggr_expr, & self . plan ) ?;
396380 let all_expr = group_expr. iter ( ) . chain ( aggr_expr. iter ( ) ) ;
397381
398382 validate_unique_names ( "Aggregations" , all_expr. clone ( ) , self . plan . schema ( ) ) ?;
@@ -436,53 +420,14 @@ impl LogicalPlanBuilder {
436420pub fn build_join_schema (
437421 left : & DFSchema ,
438422 right : & DFSchema ,
439- on : & [ ( Column , Column ) ] ,
440423 join_type : & JoinType ,
441- join_constraint : & JoinConstraint ,
442424) -> Result < DFSchema > {
443425 let fields: Vec < DFField > = match join_type {
444426 JoinType :: Inner | JoinType :: Left | JoinType :: Full | JoinType :: Right => {
445- match join_constraint {
446- JoinConstraint :: On => {
447- let right_fields = right. fields ( ) . iter ( ) ;
448- let left_fields = left. fields ( ) . iter ( ) ;
449- // left then right
450- left_fields. chain ( right_fields) . cloned ( ) . collect ( )
451- }
452- JoinConstraint :: Using => {
453- // using join requires unique join column in the output schema, so we mark all
454- // right join keys as duplicate
455- let duplicate_join_names =
456- on. iter ( ) . map ( |on| & on. 1 . name ) . collect :: < HashSet < _ > > ( ) ;
457-
458- let right_fields = right
459- . fields ( )
460- . iter ( )
461- . filter ( |f| !duplicate_join_names. contains ( f. name ( ) ) )
462- . cloned ( ) ;
463-
464- let left_fields = left. fields ( ) . iter ( ) . map ( |f| {
465- for key in on. iter ( ) {
466- // update qualifiers for shared fields
467- if duplicate_join_names. contains ( f. name ( ) ) {
468- let mut hs = HashSet :: new ( ) ;
469- if let Some ( q) = & key. 0 . relation {
470- hs. insert ( q. to_string ( ) ) ;
471- }
472- if let Some ( q) = & key. 1 . relation {
473- hs. insert ( q. to_string ( ) ) ;
474- }
475- return f. clone ( ) . set_shared_qualifiers ( hs) ;
476- }
477- }
478-
479- f. clone ( )
480- } ) ;
481-
482- // left then right
483- left_fields. chain ( right_fields) . collect ( )
484- }
485- }
427+ let right_fields = right. fields ( ) . iter ( ) ;
428+ let left_fields = left. fields ( ) . iter ( ) ;
429+ // left then right
430+ left_fields. chain ( right_fields) . cloned ( ) . collect ( )
486431 }
487432 JoinType :: Semi | JoinType :: Anti => {
488433 // Only use the left side for the schema
0 commit comments