Skip to content
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

Using sqlparser-rs for SQL AST #97

Closed
max-sixty opened this issue Feb 16, 2022 · 4 comments
Closed

Using sqlparser-rs for SQL AST #97

max-sixty opened this issue Feb 16, 2022 · 4 comments

Comments

@max-sixty
Copy link
Member

We're getting to the point where we're converting PRQL AST to SQL AST, and then we'll need to convert the SQL AST to text.

sqlparser-rs is predominantly for parsing SQL — i.e. going the other direction.

But it has:

It looks excellent quality, something I think we'd love to build on.

This would be "huge if true" — so adding this issue to socialize the idea. I'll optimistically tag @alamb as they've been the main contributor to the repo very recently, in case they have a view.

max-sixty added a commit that referenced this issue Feb 16, 2022
* Functions to transform AST to CTEs

This is not perfect code, but it's in a good enough state to merge. The next steps somewhat depend on #97
@alamb
Copy link

alamb commented Feb 16, 2022

👋 hi @max-sixty -- I (biasedly) think sqlparser is high quality and fairly stable and likely to incrementally add support for new SQL features from the community

I think many projects use sqlparser successfully, both directly like datafusion as well as fork sqlparser for their own use internally and occasionally contribute patches back upstream. The license is the liberal Apache license.

The maintainers only have limited time to work on the project however, so changes in the core repo will likely remain on rounding out the SQL parsing support

@max-sixty
Copy link
Member Author

Thanks @alamb ! Can I ask a follow-up — we are trying to go the other direction — i.e. construct SQL queries from an AST (rather than parsing SQL) — do you think sqlparser is a good fit for that? Does running Display for a sqlparser AST make a SQL query? It looks like it does, which would be awesome...

@alamb
Copy link

alamb commented Feb 16, 2022

Thanks @alamb ! Can I ask a follow-up — we are trying to go the other direction — i.e. construct SQL queries from an AST (rather than parsing SQL) — do you think sqlparser is a good fit for that?

Yes I think it is a good fit

Does running Display for a sqlparser AST make a SQL query? It looks like it does, which would be awesome...

As long as the AST is an actual query then yes :) In fact many of the tests in sqlparser verify that parsing a sql string, and then Displaying it produces the original SQL string

@max-sixty
Copy link
Member Author

That's great news! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants