tinfoil-knight commented on issue #11594:
URL: https://github.com/apache/datafusion/issues/11594#issuecomment-2259191688

   I tried a simpler solution by re-arranging the expressions if they match the 
criteria for associativity (currently only considering `Plus` & `Multiply` 
operators) in `Simplifier`. 
   
   We can just re-arrange expressions like `(i + 1) + 2` to `i + (1 + 2)`. Rest 
of the expression will be resolved by the existing `ConstEvaluator` itself. 
   
   We might've some duplication of code due to the various positions that we 
need to consider: 
   `(i + 1) + 2` ; `(1 + i) + 2` ; `2 + (i + 1)` ; `2 + (1 + i)` etc. but I'll 
try to reduce it as much as possible.
   
   
   ```
   > explain select column1 + 1 + 2 from values (100);
   
+---------------+-----------------------------------------------------------------------+
   | plan_type     | plan                                                       
           |
   
+---------------+-----------------------------------------------------------------------+
   | logical_plan  | Projection: column1 + Int64(3) AS column1 + Int64(1) + 
Int64(2)       |
   |               |   Values: (Int64(100))                                     
           |
   | physical_plan | ProjectionExec: expr=[column1@0 + 3 as column1 + Int64(1) 
+ Int64(2)] |
   |               |   ValuesExec                                               
           |
   |               |                                                            
           |
   
+---------------+-----------------------------------------------------------------------+
   ```


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