Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigQuery: Run job in one project that uses resources from another #2609

Closed
alixhami opened this issue Nov 16, 2018 · 4 comments · Fixed by #2697
Closed

BigQuery: Run job in one project that uses resources from another #2609

alixhami opened this issue Nov 16, 2018 · 4 comments · Fixed by #2697
Assignees
Labels
api: bigquery Issues related to the BigQuery API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@alixhami
Copy link
Contributor

This is a feature request if it is not supported by the library. See last line for tldr. I am updating a ruby sample to match the python sample for extracting a table. The python sample extracts the bigquery-public-data shakespeare table to a GCS bucket. When attempting this in ruby, I ran into a permissions error because of the way the request was structured by the library. The ruby library's extract_job method is attached to a table instance, so it tries to use the table's project to run the job.

Environment details

  • OS: macOS High Sierra
  • Ruby version: 2.4.4
  • Gem name and version: google-cloud-bigquery 1.8.0

Steps to reproduce

Run code with bucket_name replaced with an actual bucket:

require "google/cloud/bigquery"

bucket_name = "my-bucket"
bigquery = Google::Cloud::Bigquery.new project: "bigquery-public-data"
dataset = bigquery.dataset "samples"
table = dataset.table "shakespeare"
destination_uri = "gs://#{bucket_name}/shakespeare.csv"

extract_job = table.extract_job(destination_uri) do |updater|
  # Location must match that of the source table.
  updater.location = "US"
end
extract_job.wait_until_done!  # Waits for the job to complete

puts "Exported #{table.id} to #{destination_uri}"

I get this error on the line where the extract_job is defined:

Google::Cloud::PermissionDeniedError:
       accessDenied: Access Denied: Project bigquery-public-data: The user <MY-SERVICE-ACCOUNT> does not have bigquery.jobs.create permission in project bigquery-public-data.

Is there any way to send an extract job with one project that uses resources in another project?

@quartzmo quartzmo added type: question Request for information or clarification. Not an issue. api: bigquery Issues related to the BigQuery API. labels Nov 16, 2018
@quartzmo
Copy link
Member

@alixhami Thanks for this issue! I'm going to initially label it as a question, but I'll change it to a feature request if needed.

@quartzmo quartzmo self-assigned this Nov 16, 2018
@quartzmo
Copy link
Member

@blowmage and I looked into this, and it will require adding a project_id optional parameter to Project#dataset, similar to the project param in Pubsub::Project#topic.

@quartzmo quartzmo added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed type: question Request for information or clarification. Not an issue. labels Nov 17, 2018
quartzmo added a commit to quartzmo/google-cloud-ruby that referenced this issue Nov 27, 2018
@quartzmo
Copy link
Member

@blowmage and I looked into this, and it will require adding a project_id optional parameter to Project#dataset, similar to the project param in Pubsub::Project#topic.

Unfortunately this approach turned out to be extremely disruptive and error-prone, so I have have opened #2692 to add project_id to the extract methods.

@quartzmo
Copy link
Member

The new solution will be to add versions of #extract, #extract_job, #copy and #copy_job to Project, as discussed in PR #2692, which has been closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the BigQuery API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
2 participants