Description
Is your feature request related to a problem or challenge?
Part of #9494
As @backkem says #10528 (comment) on #10528
Currently, expressions from the DataFusion SQL unparser (aka expr --> String) are somewhat ugly
For example the expression col("a").eq(lit(5))
would be rendered as a = 5
by most poeple if they did it manaully, but DataFusion's unparser currently renders it like "a" = 5
(with extra quotes).
DataFusion also puts in quotes to make the order of operations explicit -- so instead of a < 5 AND b < 10
it would render ("a" < 5) AND ("b" < 10)
The current unparser is conservative and likely works well for when generating SQL for consumptions by other database systems. However, the SQL is not as nice for human consumption
Here is another instance from the example
datafusion/datafusion-examples/examples/plan_to_sql.rs
Lines 50 to 53 in 98647e8
Describe the solution you'd like
If we want to make the generated SQL easier to read by humans / more succint, these steps will have to be made "smarter".
Describe alternatives you've considered
Potential ideas:
- We'll have to add in the math rules to avoid unneeded parentheses
- (likely dialect specific) rules for determining of quoting is needed.
Note that the latter likely involves listing out the reserved keywords for each dialect.
Additional context
No response