#requirements:
#google-cloud-bigquery
#pandas
#db-dtypes
import os
import json
from google.cloud import bigquery
# try with a query such as
"""
SELECT name, SUM(number) as total_people
FROM `bigquery-public-data.usa_names.usa_1910_2013`
WHERE state = 'TX'
GROUP BY name, state
ORDER BY total_people DESC
LIMIT 20
"""
gcp_service_account = dict
def main(sa: gcp_service_account, query: str):
sa_path = "/tmp/sa.json"
f = open(sa_path, "a")
f.write(json.dumps(sa))
f.close()
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = sa_path
client = bigquery.Client()
query_job = client.query(query)
return query_job.to_dataframe().values.tolist()
Submitted by rubenfiszel 692 days ago