Skip to content

Commit

Permalink
fix(sqlglot): workaround breaking change to rename AlterTable to `A…
Browse files Browse the repository at this point in the history
…lter`
  • Loading branch information
cpcloud committed Aug 15, 2024
1 parent 3731100 commit 9bdc66c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions ibis/backends/duckdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from ibis.backends import CanCreateDatabase, CanCreateSchema, UrlFromPath
from ibis.backends.duckdb.converter import DuckDBPandasData
from ibis.backends.sql import SQLBackend
from ibis.backends.sql.compilers.base import STAR, C
from ibis.backends.sql.compilers.base import STAR, AlterTable, C
from ibis.common.dispatch import lazy_singledispatch
from ibis.expr.operations.udf import InputType
from ibis.util import deprecated
Expand Down Expand Up @@ -236,7 +236,7 @@ def create_table(
)
else:
cur.execute(
sge.AlterTable(
AlterTable(
this=initial_table,
actions=[sge.RenameTable(this=final_table)],
).sql(self.name)
Expand Down
7 changes: 3 additions & 4 deletions ibis/backends/pyspark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from ibis.backends.pyspark.converter import PySparkPandasData
from ibis.backends.pyspark.datatypes import PySparkSchema, PySparkType
from ibis.backends.sql import SQLBackend
from ibis.backends.sql.compilers.base import AlterTable
from ibis.expr.operations.udf import InputType
from ibis.legacy.udf.vectorized import _coerce_to_series
from ibis.util import deprecated
Expand Down Expand Up @@ -659,10 +660,8 @@ def rename_table(self, old_name: str, new_name: str) -> None:
"""
old = sg.table(old_name, quoted=True)
new = sg.table(new_name, quoted=True)
query = sge.AlterTable(
this=old,
exists=False,
actions=[sge.RenameTable(this=new, exists=True)],
query = AlterTable(
this=old, exists=False, actions=[sge.RenameTable(this=new, exists=True)]
)
with self._safe_raw_sql(query):
pass
Expand Down
10 changes: 10 additions & 0 deletions ibis/backends/sql/compilers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
from ibis.expr.operations.udf import InputType
from ibis.expr.rewrites import lower_stringslice

try:
from sqlglot.expressions import Alter
except ImportError:
from sqlglot.expressions import AlterTable

Check warning on line 39 in ibis/backends/sql/compilers/base.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/sql/compilers/base.py#L38-L39

Added lines #L38 - L39 were not covered by tests
else:

def AlterTable(*args, kind="TABLE", **kwargs):
return Alter(*args, kind=kind, **kwargs)


if TYPE_CHECKING:
from collections.abc import Callable, Iterable, Mapping

Expand Down
4 changes: 2 additions & 2 deletions ibis/backends/trino/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from ibis import util
from ibis.backends import CanCreateDatabase, CanCreateSchema, CanListCatalog
from ibis.backends.sql import SQLBackend
from ibis.backends.sql.compilers.base import C
from ibis.backends.sql.compilers.base import AlterTable, C

if TYPE_CHECKING:
from collections.abc import Iterator, Mapping
Expand Down Expand Up @@ -514,7 +514,7 @@ def create_table(

# rename the new table to the original table name
cur.execute(
sge.AlterTable(
AlterTable(
this=table_ref,
exists=True,
actions=[sge.RenameTable(this=orig_table_ref, exists=True)],
Expand Down

0 comments on commit 9bdc66c

Please sign in to comment.