Skip to content

Commit

Permalink
bigquery: account for REPEATED mode in generating schema types
Browse files Browse the repository at this point in the history
  • Loading branch information
cgsheeh committed Oct 30, 2024
1 parent 11ae861 commit ffe8326
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,14 @@ def get_last_run_timestamp(bq_client: bigquery.Client) -> Optional[datetime]:
def load_table_schema(bq_client: bigquery.Client, table_id: str) -> dict[str, str]:
"""Load a mapping of `field` -> `bigquery type` for the given table."""
table = bq_client.get_table(table_id)
return {field.name: field.field_type for field in table.schema}
return {
field.name: (
field.field_type
if field.mode != "REPEATED"
else f"ARRAY<{field.field_type}>"
)
for field in table.schema
}


def load_table_schemas(bq_client: bigquery.Client) -> dict[str, dict[str, str]]:
Expand Down

0 comments on commit ffe8326

Please sign in to comment.