Skip to content

Commit

Permalink
feat(api): add Backend.rename_table
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrist authored and cpcloud committed Aug 29, 2023
1 parent f2d3245 commit 0047143
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
14 changes: 14 additions & 0 deletions ibis/backends/base/__init__.py
Expand Up @@ -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,
Expand Down
26 changes: 14 additions & 12 deletions ibis/backends/tests/test_client.py
Expand Up @@ -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"])
Expand Down

0 comments on commit 0047143

Please sign in to comment.