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

Precompile SQL as PRQL #6040

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Precompile SQL as PRQL #6040

wants to merge 2 commits into from

Conversation

aljazerzen
Copy link
Contributor

@aljazerzen aljazerzen commented Sep 11, 2023

Proof of concept of PRQL support in EdgeDB.

Compiles prqlc from source via cargo and provides a cpython extension module edb._prql. Alternatively, we could use prql-python package from PyPi, which comes with prqlc precompiled, but this limits supported architectures and has a restricted API.

➜  edgedb git:(prql-sql) ✗ edb cli
EdgeDB 4.0-dev.7779+local (repl 3.5.0-dev)
Applied /home/aljaz/.config/edgedb/cli.toml configuration file
Type \help for help, \quit to quit.
edgedb> insert Post { title := 'hello world' };
edgedb> configure current database set allow_bare_ddl := 'AlwaysAllow';
OK: CONFIGURE DATABASE
edgedb> create type Movie {
....... create property title: str;
....... create property release_year: int32;
....... };
OK: CREATE TYPE
edgedb> insert Movie { title := "Hello world", release_year := 2014 };
{Object {id: 24f1c89e-5092-11ee-aad6-73d5cf1de13c}}
edgedb> insert Movie { title := "Hell over the world", release_year := 2020 };
{Object {id: 2c44ed92-5092-11ee-aad6-d7c93fe6cb80}}
edgedb>
➜  edgedb git:(prql-sql) ✗ psql -h localhost -p 5656 -U edgedb -d edgedb
psql (14.8, server 13.9)
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.

edgedb=# from Movie | select {id, title, release_year} #;
                  id                  |        title        | release_year
--------------------------------------+---------------------+--------------
 24f1c89e-5092-11ee-aad6-73d5cf1de13c | Hello world         |         2014
 2c44ed92-5092-11ee-aad6-d7c93fe6cb80 | Hell over the world |         2020
(2 rows)

edgedb=#

(psql is looking for ; to issue the query, but ; is invalid PRQL. As a workaround, one can end queries with a comment #;)

TODO:

  • some kind of switch to enable PRQL compiler (currently all queries over the pgsql wire protocol are treated as PRQL)
  • figure out why the edb._prql cpython extension is 256MB, instead of, say, 23MB (which is the size of edb._edgeql_parser). It's probably just the debug symbols because --release build of the cli is 17MB.
  • error handling - right now, error messages are converted to JSON and thrown as ValueError, which should be caught and converted into edb.errors.Error

Possible improvements:

  • for better UX, edgedb could generate table definitions, so prqlc would have the information about what columns exist and what are their types. This would allow it to fail early, before passing SQL to Posrgres, which reports errors within the generated SQL, not PRQL source.

@aljazerzen aljazerzen marked this pull request as draft September 11, 2023 11:11
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

Successfully merging this pull request may close these issues.

None yet

1 participant