datafusion icon indicating copy to clipboard operation
datafusion copied to clipboard

Make SQL strings generated from Exprs even "prettier"

Open alamb opened this issue 1 year ago • 0 comments

Is your feature request related to a problem or challenge?

Part of https://github.com/apache/datafusion/issues/9494

In https://github.com/apache/datafusion/pull/10573 @goldmedal made expressions from the DataFusion SQL unparser (aka expr --> String) nicer. However there are still certain cases where the rendering will err on the side of explicitness rather than (human readability()

For examoke, it 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. It could be nicer for generating SQL to read by humans

Describe the solution you'd like

If we want to make the generated SQL easier to read by humans / more succinct, these steps will have to be made "smarter".

Describe alternatives you've considered

  1. We'll have to add in the math rules (precidence) to avoid unneeded parentheses. These rules typically vary subtly between dialects.

  2. We could simply not do this item as well as it is likely hard to get right and maybe extra parens aren't all that bad 🤔

Additional context

No response

alamb avatar May 23 '24 10:05 alamb