From 00471430fd25c8fb16b1f6b9531494156180dec8 Mon Sep 17 00:00:00 2001 From: Jim Crist-Harif Date: Tue, 29 Aug 2023 16:02:49 -0500 Subject: [PATCH] feat(api): add `Backend.rename_table` --- ibis/backends/base/__init__.py | 14 ++++++++++++++ ibis/backends/tests/test_client.py | 26 ++++++++++++++------------ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/ibis/backends/base/__init__.py b/ibis/backends/base/__init__.py index 92466828f7f2..38ed28114b5a 100644 --- a/ibis/backends/base/__init__.py +++ b/ibis/backends/base/__init__.py @@ -1000,6 +1000,20 @@ def drop_table( f'Backend "{self.name}" does not implement "drop_table"' ) + def rename_table(self, old_name: str, new_name: str) -> None: + """Rename an existing table. + + Parameters + ---------- + old_name + The old name of the table. + new_name + The new name of the table. + """ + raise NotImplementedError( + f'Backend "{self.name}" does not implement "rename_table"' + ) + @abc.abstractmethod def create_view( self, diff --git a/ibis/backends/tests/test_client.py b/ibis/backends/tests/test_client.py index 8b7e535ba6f0..57aaef69bd98 100644 --- a/ibis/backends/tests/test_client.py +++ b/ibis/backends/tests/test_client.py @@ -251,26 +251,28 @@ def test_create_temporary_table_from_schema(tmpcon, new_schema): "clickhouse", "dask", "datafusion", + "druid", "duckdb", + "impala", + "mssql", "mysql", - "pandas", "oracle", + "pandas", + "polars", "postgres", - "sqlite", + "pyspark", "snowflake", - "polars", - "mssql", + "sqlite", "trino", ] ) -@mark.broken(["druid"], reason="sqlalchemy dialect is broken") -def test_rename_table(con, temp_table, temp_table_orig, new_schema): - con.create_table(temp_table_orig, schema=new_schema) - t = con.table(temp_table_orig) - t.rename(temp_table) - - assert con.table(temp_table) is not None - assert temp_table in con.list_tables() +def test_rename_table(con, temp_table, temp_table_orig): + schema = ibis.schema({"a": "string", "b": "bool", "c": "int32"}) + con.create_table(temp_table_orig, schema=schema) + con.rename_table(temp_table_orig, temp_table) + new = con.table(temp_table) + assert new.schema().equals(schema) + assert temp_table_orig not in con.list_tables() @mark.notimpl(["datafusion", "polars", "druid"])