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

Need Query Parser Support #23

Open
adityamatt opened this issue Mar 7, 2024 · 2 comments
Open

Need Query Parser Support #23

adityamatt opened this issue Mar 7, 2024 · 2 comments
Labels
feature request Request for functionality that does not currently exist on the library

Comments

@adityamatt
Copy link

Hi,

We have a use case where we want to know the tables/schemas dependencies of a Presto Query.
The package provides a way to query the presto db with an actual query which would actually execute the query, but instead I'm looking for query parser support. We have such support in java but not in typescript.

@alonsovb alonsovb added the feature request Request for functionality that does not currently exist on the library label Mar 7, 2024
@yhwang
Copy link
Member

yhwang commented Mar 7, 2024

When implementing the SQL Client of the Presto UI, I tried several SQL parsers from the NPM repo, but they don't work well with Presto SQL. Presto SQL is compliant with ANSI SQL, however, it still has some unique formats in some entities, like a fully qualified table name is using <catalog>.<scheme>.<table name> format, and most parsers don't support it.

So my solution is to generate the SQL Parser from the ANTLR grammar file that Presto is using: https://github.com/prestodb/presto/blob/master/presto-parser/src/main/antlr4/com/facebook/presto/sql/parser/SqlBase.g4

You can check details here: https://github.com/prestodb/presto/tree/master/presto-main/src/main/resources/webapp/src/sql-parser and antlr4 supports TypeScript too. You just need to get familiar with the Lexer, Listener, and Parser concepts in ANTLR to use the parser it generates.

If people do need a js SQL parser for Presto SQL, it would be good to automate the process to:

  • generate the ANTLR Lexer, Listener, and Parser for TypeScript from Presto SQL grammar
  • publish the files as a presto-sql-parser (like @prestodb/presto-sql-parser) NPM module

Once there is any change in the grammar file, the new parser will be generated and published.

@adityamatt
Copy link
Author

Thanks for pointing out a solution, I'll update the thread once I try it out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for functionality that does not currently exist on the library
Projects
None yet
Development

No branches or pull requests

3 participants