alamb opened a new issue, #11594: URL: https://github.com/apache/datafusion/issues/11594
### Is your feature request related to a problem or challenge? DataFusion will simplify expressions like this: `i + (1 + 2)` => `i + 3` However, it will not simplify `i + 1 + 2` (remains `i + 1 + 2`) You can see this in the explain plans ``` > 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)] | <-- computed expression is `column1@0 + 3` | | ValuesExec | | | | +---------------+-----------------------------------------------------------------------+ 2 row(s) fetched. Elapsed 0.013 seconds. > explain select column1 + 1 + 2 from values (100); +---------------+---------------------------------------------------------------------------+ | plan_type | plan | +---------------+---------------------------------------------------------------------------+ | logical_plan | Projection: column1 + Int64(1) + Int64(2) | | | Values: (Int64(100)) | | physical_plan | ProjectionExec: expr=[column1@0 + 1 + 2 as column1 + Int64(1) + Int64(2)] | <-- expression is STILL `column1@0 + 1 + 2` | | ValuesExec | | | | +---------------+---------------------------------------------------------------------------+ 2 row(s) fetched. Elapsed 0.002 seconds. ``` @timsaucer has identified the problem > I don’t have time to look through the code right now, but I would guess the operations happen left to right when you don’t have parentheses to indicate order. So the second would be equivalent to (col(“i”) + lit(1)) + lit(2). That is, would guess it isn’t checking for associativity of operations. So in this case `i + 1 + 2` is parsed as `(i + 1) + 2` and since `(i + 1)` can't be reduced, the entire expression isn't either ### Describe the solution you'd like It would be nice to properly support this simplification ### Describe alternatives you've considered _No response_ ### Additional context Came up on discord: https://discord.com/channels/885562378132000778/1166447479609376850/1264325499971436594 -- 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-unsubscr...@datafusion.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org