alamb commented on code in PR #3810:
URL: https://github.com/apache/arrow-datafusion/pull/3810#discussion_r993803786
##########
datafusion/optimizer/src/utils.rs:
##########
@@ -51,62 +51,72 @@ pub fn optimize_children(
from_plan(plan, &new_exprs, &new_inputs)
}
-/// converts "A AND B AND C" => [A, B, C]
-pub fn split_conjunction<'a>(predicate: &'a Expr, predicates: &mut Vec<&'a
Expr>) {
- match predicate {
+/// Splits a conjunctive [`Expr`] such as `A AND B AND C` => `[A, B, C]`
+///
+/// This is often used to "split" filter expressions such as `col1 = 5
+/// AND col2 = 10` into [`col1 = 5`, `col2 = 10`];
+pub fn split_conjunction(expr: &Expr) -> Vec<&Expr> {
+ split_conjunction_impl(expr, vec![])
+}
+
+fn split_conjunction_impl<'a>(expr: &'a Expr, mut exprs: Vec<&'a Expr>) ->
Vec<&'a Expr> {
+ match expr {
Expr::BinaryExpr {
right,
op: Operator::And,
left,
} => {
- split_conjunction(left, predicates);
- split_conjunction(right, predicates);
+ let exprs = split_conjunction_impl(left, exprs);
+ split_conjunction_impl(right, exprs)
}
- Expr::Alias(expr, _) => {
- split_conjunction(expr, predicates);
+ Expr::Alias(expr, _) => split_conjunction_impl(expr, exprs),
+ other => {
+ exprs.push(other);
+ exprs
}
- other => predicates.push(other),
}
}
-/// Combines an array of filter expressions into a single filter expression
-/// consisting of the input filter expressions joined with logical AND.
-/// Returns None if the filters array is empty.
-pub fn combine_filters(filters: &[Expr]) -> Option<Expr> {
- if filters.is_empty() {
- return None;
- }
- let combined_filter = filters
- .iter()
- .skip(1)
- .fold(filters[0].clone(), |acc, filter| and(acc, filter.clone()));
- Some(combined_filter)
+/// Splits an owned conjunctive [`Expr`] such as `A AND B AND C` => `[A, B, C]`
+///
+/// See [`split_conjunction`] for more details.
+pub fn split_conjunction_owned(expr: Expr) -> Vec<Expr> {
Review Comment:
this function used to be called `uncombine_filters` which was not at all
consistent with the `split_conjunction` that took a reference 🤯
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]