Comments (5)
Yes, I could see a couple of approaches:
Another function — prql_to_sql
prql_to_sql
function that is similar to compile
, but raises an error as pure JSON. It would operate similarly to prql_to_pl
, which gives a long string of JSON:
prql.prql_to_pl("^")
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[12], line 1
----> 1 prql.prql_to_pl("^")
ValueError: {"inner":[{"kind":"Error","code":null,"reason":"unexpected ^","hints":[],"span":"1:0-1","display":"Error: \n ╭─[:1:1]\n │\n 1 │ ^\n │ ┬ \n │ ╰── unexpected ^
\n───╯\n","location":{"start":[0,0],"end":[0,1]}}]}
...rather than a nice Error message:
prql.compile("frm artists")
Traceback (most recent call last):
File /opt/homebrew/lib/python3.9/site-packages/IPython/core/interactiveshell.py:3508 in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
Cell In[3], line 1
prql.compile("frm artists")
File <string>
SyntaxError: Error:
╭─[:1:1]
│
1 │ frm artists
│ ─┬─
│ ╰─── Unknown name
───╯
I think this could be a quite small PR.
Add the JSON onto the Exception
Browsing the PyO3 docs, I think we could return an exception which has a .json
attribute which contains the JSON.
This would be the nicer approach but is a bit more work / requires a bit of work with PyO3...
Edit: I guess the even better thing would be a custom error type which contained the fields — rather than JSON — and then has a string representation with the full error message. But that's a bit more work yet.
Any thoughts from others?
from prql.
The basic version of this is implemented in #4066; @brunorpinho let me know if that works for you.
I'll close, but we can come back when the next version of PyO3 is out and see if we can do this more elegantly.
from prql.
@max-sixty it absolutely works, all I would need for my use case is that json. Thank you!
Which version of prql am I expected to see this implemented?
from prql.
Which version of prql am I expected to see this implemented?
It would be in the next release, which we could do quite soon if it'd be helpful. You can also use the version on main
with pip install git+https://github.com/PRQL/prql#subdirectory=prqlc/bindings/python
from prql.
@brunorpinho instead of doing that, use something like this:
try:
x = prql_to_pl(query)
x = pl_to_rq(x)
x = rq_to_sql(x)
except Exception as e:
json_exception = e
...and then in the future, we'll change compile
to have the information on the object itself.
(I'm planning to revert prql_to_sql
as it doesn't add much that's useful beyond the snippet above...)
from prql.
Related Issues (20)
- Some aggregation functions need ORDER BY clause
- Unexpected result with s-string including UNNEST HOT 2
- Nightly tests failed HOT 1
- Nightly tests failed HOT 1
- RUSTSEC-2024-0336: `rustls::ConnectionCommon::complete_io` could fall into an infinite loop based on network input HOT 1
- Nightly tests failed
- Nightly tests failed
- Nightly tests failed HOT 1
- Compiler crash on `from_text` with zero rows HOT 4
- unexpected error on non-prql file HOT 1
- Add sampling extension support to PRQL HOT 3
- DISTINCT ON does not ensure columns exist HOT 1
- [Docker] the 'cargo' binary ... is not applicable to the '1.77.2-aarch64-unknown-linux-gnu' toolchain HOT 3
- Arrow type system as base for the type system HOT 1
- 'std' panics on lowering HOT 4
- Dev Container: can't run playground or book (can run website) HOT 24
- Incorrect Postgres interval syntax HOT 4
- Query optimization: join prunning and "uniqeness" HOT 3
- std.in operator does not support expression on left-hand-side HOT 2
- Named Unions as function parameters HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prql.