Reputation: 583
I am using bigquery client to query data in a table:
query_job = self.bigquery_client.query("SELECT * FROM {0} WHERE AGE={1}".format(table_name, 1))
results = query_job.result()
This one works in another process under a service account (Using query1):
self.bigquery_client = bigquery.Client().from_service_account_json(self.access_key_path)
For another process where I query another table under another project, I can't query because I don't have permission to query the table.
I tried to use this code but I still get permission error (Using query2):
self.bigquery_client = bigquery.Client()
# or self.bigquery_client = bigquery.Client(project='PROJECT_ID')
How can I access both table without providing service account to my query(2)?
Upvotes: 3
Views: 9219
Reputation: 4075
Your client needs to be authenticated to the project you want to access.
If you need to query different tables in different projects your service account should have permissions in both projects. Another approach would be having one service account per project and creating one client per project (in your case, you would use different clients for different queries).
I suggest that you use the first approach because its not only more practical but it also avoid some problems. For example, if you want to JOIN both tables in a query, you'll need to have access to both at the same time which is not possible using separated service accounts.
Upvotes: 2