File tree Expand file tree Collapse file tree 1 file changed +26
-18
lines changed
datafusion/datasource/src Expand file tree Collapse file tree 1 file changed +26
-18
lines changed Original file line number Diff line number Diff line change @@ -267,24 +267,32 @@ impl DataSource for FileScanConfig {
267
267
// If there is any non-column or alias-carrier expression, Projection should not be removed.
268
268
// This process can be moved into CsvExec, but it would be an overlap of their responsibility.
269
269
270
- Ok ( ( all_alias_free_columns ( projection. expr ( ) )
271
- && self . table_partition_cols . is_empty ( ) )
272
- . then ( || {
273
- let file_scan = self . clone ( ) ;
274
- let source = Arc :: clone ( & file_scan. file_source ) ;
275
- let new_projections = new_projections_for_columns (
276
- projection,
277
- & file_scan
278
- . projection
279
- . clone ( )
280
- . unwrap_or ( ( 0 ..self . file_schema . fields ( ) . len ( ) ) . collect ( ) ) ,
281
- ) ;
282
- file_scan
283
- // Assign projected statistics to source
284
- . with_projection ( Some ( new_projections) )
285
- . with_source ( source)
286
- . build ( ) as _
287
- } ) )
270
+ let partitioned_columns_in_proj = projection. expr ( ) . iter ( ) . any ( |( expr, _) | {
271
+ expr. as_any ( )
272
+ . downcast_ref :: < Column > ( )
273
+ . map ( |expr| expr. index ( ) >= self . file_schema . fields ( ) . len ( ) )
274
+ . unwrap_or ( false )
275
+ } ) ;
276
+
277
+ Ok (
278
+ ( all_alias_free_columns ( projection. expr ( ) ) && !partitioned_columns_in_proj)
279
+ . then ( || {
280
+ let file_scan = self . clone ( ) ;
281
+ let source = Arc :: clone ( & file_scan. file_source ) ;
282
+ let new_projections = new_projections_for_columns (
283
+ projection,
284
+ & file_scan
285
+ . projection
286
+ . clone ( )
287
+ . unwrap_or ( ( 0 ..self . file_schema . fields ( ) . len ( ) ) . collect ( ) ) ,
288
+ ) ;
289
+ file_scan
290
+ // Assign projected statistics to source
291
+ . with_projection ( Some ( new_projections) )
292
+ . with_source ( source)
293
+ . build ( ) as _
294
+ } ) ,
295
+ )
288
296
}
289
297
}
290
298
You can’t perform that action at this time.
0 commit comments