Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Commit c9f59b0

Browse files
committed
refactor: use match statement in simplify_log_expr and remove unreachable!
Signed-off-by: Yuchen Liang <[email protected]>
1 parent ecea664 commit c9f59b0

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

optd-datafusion-repr/src/rules/filter.rs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,41 +38,35 @@ pub(crate) fn simplify_log_expr(log_expr: ArcDfPredNode, changed: &mut bool) ->
3838
if let DfPredType::Constant(ConstantType::Bool) = new_child.typ {
3939
let data = ConstantPred::from_pred_node(new_child).unwrap().value();
4040
*changed = true;
41-
// TrueExpr
42-
if data.as_bool() {
43-
if op == LogOpType::And {
44-
// skip True in And
45-
continue;
46-
}
47-
if op == LogOpType::Or {
41+
42+
match (data.as_bool(), op) {
43+
(true, LogOpType::Or) => {
4844
// replace whole exprList with True
4945
return ConstantPred::bool(true).into_pred_node();
5046
}
51-
unreachable!("no other type in logOp");
52-
}
53-
// FalseExpr
54-
if op == LogOpType::And {
55-
// replace whole exprList with False
56-
return ConstantPred::bool(false).into_pred_node();
57-
}
58-
if op == LogOpType::Or {
59-
// skip False in Or
60-
continue;
47+
(false, LogOpType::And) => {
48+
// replace whole exprList with False
49+
return ConstantPred::bool(false).into_pred_node();
50+
}
51+
_ => {
52+
// skip True in `And`, and False in `Or`
53+
continue;
54+
}
6155
}
62-
unreachable!("no other type in logOp");
6356
} else if !new_children_set.contains(&new_child) {
6457
new_children_set.insert(new_child.clone());
6558
new_children.push(new_child);
6659
}
6760
}
6861
if new_children.is_empty() {
69-
if op == LogOpType::And {
70-
return ConstantPred::bool(true).into_pred_node();
71-
}
72-
if op == LogOpType::Or {
73-
return ConstantPred::bool(false).into_pred_node();
62+
match op {
63+
LogOpType::And => {
64+
return ConstantPred::bool(true).into_pred_node();
65+
}
66+
LogOpType::Or => {
67+
return ConstantPred::bool(false).into_pred_node();
68+
}
7469
}
75-
unreachable!("no other type in logOp");
7670
}
7771
if new_children.len() == 1 {
7872
*changed = true;

0 commit comments

Comments
 (0)