jayendra13 opened a new pull request, #20851:
URL: https://github.com/apache/datafusion/pull/20851

   SchemaDisplay for BinaryExpr had no parenthesization, causing SELECT (1+2)*3 
to display column header as
   "Int64(1) + Int64(2) * Int64(3)" which misrepresents precedence.
   
   Mirror the existing correct Display impl by adding a write_child helper that 
wraps child binary expressions in parentheses when the child operator has lower 
precedence than the parent.
   
   ## Which issue does this PR close?
   - Closes #16054
   
   ## Rationale for this change
   
     `SELECT (1+2)*3` displays column header as `Int64(1) + Int64(2) * 
Int64(3)` which misrepresents operator precedence. The parentheses are dropped 
because `SchemaDisplay` for `BinaryExpr` 
     has no parenthesization logic, unlike `Display` which already handles this 
correctly. 
   
   ## What changes are included in this PR?
   
     Added precedence-based parenthesization to `SchemaDisplay` for 
`BinaryExpr`, mirroring the existing correct `Display` impl (same file, line 
621). A `write_child` helper wraps child      
     binary expressions in parentheses only when the child operator has lower 
precedence than the parent.
                                                                                
                                                                                
                               
     Two optimizer test snapshots updated to reflect the corrected column 
names. 
   
   ## Are these changes tested?
   
     Covered by existing tests. The two snapshot updates in 
`common_subexpr_eliminate` and `simplify_exprs` confirm the fix produces 
correct output. All 642 optimizer unit tests, SQL planner 
     tests, and relevant SLT tests pass. 
   
   ## Are there any user-facing changes?
   
     Column headers now correctly include parentheses for nested binary 
expressions with mixed precedence. For example:                                 
                                       
                                                               
     - Before: `Int64(1) + Int64(2) * Int64(3)`                                 
                                                                                
                               
     - After: `(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]

Reply via email to