You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/10/13 12:57:46 UTC

[GitHub] [arrow-datafusion] jackwener commented on a diff in pull request #3810: Make expression manipulation consistent and easier to use: `combine/split filter` `conjunction`, etc

jackwener commented on code in PR #3810:
URL: https://github.com/apache/arrow-datafusion/pull/3810#discussion_r994609709


##########
datafusion/optimizer/src/utils.rs:
##########
@@ -424,31 +468,74 @@ mod tests {
     use super::*;
     use arrow::datatypes::DataType;
     use datafusion_common::Column;
-    use datafusion_expr::{binary_expr, col, lit, utils::expr_to_columns};
+    use datafusion_expr::{col, lit, utils::expr_to_columns};
     use std::collections::HashSet;
     use std::ops::Add;
 
     #[test]
-    fn combine_zero_filters() {
-        let result = combine_filters(&[]);
-        assert_eq!(result, None);
+    fn test_split_conjunction() {

Review Comment:
   IMO, I think we can add test for `conjunction()`. At the same time, we can check the tree structure of this expression by using `match`.
   
   ```rs
   expr is (A B) C;
   
   /// using `match` to check.
   match expr {
      And(
         And(
            B,
            C
         ),
         C
      )
   }
   ```
   
   [A, B, C ,D , E] -> (((A B) C) (D E)) is different from ((((A B) C) D) E).
   
   we can see the result of `conjunction()` in the UT
   
   



##########
datafusion/optimizer/src/utils.rs:
##########
@@ -51,62 +51,106 @@ 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]`
+///
+/// See [`split_conjunction_owned`] for more details and an example.
+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),

Review Comment:
   👍



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org