Skip to content

bigquery: the Job got from getJobs does not work #2736

Closed

Description

@c0b

for both getJobs or getJobsStream, just because the job metadata returned from jobs.list may not be sufficient or complete, sometimes you want to call a job.get to retrieve it again, or call job.getQueryResults; at this time it always failed

  1. https://googlecloudplatform.github.io/google-cloud-node/#/docs/bigquery/0.9.6/bigquery?method=getJobs
  2. https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/list
  3. https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/getQueryResults
> const bigquery = require('@google-cloud/bigquery')();

> 
> function colors(data) { console.dir(data, { depth: null, colors: true }); }

> bigquery.getJobs({ maxResults: 1 }).then(
      ([ jobs ]) => { const job = jobs[0]; job.get().then(colors); });
> [ { ApiError: Invalid job ID "project-id:jobid_kyYb4og.....". Job IDs must be alphanumeric (plus underscores and dashes) and must be at most 1024 characters long.
    at Object.parseHttpRespBody (/path/to/node_modules/@google-cloud/bigquery/node_modules/@google-cloud/common/src/util.js:192:30)
    at Object.handleResp (/path/to/node_modules/@google-cloud/bigquery/node_modules/@google-cloud/common/src/util.js:132:18)
    at /path/to/node_modules/@google-cloud/bigquery/node_modules/@google-cloud/common/src/util.js:465:12
    at Request.onResponse [as _callback] (/path/to/node_modules/@google-cloud/bigquery/node_modules/retry-request/index.js:180:7)
    at Request.self.callback (/path/to/node_modules/@google-cloud/bigquery/node_modules/request/request.js:186:22)
    at emitTwo (events.js:135:13)
    at Request.emit (events.js:224:7)
    at Request.<anonymous> (/path/to/node_modules/@google-cloud/bigquery/node_modules/request/request.js:1163:10)
    at emitOne (events.js:125:13)
    at Request.emit (events.js:221:7)
    code: 400,
    errors: 
     [ { domain: 'global',
         reason: 'invalid',
         message: 'Invalid job ID "project-id:jobid_kyYb4og.....". Job IDs must be alphanumeric (plus underscores and dashes) and must be at most 1024 characters long.' } ],
    response: undefined,
    message: 'Invalid job ID "project-id:jobid_kyYb4og.....". Job IDs must be alphanumeric (plus underscores and dashes) and must be at most 1024 characters long.' },
  null,
  null ]

> 

The reason failed is because the job id returned is the full id in the format of "project-id:job-id" but the job.get or getQueryResults is expecting "job-id" only, without "project-id" prefix,

so a workaround is simple as to remove the prefix:

> bigquery.getJobs({ maxResults: 1 }).then(
      ([ jobs ]) => { const job = jobs[0]; job.id = job.id.replace(/^.*:/, ''); job.get().then(colors); });

// this works as expected

the line needs to be changed is the bigquery/src/index.js#L809, can use the .replace remove prefix, or use jobObject.jobReference.jobId I can send a one-line PR, let me know.
https://github.com/GoogleCloudPlatform/google-cloud-node/blob/master/packages/bigquery/src/index.js#L809

Activity

  1. stephenplusplus commented on Nov 8, 2017

    @stephenplusplus
    Contributor

    Yeah, a PR would be great, thank you as always!

  2. added 3 commits that reference this issue on Nov 9, 2017
    9bbacde
    c2fe4a7
    ef54121
  3. added a commit that references this issue on Nov 9, 2017
    f10f61f
  4. added a commit that references this issue on Feb 3, 2026
    9d695c3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions