Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for BigQuery relation renaming #2521

Merged
merged 6 commits into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Added a "docs" field to macros, with a "show" subfield to allow for hiding macros from the documentation site ([#2430](https://github.com/fishtown-analytics/dbt/issues/2430))
- Added intersection syntax for model selector ([#2167](https://github.com/fishtown-analytics/dbt/issues/2167), [#2417](https://github.com/fishtown-analytics/dbt/pull/2417))
- Extends model selection syntax with at most n-th parent/children `dbt run --models 3+m1+2` ([#2052](https://github.com/fishtown-analytics/dbt/issues/2052), [#2485](https://github.com/fishtown-analytics/dbt/pull/2485))
- Added support for renaming BigQuery relations ([#2520](https://github.com/fishtown-analytics/dbt/issues/2520), [#2521](https://github.com/fishtown-analytics/dbt/pull/2521))

### Fixes
- Fixed an error in create_adapter_plugins.py script when -dependency arg not passed ([#2507](https://github.com/fishtown-analytics/dbt/issues/2507), [#2508](https://github.com/fishtown-analytics/dbt/pull/2508))
Expand All @@ -14,7 +15,8 @@ Contributors:
- [@raalsky](https://github.com/Raalsky) ([#2417](https://github.com/fishtown-analytics/dbt/pull/2417), [#2485](https://github.com/fishtown-analytics/dbt/pull/2485))
- [@alf-mindshift](https://github.com/alf-mindshift) ([#2431](https://github.com/fishtown-analytics/dbt/pull/2431))
- [@scarrucciu](https://github.com/scarrucciu) ([#2508](https://github.com/fishtown-analytics/dbt/pull/2508))
- [@southpolemonkey](https://github.com/southpolemonkey)([#2511](https://github.com/fishtown-analytics/dbt/issues/2511))
- [@southpolemonkey](https://github.com/southpolemonkey)([#2511](https://github.com/fishtown-analytics/dbt/issues/2511))
- [@azhard](https://github.com/azhard) ([#2521](https://github.com/fishtown-analytics/dbt/pull/2521)

## dbt 0.17.0 (June 08, 2020)

Expand Down
24 changes: 21 additions & 3 deletions plugins/bigquery/dbt/adapters/bigquery/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,27 @@ def truncate_relation(self, relation: BigQueryRelation) -> None:
def rename_relation(
self, from_relation: BigQueryRelation, to_relation: BigQueryRelation
) -> None:
raise dbt.exceptions.NotImplementedException(
'`rename_relation` is not implemented for this adapter!'
)
self.cache_renamed(from_relation, to_relation)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this down to just before the copy/delete calls? I think we want to avoid updating the cache until we're just about to do it, if possible.


conn = self.connections.get_thread_connection()
client = conn.handle

from_table_ref = self.connections.table_ref(from_relation.database,
from_relation.schema,
from_relation.identifier,
conn)
from_table = client.get_table(from_table_ref)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also ensure that from_relation.type and to_relation.type are the same type? And that to_relation.type is not RelationType.View?

if from_table.table_type == "VIEW":
raise dbt.exceptions.RuntimeException(
'Renaming of views is not currently supported in BigQuery'
)

to_table_ref = self.connections.table_ref(to_relation.database,
to_relation.schema,
to_relation.identifier,
conn)
client.copy_table(from_table_ref, to_table_ref)
client.delete_table(from_table_ref)

@available
def list_schemas(self, database: str) -> List[str]:
Expand Down
4 changes: 4 additions & 0 deletions plugins/bigquery/dbt/include/bigquery/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,7 @@
{% macro bigquery__alter_column_comment(relation, column_dict) -%}
{% do adapter.update_column_descriptions(relation, column_dict) %}
{% endmacro %}

{% macro bigquery__rename_relation(from_relation, to_relation) -%}
{% do adapter.rename_relation(from_relation, to_relation) %}
{% endmacro %}