Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ jobs:
- name: Lint
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade pkgmt codespell nox
python -m pip install --upgrade pkgmt nox
pkgmt lint
codespell

- name: Install dependencies
run: |
Expand All @@ -113,7 +112,7 @@ jobs:
nox --session test_unit --no-install --reuse-existing-virtualenvs

- name: Upload failed images artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: failure()
with:
name: failed-image-artifacts ${{ matrix.os }} ${{ matrix.python-version }}
Expand Down Expand Up @@ -158,7 +157,7 @@ jobs:
nox --session test_unit_sqlalchemy_one --no-install --reuse-existing-virtualenvs

- name: Upload failed images artifacts sqlalchemyv1
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: failure()
with:
name: failed-image-artifacts-sqlalchemy ${{ matrix.os }} ${{ matrix.python-version }}
Expand Down
1 change: 1 addition & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ conda:
sphinx:
builder: html
fail_on_warning: true
configuration: doc/_config.yml
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# CHANGELOG

## 0.10.18dev
## 0.11.0dev

* [API Change] Disabled `%sql` and `%%sql` on Databricks ([#1047](https://github.com/ploomber/jupysql/issues/1047))

## 0.10.17 (2025-01-08)

Expand Down
4 changes: 3 additions & 1 deletion doc/howto.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,9 @@ some_engine = create_engine("sqlite:///some.db")

## Use `%sql`/`%%sql` in Databricks

Databricks uses the same name (`%sql`/`%%sql`) for its SQL magics; however, JupySQL exposes a `%jupysql`/`%%jupysql` alias so you can use both:
Databricks uses the same name (`%sql`/`%%sql`) for its SQL magics; however, since this
clashes with Databricks' `%%sql` command, JupySQL will enable an `%jupysql`/`%%jupysql`
alias if a `DATABRICKS_RUNTIME_VERSION` is declared:

```{code-cell} ipython3
%jupysql duckdb://
Expand Down
3 changes: 1 addition & 2 deletions scripts/large-table-gen.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Renter large-table-template.sql
"""
"""Renter large-table-template.sql"""

from pathlib import Path
from jinja2 import Template
Expand Down
2 changes: 1 addition & 1 deletion src/sql/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from sql.magic import load_ipython_extension


__version__ = "0.10.18dev"
__version__ = "0.11.0dev"


__all__ = ["load_ipython_extension"]
1 change: 1 addition & 0 deletions src/sql/column_guesser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

class Column(list):
"Store a column of tabular data; record its name and whether it is numeric"

is_quantity = True
name = ""

Expand Down
9 changes: 8 additions & 1 deletion src/sql/magic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os
import re
from pathlib import Path

Expand Down Expand Up @@ -704,7 +705,7 @@ def get_query_type(command: str):

def set_configs(ip, file_path, alternate_path):
"""Set user defined SqlMagic configuration settings"""
sql = ip.find_cell_magic("sql").__self__
sql = ip.find_cell_magic("jupysql").__self__
user_configs, loaded_from = util.get_user_configs(file_path, alternate_path)
default_configs = util.get_default_configs(sql)
table_rows = []
Expand Down Expand Up @@ -769,6 +770,12 @@ def load_SqlMagic_configs(ip):

def load_ipython_extension(ip):
"""Load the magics, this function is executed when the user runs: %load_ext sql"""

# If running within Databricks, do not use the sql magics
if "DATABRICKS_RUNTIME_VERSION" in os.environ:
del SqlMagic.magics["cell"]["sql"]
del SqlMagic.magics["line"]["sql"]

sql_magic = SqlMagic(ip)
_set_sql_magic(sql_magic)
ip.register_magics(sql_magic)
Expand Down
26 changes: 26 additions & 0 deletions src/tests/test_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from sql.run.resultset import ResultSet
from sql import magic
from sql.warnings import JupySQLQuotedNamedParametersWarning
from sql._testing import TestingShell
from sql.magic import load_ipython_extension


from conftest import runsql
Expand Down Expand Up @@ -2767,3 +2769,27 @@ def test_disabled_named_parameters_shows_disabled_warning(ip):
)

assert expected_warning in str(excinfo.value)


@pytest.mark.skip(
reason=(
"Running this breaks all subsequent tests because "
"TestingShell is a singleton. We need to find a way to isolate this test"
)
)
def test_databricks_sql_magic_disabled(monkeypatch):
monkeypatch.setenv("DATABRICKS_RUNTIME_VERSION", "10.0.0")
ip = TestingShell.preconfigured_shell()
load_ipython_extension(ip)

ip.run_cell("%jupysql duckdb://")
ip.run_cell("%jupysql select 1")

with pytest.raises(UsageError) as excinfo_line:
ip.run_cell("%sql select 1")

with pytest.raises(UsageError) as excinfo_cell:
ip.run_cell("%%sql\nselect 1")

assert "Line magic function `%sql` not found" in str(excinfo_line.value)
assert "Cell magic `%%sql` not found" in str(excinfo_cell.value)
Loading