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

Minor: clean the code in eliminate_filter #4055

Merged
merged 1 commit into from
Nov 1, 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
27 changes: 10 additions & 17 deletions datafusion/optimizer/src/eliminate_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,22 @@ impl OptimizerRule for EliminateFilter {
plan: &LogicalPlan,
optimizer_config: &mut OptimizerConfig,
) -> Result<LogicalPlan> {
let (filter_value, input) = match plan {
let predicate_and_input = match plan {
LogicalPlan::Filter(filter) => match filter.predicate() {
Expr::Literal(ScalarValue::Boolean(Some(v))) => {
(Some(*v), Some(filter.input()))
Some((*v, filter.input()))
}
_ => (None, None),
_ => None,
},
_ => (None, None),
_ => None,
};

match filter_value {
Some(v) => {
// input is guaranteed be Some due to previous code
let input = input.unwrap();
if v {
self.optimize(input, optimizer_config)
} else {
Ok(LogicalPlan::EmptyRelation(EmptyRelation {
produce_one_row: false,
schema: input.schema().clone(),
}))
}
}
match predicate_and_input {
Some((true, input)) => self.optimize(input, optimizer_config),
Some((false, input)) => Ok(LogicalPlan::EmptyRelation(EmptyRelation {
produce_one_row: false,
schema: input.schema().clone(),
})),
None => {
// Apply the optimization to all inputs of the plan
let inputs = plan.inputs();
Expand Down