From f75844246309667158d7df82d4d0666523b8063f Mon Sep 17 00:00:00 2001 From: Matt Butrovich Date: Wed, 13 Nov 2024 14:35:45 -0500 Subject: [PATCH] Selectively generate projection vector. --- .../core/src/execution/datafusion/planner.rs | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/native/core/src/execution/datafusion/planner.rs b/native/core/src/execution/datafusion/planner.rs index 1268a2ff4..cd79e8e0b 100644 --- a/native/core/src/execution/datafusion/planner.rs +++ b/native/core/src/execution/datafusion/planner.rs @@ -968,16 +968,6 @@ impl PhysicalPlanner { ) .unwrap(), ); - assert!(!required_schema_arrow.fields.is_empty()); - - let mut projection_vector: Vec = - Vec::with_capacity(required_schema_arrow.fields.len()); - // TODO: could be faster with a hashmap rather than iterating over data_schema_arrow with index_of. - required_schema_arrow.fields.iter().for_each(|field| { - projection_vector.push(data_schema_arrow.index_of(field.name()).unwrap()); - }); - - assert_eq!(projection_vector.len(), required_schema_arrow.fields.len()); // Convert the Spark expressions to Physical expressions let data_filters: Result>, ExecutionError> = scan @@ -1028,10 +1018,22 @@ impl PhysicalPlanner { assert_eq!(file_groups.len(), partition_count); let object_store_url = ObjectStoreUrl::local_filesystem(); - let file_scan_config = + let mut file_scan_config = FileScanConfig::new(object_store_url, Arc::clone(&data_schema_arrow)) - .with_file_groups(file_groups) - .with_projection(Some(projection_vector)); + .with_file_groups(file_groups); + + // Check for projection, if so generate the vector and add to FileScanConfig. + if !required_schema_arrow.fields.is_empty() { + let mut projection_vector: Vec = + Vec::with_capacity(required_schema_arrow.fields.len()); + // TODO: could be faster with a hashmap rather than iterating over data_schema_arrow with index_of. + required_schema_arrow.fields.iter().for_each(|field| { + projection_vector.push(data_schema_arrow.index_of(field.name()).unwrap()); + }); + + assert_eq!(projection_vector.len(), required_schema_arrow.fields.len()); + file_scan_config = file_scan_config.with_projection(Some(projection_vector)); + } let mut table_parquet_options = TableParquetOptions::new(); // TODO: Maybe these are configs?