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: Use dataset_id & table_id as the key of set 'grouped_tables' in bigquery_metadata_extractor #421

Merged
merged 1 commit into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions databuilder/extractor/base_bigquery_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class BaseBigQueryExtractor(Extractor):
DEFAULT_PAGE_SIZE = 300
NUM_RETRIES = 3
DATE_LENGTH = 8
SHARDED_TABLE_KEY_FORMAT = '{dataset_id}/{table_id}'

def init(self, conf: ConfigTree) -> None:
# should use key_path, or cred_key if the former doesn't exist
Expand Down
9 changes: 6 additions & 3 deletions databuilder/extractor/bigquery_metadata_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@ def _retrieve_tables(self, dataset: DatasetRef) -> Any:
# If the last eight characters are digits, we assume the table is of a table date range type
# and then we only need one schema definition
table_prefix = table_id[:-BigQueryMetadataExtractor.DATE_LENGTH]
if table_prefix in self.grouped_tables:
table_id = table_prefix
sharded_table_key = BigQueryMetadataExtractor.SHARDED_TABLE_KEY_FORMAT.format(
dataset_id=tableRef['datasetId'],
table_id=table_id)
if sharded_table_key in self.grouped_tables:
# If one table in the date range is processed, then ignore other ones
# (it adds too much metadata)
continue

table_id = table_prefix
self.grouped_tables.add(table_prefix)
self.grouped_tables.add(sharded_table_key)

table = self.bigquery_service.tables().get(
projectId=tableRef['projectId'],
Expand Down