-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Always add parentheses when formatting BinaryExpr
with SchemaDisplay
#16209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Always add parentheses when formatting BinaryExpr
with SchemaDisplay
#16209
Conversation
BinaryExpr
BinaryExpr
with SchemaDisplay
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
Given how widely used this code is I suspect this change will be quite invasive / require changing many tests |
@@ -2500,7 +2500,7 @@ impl Display for SchemaDisplay<'_> { | |||
} | |||
} | |||
Expr::BinaryExpr(BinaryExpr { left, op, right }) => { | |||
write!(f, "{} {op} {}", SchemaDisplay(left), SchemaDisplay(right),) | |||
write!(f, "({} {op} {})", SchemaDisplay(left), SchemaDisplay(right),) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the actual change.
@hendrikmakait Hi, there are still a few places that need to change |
BinaryExpr
with SchemaDisplay
BinaryExpr
with SchemaDisplay
@xudong963: CI is green now. |
cc @alamb for another look |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @hendrikmakait and @xudong963 !
I agree this is better, but I see a bunch of tests where the parens are added even when they aren't necessary to distinguish order
Maybe we could add a check and only add parens to the display if they were needed (in some sort of Expr::Binary operator tree 🤔 )
"| 2025-05-19 |", | ||
"+-----------------------------------+", | ||
"+-------------------------------------+", | ||
"| make_date((t.y + Int64(1)),t.m,t.d) |", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parens here seem unecessary (the top most expression) -- I wonder if we can avoid that somehow
@alamb: That's a fair point, I actually brought it up in the issue (#16054 (comment)). I'm happy to adjust the implementation. |
I think we should try to adjust if possible. Thank you @hendrikmakait |
Which issue does this PR close?
Rationale for this change
What changes are included in this PR?
BinaryExpr
via SchemaDisplayAre these changes tested?
Yes, added a regression test
Are there any user-facing changes?
No