4

Using Python to run BigQuery job with project id

 1 year ago
source link: https://donghao.org/2022/11/18/using-python-to-run-bigquery-job-with-project-id/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Using Python to run BigQuery job with project id

Here is the code for me to query a table of BigQuery:

from google.cloud import bigquery
from google.cloud.bigquery_storage import BigQueryReadClient

client = bigquery.Client()
storage_client = BigQueryReadClient()
df = client.query("select * from my_table1").to_dataframe(bqstorage_client=storage_client)
Python
from google.cloud import bigquery
from google.cloud.bigquery_storage import BigQueryReadClient
client = bigquery.Client()
storage_client = BigQueryReadClient()
df = client.query("select * from my_table1").to_dataframe(bqstorage_client=storage_client)

Then it reported the error:

“Access Denied: Project PRJ_B: User does not have bigquery.jobs.create permission in project PRJ_B.”

But actually, I want to launch a job in project PRJ_A. So I add a shell command “gcloud config set project PRJ_A” before running this python script. But the errors continued.

After searching the API doc of Python BigQuery, I found out that the “bigquery.Client()” function could add an argument:

client = bigquery.Client(project="PRJ_A")
Python
client = bigquery.Client(project="PRJ_A")

Now the script works well.

Related Posts

November 18, 2022 - 2:17 RobinDong bigdata
BigQuery
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Comment *

Name *

Email *

Website

Save my name, email, and website in this browser for the next time I comment.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK