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

[DC-3643] Remove bq_utils.create_dataset() from project #1849

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
42 changes: 0 additions & 42 deletions data_steward/bq_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,45 +1010,3 @@ def has_primary_key(table):
id_field = table + '_id'
return any(field for field in fields
if field['type'] == 'integer' and field['name'] == id_field)


@deprecated(reason='create_snapshot_dataset is deprecated')
def create_snapshot_dataset(project_id, dataset_id, snapshot_dataset_id):
"""

:param dataset_id:
:param project_id:
:param snapshot_dataset_id:
:return:
"""
dataset_result = create_dataset(project_id=project_id,
dataset_id=snapshot_dataset_id,
description=f'Snapshot of {dataset_id}',
overwrite_existing=True)
validation_dataset = dataset_result.get(bq_consts.DATASET_REF, {})
snapshot_dataset_id = validation_dataset.get(bq_consts.DATASET_ID, '')
# Create the empty tables in the new snapshot dataset
for table_id in list_all_table_ids(dataset_id):
metadata = get_table_info(table_id, dataset_id)
fields = metadata['schema']['fields']
create_table(table_id,
fields,
drop_existing=True,
dataset_id=snapshot_dataset_id)
# Copy the table content from the current dataset to the snapshot dataset
copy_table_job_ids = []
for table_id in list_all_table_ids(dataset_id):
select_all_query = (
'SELECT * FROM `{project_id}.{dataset_id}.{table_id}` ')
q = select_all_query.format(project_id=project_id,
dataset_id=dataset_id,
table_id=table_id)
results = query(q,
use_legacy_sql=False,
destination_table_id=table_id,
destination_dataset_id=snapshot_dataset_id,
batch=True)
copy_table_job_ids.append(results['jobReference']['jobId'])
incomplete_jobs = wait_on_jobs(copy_table_job_ids)
if len(incomplete_jobs) > 0:
raise BigQueryJobWaitError(incomplete_jobs)