Skip to content

Commit

Permalink
fix: Fix generating BQ views for IDC dataset (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
adlersantos committed Apr 5, 2022
1 parent afa6492 commit 5896865
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions datasets/idc/pipelines/_images/generate_bq_views/script.py
Expand Up @@ -51,14 +51,17 @@ def main(
source_view = client.get_table(
f"{source_project}.{dataset}.{table.table_id}"
)
create_or_update_view(client, source_view, target_project)
create_or_update_view(client, source_view, source_project, target_project)
source_views.append(table.table_id)

sync_views(client, dataset, source_views, target_project)


def create_or_update_view(
client: bigquery.Client, source_view: bigquery.Table, target_project: str
client: bigquery.Client,
source_view: bigquery.Table,
source_project: str,
target_project: str,
) -> None:
try:
target_view = client.get_table(
Expand All @@ -71,7 +74,7 @@ def create_or_update_view(
f"{target_project}.{source_view.dataset_id}.{source_view.table_id}"
)
_view.description = source_view.description
_view.view_query = source_view.view_query
_view.view_query = source_view.view_query.replace(source_project, target_project)

# Create the view if it doesn't exist. Otherwise, update it.
if not target_view:
Expand Down

0 comments on commit 5896865

Please sign in to comment.