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

Jupysql overrides Databricks %sql magic despite alias #1047

Closed
danielsparing opened this issue Feb 6, 2025 · 2 comments · Fixed by #1048
Closed

Jupysql overrides Databricks %sql magic despite alias #1047

danielsparing opened this issue Feb 6, 2025 · 2 comments · Fixed by #1048

Comments

@danielsparing
Copy link

What happens?

In Databricks, once jupysql is loaded, the original Databricks %sql magics are unusable, even though the docs say "you can use both".

Probably in a Databricks enviromnent only the %jupysql alias should be added.

To Reproduce

In a Databricks notebook:

%pip install jupysql --quiet

%load_ext sql
%sql
select 1
# Returns UsageError: No active connection.

The above error hints that %sql was trying to call jupysql.

OS:

Linux

JupySQL Version:

0.10.17

Full Name:

Daniel Sparing

Affiliation:

Goudappel

@edublancas
Copy link

edublancas commented Feb 6, 2025

shouldn't be too hard to do it. perhaps we can look at some env var to detect the databricks environment. worst case we can add a manual flag

either we can dynamically add the magic names, or add both and remove sql here

the latter seems to work:

In [1]: from sql.magic import SqlMagic

In [2]: del SqlMagic.magics["cell"]["sql"]

In [3]: del SqlMagic.magics["line"]["sql"]

In [4]: %load_ext sql

In [5]: %sql
UsageError: Line magic function `%sql` not found.

In [6]: %jupysql
UsageError: No active connection.

To fix it:

Pass a valid connection string:
    Example: %sql postgresql://username:password@hostname/dbname

OR

Set the environment variable $DATABASE_URL

For more details, see: https://jupysql.ploomber.io/en/latest/connecting.html
If you need help solving this issue, send us a message: https://ploomber.io/community

In [7]:

I just had to modify set_configs to loadjupysql instead of sql, since `jupysql will always be present.

PRs welcome!

@danielsparing
Copy link
Author

Thanks!

I did put it in a PR, successfully tested it in Colab and Databricks, but haven't actually written any tests as there I wouldn't even know where to start.

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 a pull request may close this issue.

2 participants