AndreaBozzo opened a new pull request, #19916:
URL: https://github.com/apache/datafusion/pull/19916
## Which issue does this PR close?
Closes #16054
## Rationale for this change
Binary expressions like `(1+2)*3` were displayed incorrectly as `Int64(1) +
Int64(2) * Int64(3)` without parentheses, which is misleading because it
doesn't preserve the operator precedence from the original expression.
## What changes are included in this PR?
- Modified `Display` implementation for `BinaryExpr` to always wrap nested
binary expressions in parentheses
- Applied the same fix to `SchemaDisplay` and `SqlDisplay` wrappers
- Added tests for binary expression display with various precedence scenarios
## How are these changes tested?
- New unit test `test_binary_expr_display_with_parentheses` covering:
- Arithmetic expressions: `(1+2)*3`
- Logical expressions: `(a OR b) AND c`
- Existing tests pass
## Are these changes safe?
Yes. This follows DuckDB's approach of always adding parentheses around
nested binary expressions, which was discussed and approved in the issue
comments.
### Example
Before:
```
> select (1+2)*3;
+--------------------------------+
| Int64(1) + Int64(2) * Int64(3) |
+--------------------------------+
```
After:
```
> select (1+2)*3;
+------------------------------------+
| (Int64(1) + Int64(2)) * Int64(3) |
+------------------------------------+
```
---
--
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]