-
Notifications
You must be signed in to change notification settings - Fork 172
enh: Introduce narwhals.sql
#3254
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
base: main
Are you sure you want to change the base?
Conversation
narwhals/sql.py
Outdated
| CREATE TABLE "{name}" | ||
| ({dtypes}); | ||
| """) | ||
| return from_native(CONN.table(name)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π€ maybe this could return a subclass of LazyFrame which has a to_sql method, with an optional dependency on sqlglot if people want to pass dialect != 'duckdb' or pretty=True
| try: | ||
| import duckdb # ignore-banned-import | ||
| except ImportError as _exc: # pragma: no cover | ||
| msg = ( | ||
| "`narwhals.sql` requires DuckDB to be installed.\n\n" | ||
| "Hint: run `pip install -U narwhals[sql]`" | ||
| ) | ||
| raise ModuleNotFoundError(msg) from _exc | ||
|
|
||
| CONN = duckdb.connect() | ||
| TZ = DeferredTimeZone( | ||
| CONN.sql("select value from duckdb_settings() where name = 'TimeZone'") | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think (hope?) that in the future we could make a narwhals-sqlglot or narwhals-substrait plugin and use that here. But for now, I think using DuckDB for this is quite nice
What type of PR is this? (check all applicable)
Related issues
Checklist
If you have comments or can explain your changes, please do so below