diff --git a/ibis/backends/duckdb/__init__.py b/ibis/backends/duckdb/__init__.py index 6341605849b7..f1e2f647b156 100644 --- a/ibis/backends/duckdb/__init__.py +++ b/ibis/backends/duckdb/__init__.py @@ -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 @@ -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) diff --git a/ibis/backends/pyspark/__init__.py b/ibis/backends/pyspark/__init__.py index 11c62f290441..0ea49d20b2bc 100644 --- a/ibis/backends/pyspark/__init__.py +++ b/ibis/backends/pyspark/__init__.py @@ -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 @@ -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 diff --git a/ibis/backends/sql/compilers/base.py b/ibis/backends/sql/compilers/base.py index c2e446c781b2..d89aa2b40e0c 100644 --- a/ibis/backends/sql/compilers/base.py +++ b/ibis/backends/sql/compilers/base.py @@ -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 +else: + + def AlterTable(*args, kind="TABLE", **kwargs): + return Alter(*args, kind=kind, **kwargs) + + if TYPE_CHECKING: from collections.abc import Callable, Iterable, Mapping diff --git a/ibis/backends/trino/__init__.py b/ibis/backends/trino/__init__.py index f7af4c493649..858bc4b21e27 100644 --- a/ibis/backends/trino/__init__.py +++ b/ibis/backends/trino/__init__.py @@ -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 @@ -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)], diff --git a/poetry.lock b/poetry.lock index c8065dbeb512..8f20b2c5c214 100644 --- a/poetry.lock +++ b/poetry.lock @@ -6855,13 +6855,13 @@ sqlcipher = ["sqlcipher3_binary"] [[package]] name = "sqlglot" -version = "25.10.0" +version = "25.11.0" description = "An easily customizable SQL parser and transpiler" optional = false python-versions = ">=3.7" files = [ - {file = "sqlglot-25.10.0-py3-none-any.whl", hash = "sha256:81207467262981aed6cb1586c8cea47778425a8b54f5ad57ec28b37e3b3c5314"}, - {file = "sqlglot-25.10.0.tar.gz", hash = "sha256:131d47163696228201224504e5a8c9f189134e9acece4c6336bb8534bd08b906"}, + {file = "sqlglot-25.11.0-py3-none-any.whl", hash = "sha256:e706520a35f8bcfe601633071af5d2257b9b57873dca8a519714b8382798e1b9"}, + {file = "sqlglot-25.11.0.tar.gz", hash = "sha256:d513adb63a16db74907079c91e43c371aed48e16567e0083819e03b173f96709"}, ] [package.extras] @@ -7848,4 +7848,4 @@ visualization = ["graphviz"] [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "66a9f3e233a8309199b17428b22540f69238891d67a0d910b9661f5a380e56ec" +content-hash = "565e2c694e22803168f82a3f26bfc522a0c29920af5b18beb7f4a5d6063e972e" diff --git a/pyproject.toml b/pyproject.toml index 1ada3c55b924..3144d0aa208e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,7 @@ atpublic = ">=2.3,<6" parsy = ">=2,<3" python-dateutil = ">=2.8.2,<3" pytz = ">=2022.7" -sqlglot = ">=23.4,<25.11" +sqlglot = ">=23.4,<25.12" toolz = ">=0.11,<1" typing-extensions = ">=4.3.0,<5" numpy = { version = ">=1.23.2,<3", optional = true } diff --git a/requirements-dev.txt b/requirements-dev.txt index e199f1575225..52ba9892ab62 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -257,7 +257,7 @@ sortedcontainers==2.4.0 ; python_version >= "3.10" and python_version < "4.0" soupsieve==2.5 ; python_version >= "3.10" and python_version < "3.13" sphobjinv==2.3.1.1 ; python_version >= "3.10" and python_version < "3.13" sqlalchemy==2.0.32 ; python_version >= "3.10" and python_version < "3.13" -sqlglot==25.10.0 ; python_version >= "3.10" and python_version < "4.0" +sqlglot==25.11.0 ; python_version >= "3.10" and python_version < "4.0" stack-data==0.6.3 ; python_version >= "3.10" and python_version < "4.0" statsmodels==0.14.2 ; python_version >= "3.10" and python_version < "3.13" tabulate==0.9.0 ; python_version >= "3.10" and python_version < "3.13"