Skip to content

Commit

Permalink
bigquery: map type names to their correct values
Browse files Browse the repository at this point in the history
Why Google made these different is beyond me.
  • Loading branch information
cgsheeh committed Oct 31, 2024
1 parent 97d1854 commit 74b9d73
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,18 @@ def get_time_queries(now: datetime, bq_client: bigquery.Client) -> list:
return queries


BIGQUERY_TYPE_MAPPING = {
"STRING": "STRING",
"INTEGER": "INT64",
"FLOAT": "FLOAT64",
"BOOLEAN": "BOOL",
"TIMESTAMP": "TIMESTAMP",
"DATE": "DATE",
"DATETIME": "DATETIME",
"TIME": "TIME",
}


def merge_into_bigquery(
bq_client: bigquery.Client,
table_id: str,
Expand All @@ -513,12 +525,16 @@ def merge_into_bigquery(

query_parameters = [
bigquery.ScalarQueryParameter(
"id", table_schema_mapping[id_column].field_type, row[id_column]
"id",
BIGQUERY_TYPE_MAPPING[table_schema_mapping[id_column].field_type],
row[id_column],
)
] + [
(
bigquery.ScalarQueryParameter(
f"param_{key}", table_schema_mapping[key].field_type, field
f"param_{key}",
BIGQUERY_TYPE_MAPPING[table_schema_mapping[key].field_type],
field,
)
if table_schema_mapping[key].mode != "REPEATED"
# Use the `ArrayQueryParameter` for `REPEATED` mode fields.
Expand Down

0 comments on commit 74b9d73

Please sign in to comment.