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

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


The following commit(s) were added to refs/heads/master by this push:
     new 74bf7ab  fix bug the optimizer rule filter push down (#2039)
74bf7ab is described below

commit 74bf7ab4f578edda8dcb4fe70ec43560992f5bab
Author: jakevin <[email protected]>
AuthorDate: Sun Mar 20 17:38:34 2022 +0800

    fix bug the optimizer rule filter push down (#2039)
    
    * optimizer: fix the filter push down bug
    
    * *: add unit test
    
    * *: add the reproduce unit test
---
 datafusion/src/optimizer/filter_push_down.rs | 38 +++++++++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git a/datafusion/src/optimizer/filter_push_down.rs 
b/datafusion/src/optimizer/filter_push_down.rs
index d8e43ed..795e7a2 100644
--- a/datafusion/src/optimizer/filter_push_down.rs
+++ b/datafusion/src/optimizer/filter_push_down.rs
@@ -523,7 +523,7 @@ fn optimize(plan: &LogicalPlan, mut state: State) -> 
Result<LogicalPlan> {
                     // Don't add expression again if it's already present in
                     // pushed down filters.
                     if new_filters.contains(filter_expr) {
-                        break;
+                        continue;
                     }
                     new_filters.push(filter_expr.clone());
                 }
@@ -1376,6 +1376,11 @@ mod tests {
                     arrow::datatypes::DataType::Int32,
                     true,
                 ),
+                arrow::datatypes::Field::new(
+                    "b",
+                    arrow::datatypes::DataType::Int32,
+                    true,
+                ),
             ]))
         }
 
@@ -1471,4 +1476,35 @@ mod tests {
         assert_optimized_plan_eq(&plan, expected);
         Ok(())
     }
+
+    #[test]
+    fn multi_combined_filter() -> Result<()> {
+        let test_provider = PushDownProvider {
+            filter_support: TableProviderFilterPushDown::Inexact,
+        };
+
+        let table_scan = LogicalPlan::TableScan(TableScan {
+            table_name: "test".to_string(),
+            filters: vec![col("a").eq(lit(10i64)), col("b").gt(lit(11i64))],
+            projected_schema: Arc::new(DFSchema::try_from(
+                (*test_provider.schema()).clone(),
+            )?),
+            projection: Some(vec![0]),
+            source: Arc::new(test_provider),
+            limit: None,
+        });
+
+        let plan = LogicalPlanBuilder::from(table_scan)
+            .filter(and(col("a").eq(lit(10i64)), col("b").gt(lit(11i64))))?
+            .project(vec![col("a"), col("b")])?
+            .build()?;
+
+        let expected ="Projection: #a, #b\
+            \n  Filter: #a = Int64(10) AND #b > Int64(11)\
+            \n    TableScan: test projection=Some([0]), filters=[#a = 
Int64(10), #b > Int64(11)]";
+
+        assert_optimized_plan_eq(&plan, expected);
+
+        Ok(())
+    }
 }

Reply via email to