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

Query builder editor's autocomplete context awareness #2151

Open
depombo opened this issue Mar 8, 2023 · 2 comments
Open

Query builder editor's autocomplete context awareness #2151

depombo opened this issue Mar 8, 2023 · 2 comments

Comments

@depombo
Copy link
Member

depombo commented Mar 8, 2023

No description provided.

@depombo depombo converted this from a draft issue Mar 8, 2023
@mtp1376
Copy link
Contributor

mtp1376 commented Mar 16, 2023

I think we need an implementation of PostgreSQL lexer to be able to do this.

@dfellis
Copy link
Member

dfellis commented Mar 16, 2023

We use one in the engine itself, it's called pgsql-parser. It's a binding to the real C parser, though, so to use it in the dashboard we need to access it via an API call, which may introduce too much latency to be useful.

Possible solutions on that front:

  1. Fork the repo and convert the binding to one based on a WASM compilation of the C parser, allowing us to run it client side.
  2. Create a new project that uses pgsql-parser only as a guide to create a WASM compilation of the C parser. (Similar to above, but if we decide that it's more work to convert the project than to greenfield one.)
  3. We grab our high perf parser code from Alan (I call it high perf because in Javascript it's faster than ANTLR even in its native Java, though the API is more awkward, tbh) and write a parser for Postgres SELECT, INSERT, UPDATE, and DELETE statements, and just fall back to the current prefix matching on all keywords on parse failure.
  4. Find an existing JS SQL parser that may or may not perfectly match Postgres and go with that, possibly failing more often.
  5. Implement a super simple line-by-line-only parser that only narrows down the set of keywords based on the class of the keyword (column name, table name, value, etc) expected since SELECT statements unfortunately put the column selection before the table selection so restricting to just columns of a table you don't know yet is impossible.

I'm sure there's others, but we could also consider this list backwards in order of improvements we can make, and decide on a set to follow (eg, first 5, then 4, then 2).

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

No branches or pull requests

3 participants