Apache DataFusion SQL Query Engine
fix bug the optimizer rule filter push down (#2039)
jakevin74bf7ab4f578
diff --git a/datafusion/src/optimizer/filter_push_down.rs b/datafusion/src/optimizer/filter_push_down.rsindex d8e43ed217..795e7a2938 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(())+ }}