|
15 | 15 |
|
16 | 16 | if t.TYPE_CHECKING: |
17 | 17 | import agate |
18 | | - import pandas as pd |
19 | 18 | from dbt.adapters.base import BaseRelation |
20 | 19 | from dbt.adapters.base.column import Column |
21 | 20 | from dbt.adapters.base.impl import AdapterResponse |
@@ -86,6 +85,10 @@ def drop_schema(self, relation: BaseRelation) -> None: |
86 | 85 | def drop_relation(self, relation: BaseRelation) -> None: |
87 | 86 | """Drops a relation (table) in the target database.""" |
88 | 87 |
|
| 88 | + @abc.abstractmethod |
| 89 | + def rename_relation(self, from_relation: BaseRelation, to_relation: BaseRelation) -> None: |
| 90 | + """Renames a relation (table) in the target database.""" |
| 91 | + |
89 | 92 | @abc.abstractmethod |
90 | 93 | def execute( |
91 | 94 | self, sql: str, auto_begin: bool = False, fetch: bool = False |
@@ -210,6 +213,9 @@ def drop_schema(self, relation: BaseRelation) -> None: |
210 | 213 | def drop_relation(self, relation: BaseRelation) -> None: |
211 | 214 | self._raise_parsetime_adapter_call_error("drop relation") |
212 | 215 |
|
| 216 | + def rename_relation(self, from_relation: BaseRelation, to_relation: BaseRelation) -> None: |
| 217 | + self._raise_parsetime_adapter_call_error("rename relation") |
| 218 | + |
213 | 219 | def execute( |
214 | 220 | self, sql: str, auto_begin: bool = False, fetch: bool = False |
215 | 221 | ) -> t.Tuple[AdapterResponse, agate.Table]: |
@@ -349,6 +355,12 @@ def drop_relation(self, relation: BaseRelation) -> None: |
349 | 355 | if relation.schema is not None and relation.identifier is not None: |
350 | 356 | self.engine_adapter.drop_table(self._normalize(self._relation_to_table(relation))) |
351 | 357 |
|
| 358 | + def rename_relation(self, from_relation: BaseRelation, to_relation: BaseRelation) -> None: |
| 359 | + old_table_name = self._normalize(self._relation_to_table(from_relation)) |
| 360 | + new_table_name = self._normalize(self._relation_to_table(to_relation)) |
| 361 | + |
| 362 | + self.engine_adapter.rename_table(old_table_name, new_table_name) |
| 363 | + |
352 | 364 | def execute( |
353 | 365 | self, sql: str, auto_begin: bool = False, fetch: bool = False |
354 | 366 | ) -> t.Tuple[AdapterResponse, agate.Table]: |
|
0 commit comments