andygrove commented on code in PR #3884:
URL: https://github.com/apache/arrow-datafusion/pull/3884#discussion_r1002593235


##########
datafusion/expr/src/expr.rs:
##########
@@ -267,6 +267,28 @@ impl BinaryExpr {
     }
 }
 
+impl Display for BinaryExpr {
+    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
+        // Put parentheses around child binary expressions so that we can see 
the difference
+        // between `(a OR b) AND c` and `a OR (b AND c)`. A future improvement 
here would be
+        // to only insert parentheses when needed, based on operator 
precedence. For example,
+        // `(a AND b) OR c` and `a AND b OR c` are equivalent and the 
parentheses are not
+        // necessary
+        if matches!(*self.left, Expr::BinaryExpr(_)) {
+            write!(f, "({})", self.left)?;
+        } else {
+            write!(f, "{}", self.left)?;
+        }
+        write!(f, " {} ", self.op)?;
+        if matches!(*self.right, Expr::BinaryExpr(_)) {
+            write!(f, "({})", self.right)?;
+        } else {
+            write!(f, "{}", self.right)?;
+        }
+        Ok(())
+    }
+}

Review Comment:
   I am going to update this PR to do the right thing based on the precedence 
of the operators



-- 
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]

Reply via email to