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

fix: Fix generating BQ views for IDC dataset #324

Merged
merged 1 commit into from
Apr 5, 2022
Merged
Changes from all commits
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
9 changes: 6 additions & 3 deletions datasets/idc/pipelines/_images/generate_bq_views/script.py
Original file line number Diff line number Diff line change
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