@@ -163,8 +163,12 @@ fn try_swapping_with_csv(
163163 // This process can be moved into CsvExec, but it would be an overlap of their responsibility.
164164 all_alias_free_columns ( projection. expr ( ) ) . then ( || {
165165 let mut file_scan = csv. base_config ( ) . clone ( ) ;
166- let new_projections =
167- new_projections_for_columns ( projection, & file_scan. projection ) ;
166+ let new_projections = new_projections_for_columns (
167+ projection,
168+ & file_scan
169+ . projection
170+ . unwrap_or ( ( 0 ..csv. schema ( ) . fields ( ) . len ( ) ) . collect ( ) ) ,
171+ ) ;
168172 file_scan. projection = Some ( new_projections) ;
169173
170174 Arc :: new ( CsvExec :: new (
@@ -188,8 +192,11 @@ fn try_swapping_with_memory(
188192 // This process can be moved into MemoryExec, but it would be an overlap of their responsibility.
189193 all_alias_free_columns ( projection. expr ( ) )
190194 . then ( || {
191- let new_projections =
192- new_projections_for_columns ( projection, memory. projection ( ) ) ;
195+ let all_projections = ( 0 ..memory. schema ( ) . fields ( ) . len ( ) ) . collect ( ) ;
196+ let new_projections = new_projections_for_columns (
197+ projection,
198+ memory. projection ( ) . as_ref ( ) . unwrap_or ( & all_projections) ,
199+ ) ;
193200
194201 MemoryExec :: try_new (
195202 memory. partitions ( ) ,
@@ -216,8 +223,11 @@ fn try_swapping_with_streaming_table(
216223 . projection ( )
217224 . as_ref ( )
218225 . map ( |i| i. as_ref ( ) . to_vec ( ) ) ;
219- let new_projections =
220- new_projections_for_columns ( projection, & streaming_table_projections) ;
226+ let new_projections = new_projections_for_columns (
227+ projection,
228+ & streaming_table_projections
229+ . unwrap_or ( ( 0 ..streaming_table. schema ( ) . fields ( ) . len ( ) ) . collect ( ) ) ,
230+ ) ;
221231
222232 let mut lex_orderings = vec ! [ ] ;
223233 for lex_ordering in streaming_table. projected_output_ordering ( ) . into_iter ( ) {
@@ -833,15 +843,15 @@ fn all_alias_free_columns(exprs: &[(Arc<dyn PhysicalExpr>, String)]) -> bool {
833843/// ensure that all expressions are `Column` expressions without aliases.
834844fn new_projections_for_columns (
835845 projection : & ProjectionExec ,
836- source : & Option < Vec < usize > > ,
846+ source : & [ usize ] ,
837847) -> Vec < usize > {
838848 projection
839849 . expr ( )
840850 . iter ( )
841851 . filter_map ( |( expr, _) | {
842852 expr. as_any ( )
843853 . downcast_ref :: < Column > ( )
844- . and_then ( |expr| source. as_ref ( ) . map ( |proj| proj [ expr. index ( ) ] ) )
854+ . map ( |expr| source[ expr. index ( ) ] )
845855 } )
846856 . collect ( )
847857}
0 commit comments