Skip to content

Commit

Permalink
fix bug the optimizer rule filter push down (#2039)
Browse files Browse the repository at this point in the history
* optimizer: fix the filter push down bug

* *: add unit test

* *: add the reproduce unit test
  • Loading branch information
jackwener authored Mar 20, 2022
1 parent 503618f commit 74bf7ab
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion datafusion/src/optimizer/filter_push_down.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -1376,6 +1376,11 @@ mod tests {
arrow::datatypes::DataType::Int32,
true,
),
arrow::datatypes::Field::new(
"b",
arrow::datatypes::DataType::Int32,
true,
),
]))
}

Expand Down Expand Up @@ -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(())
}
}

0 comments on commit 74bf7ab

Please sign in to comment.