简体   繁体   中英

BigQuery table copy from one project to another (These use another credentials)

I want to copy table from SourceProject to DestProject. SourceProject is owned by service user, and DestProject is owned by me. I have received credentials from a service user to access SourceProject. How can I copy table from SourceProject to DestProject?

I'm checking this question. Exporting BigQuery table from one project to another

And I'm tried this code.

source_client = bigquery.Client(
    credentials=user_credentials,
    project=source_project,
)

dest_client = bigquery.Client(
    credentials=my_credentials,
    project=dest_project,
)

source_dataset = source_client.dataset("source_dataset", project="source_project")
source_table_ref = source_dataset.table("source_table")

dest_dataset = dest_client.dataset("dest_dataset", project="dest_project")
dest_table_ref = dest_dataset.table("dest_table")

job = dest_client.copy_table(
    source_table_ref,
    dest_table_ref,
)  # API request

job.result()

but it wasn't work.(yes,of course) returned to this message.

google.api_core.exceptions.Forbidden: 403 POST https://bigquery.googleapis.com/bigquery/v2/projects/dest_project/jobs: Access Denied: Dataset source_project:source_dataset: User does not have bigquery.tables.create permission for dataset source_project:source_dataset.

It would be helpful if you could tell me a good way or an alternative. thank you for reading.

Your code is right and you set all the required information such as Project, Dataset and Table.

As we discussed in the comments, the problem for this method is that you were using the wrong credentials. In order to create a new table in BigQuery you need to have the bigquery.tables.create privilege in the given dataset.

If you need any further support, please let me know

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM