GithubHelp home page GithubHelp logo

Comments (5)

max-sixty avatar max-sixty commented on June 10, 2024 1

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]
   │
 1frm 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.

max-sixty avatar max-sixty commented on June 10, 2024 1

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.

brunorpinho avatar brunorpinho commented on June 10, 2024

@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.

max-sixty avatar max-sixty commented on June 10, 2024

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.

max-sixty avatar max-sixty commented on June 10, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.