in backfill/2023-09-26-initialize-clients_first_seen_v2/bigquery_etl_cli_query.py [0:0]
def _attach_metadata(query_file_path: Path, table: bigquery.Table) -> None:
"""Add metadata from query file's metadata.yaml to table object."""
try:
metadata = Metadata.of_query_file(query_file_path)
except FileNotFoundError:
return
table.description = metadata.description
table.friendly_name = metadata.friendly_name
if metadata.bigquery and metadata.bigquery.time_partitioning:
table.time_partitioning = bigquery.TimePartitioning(
metadata.bigquery.time_partitioning.type.bigquery_type,
field=metadata.bigquery.time_partitioning.field,
require_partition_filter=(
metadata.bigquery.time_partitioning.require_partition_filter
),
expiration_ms=metadata.bigquery.time_partitioning.expiration_ms,
)
if metadata.bigquery and metadata.bigquery.clustering:
table.clustering_fields = metadata.bigquery.clustering.fields
# BigQuery only allows for string type labels with specific requirements to be published:
# https://cloud.google.com/bigquery/docs/labels-intro#requirements
if metadata.labels:
table.labels = {
key: value
for key, value in metadata.labels.items()
if isinstance(value, str)
}