Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug the optimizer rule filter push down #2039

Merged
merged 3 commits into from
Mar 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(())
}
}