in scripts/copy_bigquery_data.py [0:0]
def run_bq_query(sql: str) -> Union[str, pd.DataFrame]:
"""
Input: SQL query, as a string, to execute in BigQuery
Returns the query results as a pandas DataFrame, or error, if any
"""
from google.cloud import bigquery
bq_client = bigquery.Client()
# Try dry run before executing query to catch any errors
job_config = bigquery.QueryJobConfig(dry_run=True, use_query_cache=False)
bq_client.query(sql, job_config=job_config)
# If dry run succeeds without errors, proceed to run query
job_config = bigquery.QueryJobConfig()
client_result = bq_client.query(sql, job_config=job_config)
job_id = client_result.job_id
# Wait for query/job to finish running. then get & return data frame
df = client_result.result().to_arrow().to_pandas()
return df