Skip to content

Commit

Permalink
Selectively generate projection vector.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbutrovich committed Nov 13, 2024
1 parent 90e2b6f commit f758442
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions native/core/src/execution/datafusion/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -968,16 +968,6 @@ impl PhysicalPlanner {
)
.unwrap(),
);
assert!(!required_schema_arrow.fields.is_empty());

let mut projection_vector: Vec<usize> =
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<Vec<Arc<dyn PhysicalExpr>>, ExecutionError> = scan
Expand Down Expand Up @@ -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<usize> =
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?
Expand Down

0 comments on commit f758442

Please sign in to comment.