-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make SQL strings generated from Expr
s "prettier"
#10557
Comments
Provide something I surveyed. I think we can follow how Calcite handles the quoted issue. The It can be overridden according to the specific data source, such as BigQuery: They implement some rules, such as regex patterns or reserved word lists. I think a dialect-specific rule is a nice choice. |
Indeed, there is already a function on the sqlparser::dialect trait that takes this into account: The dialect specific implementations just need to be expanded on. For now they just always return a conservative quote character. |
I think it's same as the dialect in datafusion::unparser::dialect
However, what we need is a checker to check if the identifier needs to be quoted. I think I can make a PR for DefaultDialect first.
|
As the mentioned in
I think we need to use the Dialect in sqlparser-rs instead and extract |
Yes, these are basically the same object. The one in DataFusion was put there temporarily until the trait extension in the sqlparser repo is landed and pushed to crates.io. This may have happened in the meantime. |
We may need a 0.46.1 for resolving the regressions:
I've locally confirmed that |
I'm not sure but I think we can merge #10573 first because it also fix many unpasring tests. Then, I'll create PR for sqlparser to add the check rule in dialect. |
FWI #10573 is merged! |
Do we split off a ticket reduce the nr of brackets emitted? |
Excellent call -- I filed #10633 |
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 asa = 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:
Note that the latter likely involves listing out the reserved keywords for each dialect.
Additional context
No response
The text was updated successfully, but these errors were encountered: