This is an automated email from the ASF dual-hosted git repository.

agrove pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new 0a698c0  ARROW-9831: [Rust][DataFusion] Fixed compilation error
0a698c0 is described below

commit 0a698c06d1e49976133cb64681d627faf8967511
Author: Jorge C. Leitao <jorgecarlei...@gmail.com>
AuthorDate: Sat Aug 22 12:17:22 2020 -0600

    ARROW-9831: [Rust][DataFusion] Fixed compilation error
    
    @andygrove , the commit that we just merged to master was not aligned with 
master, causing the code to fail to compile :(
    
    This fixes the compilation, but there are still failing tests. I am working 
on them...
    
    Closes #8026 from jorgecarleitao/fix_test
    
    Authored-by: Jorge C. Leitao <jorgecarlei...@gmail.com>
    Signed-off-by: Andy Grove <andygrov...@gmail.com>
---
 .../datafusion/src/optimizer/projection_push_down.rs | 20 +++++++++++++-------
 rust/datafusion/src/test/mod.rs                      |  1 -
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/rust/datafusion/src/optimizer/projection_push_down.rs 
b/rust/datafusion/src/optimizer/projection_push_down.rs
index 4ec2fa0..54eee2f 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 Aggregate
             let 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 columns
                         utils::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 columns
         LogicalPlan::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.rs
index ed8f8b6..26d67fe 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,
     }
 }

Reply via email to