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/18 19:47:48 UTC
[GitHub] [arrow-datafusion] andygrove commented on a diff in pull request #3884: Improve formatting of binary expressions
andygrove commented on code in PR #3884:
URL: https://github.com/apache/arrow-datafusion/pull/3884#discussion_r998642719
##########
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:
@Ted-Jiang @alamb This is the main change. Would be good to get some initial feedback here before I update the remaining tests.
--
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