google-big-queryHow do I use a JSON service account with Google Big Query?
- To use a JSON service account with Google Big Query, you need to create a service account and download its JSON key file.
- After creating the service account, you must grant the service account the necessary permissions to access Big Query.
- To authenticate with Big Query, you must set the environment variable
GOOGLE_APPLICATION_CREDENTIALS
to the path of the JSON key file. - You can then use the
bigquery
library in Python to authenticate with Big Query. For example:
from google.cloud import bigquery
client = bigquery.Client.from_service_account_json('path/to/service_account.json')
- After authenticating with Big Query, you can use the client object to run queries and other operations. For example:
query_job = client.query("SELECT * FROM `bigquery-public-data.usa_names.usa_1910_2013` LIMIT 10")
results = query_job.result()
for row in results:
print(row)
Output example
Row(('Mary', 1910, 0.07248475199092562), {'name': 0, 'year': 1, 'number': 2})
Row(('Anna', 1910, 0.02637829011019772), {'name': 0, 'year': 1, 'number': 2})
Row(('Emma', 1910, 0.02512562814070352), {'name': 0, 'year': 1, 'number': 2})
Row(('Elizabeth', 1910, 0.023852320675105485), {'name': 0, 'year': 1, 'number': 2})
Row(('Minnie', 1910, 0.012989623885918001), {'name': 0, 'year': 1, 'number': 2})
Row(('Margaret', 1910, 0.012924851757187394), {'name': 0, 'year': 1, 'number': 2})
Row(('Ida', 1910, 0.012705821783236776), {'name': 0, 'year': 1, 'number': 2})
Row(('Alice', 1910, 0.009608037617924537), {'name': 0, 'year': 1, 'number': 2})
Row(('Bertha', 1910, 0.009142418793820666), {'name': 0, 'year': 1, 'number': 2})
Row(('Sarah', 1910, 0.008930357142857142), {'name': 0, 'year': 1, 'number': 2})
- You can also use the
bq
command-line tool to authenticate with Big Query. For example:
bq --location=US --key_file=path/to/service_account.json mk my_dataset
- For more information, see the BigQuery authentication documentation and the BigQuery Python Client Library documentation.
More of Google Big Query
- What are the advantages and disadvantages of using Google BigQuery?
- How do I set up a Google Big Query zone?
- How can I use Google Big Query to integrate with Zephyr?
- How do I set up permissions for Google BigQuery?
- How do I use the "not in" operator in Google BigQuery?
- How can I use Google Big Query with MicroStrategy?
- How do I use Google Big Query with Zoom?
- ¿Cuáles son las ventajas y desventajas de usar Google BigQuery?
- How can I use Google BigQuery to wait for a query to complete?
- How do I use wildcards in Google BigQuery?
See more codes...