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

Does createDataset support the supplying of a projectId? #1227

Closed
atrbgithub opened this issue Jul 21, 2023 · 0 comments · Fixed by #1230
Closed

Does createDataset support the supplying of a projectId? #1227

atrbgithub opened this issue Jul 21, 2023 · 0 comments · Fixed by #1230
Assignees
Labels
api: bigquery Issues related to the googleapis/nodejs-bigquery API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue.

Comments

@atrbgithub
Copy link

I'm trying to create a single instance of this client and then use it to create datasets in multiple projects.

For example:

const bigqueryClient = new BigQuery()

let ds = new Dataset(bigqueryClient, "a_test_dataset", {
   projectId: "a-test-project"
 })

ds.create()

This does not work, the dataset is created in whatever project is currently set as the default locally via gcloud.

const bigqueryClient = new BigQuery()
  bigqueryClient.createDataset("a_test_dataset", {
    projectId: "a-test-project"
  })

Same issue when doing it this way.

const bigqueryClient = new BigQuery()
  bigqueryClient.createDataset("a_test_dataset", {
    projectId: "a-test-project",
    datasetReference: {
      projectId: "a-test-project",
    },
  })

Finally this way throws an error:

Value some-default-project-id in content does not agree with value a-test-project. This can happen when a value set through a parameter is inconsistent with a value set in the request.

This is the only way that does work, but, it involves changing the projectId directly on the BigQuery client instance, it changes it for all subsequent requests.

  const bigqueryClient = new BigQuery()

  let ds = new Dataset(bigqueryClient, "a_test_dataset", {
     projectId: "a-test-project"
   })

   ds.bigQuery.projectId = "a-test-project"

   ds.create()

Interestingly, it does work for getDatasets:

  const bigqueryClient = new BigQuery()

  // @ts-ignore:next-line
  const [datasets] = await bigqueryClient.getDatasets({
    // @ts-ignore:next-line
    projectId: "a-test-project",
  })
  datasets.forEach((ds: any) => {
    console.log(ds.id)
  })

The above code returns the datasets from the correct project, although the types need to be overridden in typescript.

There was a PR from last year around cross project access. @steffnay @shollyman @feywind apologies for pinging you directly, do you know if creating a dataset should support the passing in of the projectId?

@atrbgithub atrbgithub added priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue. labels Jul 21, 2023
@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/nodejs-bigquery API. label Jul 21, 2023
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 googleapis/nodejs-bigquery API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants