Skip to content

Commit

Permalink
minor: remove useless .get() (#5336)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackwener authored Feb 20, 2023
1 parent db4f998 commit ae89960
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 32 deletions.
40 changes: 14 additions & 26 deletions datafusion/optimizer/src/propagate_empty_relation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,8 @@ impl OptimizerRule for PropagateEmptyRelation {
}

fn binary_plan_children_is_empty(plan: &LogicalPlan) -> Result<(bool, bool)> {
let inputs = plan.inputs();

// all binary-plan need to deal with separately.
match inputs.len() {
2 => {
let left = inputs.get(0).unwrap();
let right = inputs.get(1).unwrap();

match plan.inputs()[..] {
[left, right] => {
let left_empty = match left {
LogicalPlan::EmptyRelation(empty) => !empty.produce_one_row,
_ => false,
Expand All @@ -169,26 +163,20 @@ fn binary_plan_children_is_empty(plan: &LogicalPlan) -> Result<(bool, bool)> {
}

fn empty_child(plan: &LogicalPlan) -> Result<Option<LogicalPlan>> {
let inputs = plan.inputs();

// all binary-plan need to deal with separately.
match inputs.len() {
1 => {
let input = inputs.get(0).unwrap();
match input {
LogicalPlan::EmptyRelation(empty) => {
if !empty.produce_one_row {
Ok(Some(LogicalPlan::EmptyRelation(EmptyRelation {
produce_one_row: false,
schema: plan.schema().clone(),
})))
} else {
Ok(None)
}
match plan.inputs()[..] {
[child] => match child {
LogicalPlan::EmptyRelation(empty) => {
if !empty.produce_one_row {
Ok(Some(LogicalPlan::EmptyRelation(EmptyRelation {
produce_one_row: false,
schema: plan.schema().clone(),
})))
} else {
Ok(None)
}
_ => Ok(None),
}
}
_ => Ok(None),
},
_ => Err(DataFusionError::Plan(
"plan just can have one child".to_string(),
)),
Expand Down
4 changes: 1 addition & 3 deletions datafusion/optimizer/src/push_down_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,7 @@ impl OptimizerRule for PushDownFilter {
| LogicalPlan::Sort(_) => {
// commutable
let new_filter =
plan.with_new_inputs(&[
(**(child_plan.inputs().get(0).unwrap())).clone()
])?;
plan.with_new_inputs(&[child_plan.inputs()[0].clone()])?;
child_plan.with_new_inputs(&[new_filter])?
}
LogicalPlan::SubqueryAlias(subquery_alias) => {
Expand Down
4 changes: 1 addition & 3 deletions datafusion/optimizer/src/push_down_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@ impl OptimizerRule for PushDownLimit {
LogicalPlan::Projection(_) | LogicalPlan::SubqueryAlias(_) => {
// commute
let new_limit =
plan.with_new_inputs(&[
(*(child_plan.inputs().get(0).unwrap())).clone()
])?;
plan.with_new_inputs(&[child_plan.inputs()[0].clone()])?;
Some(child_plan.with_new_inputs(&[new_limit])?)
}
_ => None,
Expand Down

0 comments on commit ae89960

Please sign in to comment.