Skip to content

Commit

Permalink
feat(impala): implement Backend.rename_table
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `ImpalaTable.rename` is removed, use `Backend.rename_table` instead.
  • Loading branch information
jcrist authored and cpcloud committed Aug 29, 2023
1 parent 0a8b201 commit 309c999
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 42 deletions.
14 changes: 14 additions & 0 deletions ibis/backends/impala/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
DropDatabase,
DropTable,
DropView,
RenameTable,
TruncateTable,
fully_qualified_re,
is_fully_qualified,
Expand Down Expand Up @@ -973,6 +974,19 @@ def truncate_table(self, name: str, database: str | None = None) -> None:
statement = TruncateTable(name, database=database)
self._safe_exec_sql(statement)

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.
"""
statement = RenameTable(old_name, new_name)
self._safe_exec_sql(statement)

def drop_table_or_view(self, name, *, database=None, force=False):
"""Drop view or table."""
try:
Expand Down
23 changes: 1 addition & 22 deletions ibis/backends/impala/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@
from ibis import util
from ibis.backends.base import Database
from ibis.backends.base.sql.compiler import DDL, DML
from ibis.backends.base.sql.ddl import (
AlterTable,
InsertSelect,
RenameTable,
fully_qualified_re,
)
from ibis.backends.base.sql.ddl import AlterTable, InsertSelect
from ibis.backends.impala import ddl
from ibis.backends.impala.compat import HS2Error, impyla

Expand Down Expand Up @@ -334,22 +329,6 @@ def load_data(self, path, overwrite=False, partition=None):
def name(self) -> str:
return self.op().name

def rename(self, new_name: str, database: str | None = None) -> ImpalaTable:
"""Rename table inside Impala.
References to the old table are no longer valid.
"""
m = fully_qualified_re.match(new_name)
if not m and database is None:
database = self._database
statement = RenameTable(
self.name, new_name, old_database=self._database, new_database=database
)
self._client._safe_exec_sql(statement)

op = self.op().copy(name=new_name, namespace=database)
return self.__class__(op)

@property
def is_partitioned(self):
"""True if the table is partitioned."""
Expand Down
19 changes: 0 additions & 19 deletions ibis/backends/impala/tests/test_ddl.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,25 +207,6 @@ def test_drop_view(con, created_view):
assert created_view not in con.list_tables()


def test_rename_table(con, temp_database):
tmp_db = temp_database

orig_name = "tmp_rename_test"
con.create_table(orig_name, con.table("region"))
table = con.table(orig_name)

old_name = table.name

new_name = "rename_test"
renamed = table.rename(new_name, database=tmp_db)
renamed.execute()

t = con.table(new_name, database=tmp_db)
assert_equal(renamed, t)

assert table.name == old_name


@pytest.fixture
def path_uuid():
return f"change-location-{util.guid()}"
Expand Down
1 change: 0 additions & 1 deletion ibis/backends/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ def test_create_temporary_table_from_schema(tmpcon, new_schema):
"datafusion",
"druid",
"duckdb",
"impala",
"mssql",
"mysql",
"oracle",
Expand Down

0 comments on commit 309c999

Please sign in to comment.