Apache DataFusion SQL Query Engine
ARROW-9831: [Rust][DataFusion] Fixed compilation error
Jorge C. Leitaod4ec267dfe32
diff --git a/rust/datafusion/src/optimizer/projection_push_down.rs b/rust/datafusion/src/optimizer/projection_push_down.rsindex 4ec2fa03e5..54eee2f05f 100644--- a/rust/datafusion/src/optimizer/projection_push_down.rs+++ b/rust/datafusion/src/optimizer/projection_push_down.rs@@ -174,16 +174,14 @@ fn optimize_plan(// Gather all columns needed for expressions in this Aggregatelet mut new_aggr_expr = Vec::new();- let mut new_fields = Vec::new();aggr_expr.iter().map(|expr| {let name = &expr.name(&schema)?;- let field = schema.field_with_name(name)?;if required_columns.contains(name) {new_aggr_expr.push(expr.clone());- new_fields.push(field.clone());+ new_required_columns.insert(name.clone());// add to the new set of required columnsutils::expr_to_column_names(expr, &mut new_required_columns)@@ -192,7 +190,15 @@ fn optimize_plan(}}).collect::<Result<()>>()?;- let new_schema = Schema::new(new_fields);++ let new_schema = Schema::new(+ schema+ .fields()+ .iter()+ .filter(|x| new_required_columns.contains(x.name()))+ .cloned()+ .collect(),+ );Ok(LogicalPlan::Aggregate {group_expr: group_expr.clone(),@@ -303,7 +309,7 @@ fn optimize_plan(// all other nodes:// * gather all used columns as required columnsLogicalPlan::Limit { .. }- | LogicalPlan::Selection { .. }+ | LogicalPlan::Filter { .. }| LogicalPlan::EmptyRelation { .. }| LogicalPlan::Sort { .. }| LogicalPlan::CreateExternalTable { .. } => {@@ -486,7 +492,7 @@ mod tests {let expected = "\Aggregate: groupBy=[[#c]], aggr=[[MAX(#a)]]\- \n Selection: #c Gt Int32(1)\+ \n Filter: #c Gt Int32(1)\\n Projection: #c, #a\\n TableScan: test projection=Some([0, 2])";@@ -537,7 +543,7 @@ mod tests {let expected = "\Projection: #c, #a, #MAX(b)\- \n Selection: #c Gt Int32(1)\+ \n Filter: #c Gt Int32(1)\\n Aggregate: groupBy=[[#a, #c]], aggr=[[MAX(#b)]]\\n TableScan: test projection=Some([0, 1, 2])";diff --git a/rust/datafusion/src/test/mod.rs b/rust/datafusion/src/test/mod.rsindex ed8f8b64ea..26d67fede1 100644--- a/rust/datafusion/src/test/mod.rs+++ b/rust/datafusion/src/test/mod.rs@@ -235,6 +235,5 @@ pub fn min(expr: Expr) -> Expr {Expr::AggregateFunction {name: "MIN".to_owned(),args: vec![expr],- return_type: DataType::Float64,}}