alamb commented on code in PR #13032:
URL: https://github.com/apache/datafusion/pull/13032#discussion_r1809499606
##########
datafusion/expr/src/utils.rs:
##########
@@ -1101,6 +1101,54 @@ fn split_conjunction_impl<'a>(expr: &'a Expr, mut exprs:
Vec<&'a Expr>) -> Vec<&
}
}
+/// Iteratate parts in a conjunctive [`Expr`] such as `A AND B AND C` => `[A,
B, C]`
+///
+/// See [`split_conjunction_owned`] for more details and an example.
+pub fn iter_conjunction(expr: &Expr) -> impl Iterator<Item = &Expr> {
+ let mut stack = vec![expr];
+ std::iter::from_fn(move || {
+ while let Some(expr) = stack.pop() {
+ match expr {
+ Expr::BinaryExpr(BinaryExpr {
+ right,
+ op: Operator::And,
+ left,
+ }) => {
+ stack.push(right);
+ stack.push(left);
+ }
+ Expr::Alias(Alias { expr, .. }) => stack.push(expr),
+ other => return Some(other),
+ }
+ }
+ None
+ })
+}
+
+/// Iteratate parts in a conjunctive [`Expr`] such as `A AND B AND C` => `[A,
B, C]`
+///
+/// See [`split_conjunction_owned`] for more details and an example.
+pub fn iter_conjunction_owned(expr: Expr) -> impl Iterator<Item = Expr> {
+ let mut stack = vec![expr];
+ std::iter::from_fn(move || {
+ while let Some(expr) = stack.pop() {
Review Comment:
this is a clever formulation of an iterator
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]