-
Notifications
You must be signed in to change notification settings - Fork 608
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
feat: support table.sql() for Polars #8525
Comments
Thanks for the issue. Can you paste in a copy-pastable example 😁 |
We can't support anything but the most trivial queries until Polars has support for CTEs (common table expressions). I'll put up a draft PR to demonstrate the issue. |
updated -- the PR works for the example I want to use for docs |
looks like two relevant (currently open) issues in Polars:
|
The |
It does seem to work in 0.20.13:
|
We've had basic (non-recursive) CTE support1 for about a year now 😉👌 Footnotes |
hi @alexander-beedie! I did ask here, but while you're here do you know if Polars is following any specific SQL dialect or doing its own thing? I'm mainly curious 1) if/when the SQL interface would catch up to the dataframe interface and 2) if it'd be easy to use SQLGlot via one of the existing dialects to interface with it |
Polars doesn't seem to handle quoted identifiers. That's the main reason for the extremely limited support for SQL operations using the polars backend in Ibis. |
@lostmygithubaccount: We aim to follow PostgreSQL for the majority of standard SQL syntax; not everything fits there of course, so then we try to obey the "principle of least surprise" ;) (For example, there is no standard PostgreSQL function for
No fixed target for that, but it's continuing to build out - yesterday's release added a few more functions ( If you are being held back by lack of some specific function/syntax though, please raise an Issue directly with us, as that can help prioritise what gets added next 👍 |
@cpcloud: Sure we do; got a specific instance where it goes wrong? If so, please let us know - if there's a bug but nobody reports it, we'll have quite a hard time fixing it. Feel free to tag me in an Issue/bug-report so I can take a look ;) For example, the following query uses quoted table, column, and alias identifiers without issue: df = pl.DataFrame({
"name": ["John","Mark","Steve","Bob"],
"surname": ["Smith","Jones","Smith","Smith"],
})
with pl.SQLContext(employees=df) as ctx:
res = ctx.execute(
"""
SELECT "employees"."surname", COUNT(*) AS "n"
FROM "employees"
GROUP BY "surname"
"""
).collect()
# shape: (2, 2)
# ┌─────────┬─────┐
# │ surname ┆ n │
# │ --- ┆ --- │
# │ str ┆ u32 │
# ╞═════════╪═════╡
# │ Jones ┆ 1 │
# │ Smith ┆ 3 │
# └─────────┴─────┘ |
@alexander-beedie Here you go:
|
Got it; fixed with a one-liner - exclusively impacted CTE identifier names. |
Also, will follow up on this one; I just delved into the docs and was faintly horrified to see that PostgreSQL does actually claim to support grouping by1 ordinal position values - which seems genuinely horrible (not self-documenting, and presumably shockingly fragile, but... valid syntax nevertheless!) 🤣 Footnotes |
It's a nice syntax for SQL-generating libraries to avoid repeating large group by expressions. It's used a lot more than you'd think. |
FYI: the upcoming Update: released... |
Version bump here: #8960. Will get shipped in the next Ibis release in a week or so. |
FYI: ordinal support for the |
Is your feature request related to a problem?
con.sql()
is implemented, buttable.sql()
is not:Describe the solution you'd like
support
table.sql()
with the Polars backendthis is mainly useful to me for consistency in example code for the documentation
What version of ibis are you running?
main
What backend(s) are you using, if any?
Polars
Code of Conduct
The text was updated successfully, but these errors were encountered: