Loint
Loint

Reputation: 3938

How to getQueryResults() of 1 job after createQueryJob() successfully in Google BigQuery?

I'm using google cloud big query service with nodejs client version 1.0x . I created a job successfully by function createQueryJob(). After that, I used an event listen when a callback create job response with getQueryResults() such as:

 const options = {
        query: sqlQuery,
        useLegacySql: true,
        dryRun: true
    };
    // this.bigquery is an constructor.
    // this.bigquery = new BigQuery({
    //    projectId: this.projectId,
    //   keyFilename: this.keyFile,
    // });
    this.bigquery.createQueryJob(options, function (err, job) {
        if (!err) {
            // job id such as 731bf23b-5044-4842-894b-4d9f77485d9b
            function manualPaginationCallback(err, rows, nextQuery, apiResponse) {
                if (nextQuery) {
                    job.getQueryResults(nextQuery, manualPaginationCallback);
                } else {
                    return Promise.resolve(rows);
                }
            }

            return job.getQueryResults({
                maxResults: 100000,
                autoPaginate: false,
                // timeoutMs : 60000
            }, manualPaginationCallback);
        }
    });

But It throw an error

{"error":{"code":404,"message":"Not found: Job [myProjectId]:731bf23b-5044-4842-894b-4d9f77485d9b","errors":[{"message":"Not found: Job [myProjectId]:731bf23b-5044-4842-894b-4d9f77485d9b","domain":"global","reason":"notFound"}],"status":"NOT_FOUND"}}

refrence

https://cloud.google.com/nodejs/docs/reference/bigquery/1.0.x/BigQuery#createQueryJob https://cloud.google.com/nodejs/docs/reference/bigquery/1.0.x/Job#getQueryResults

What wrong's with me? Any help. Thank you!

Upvotes: 0

Views: 1202

Answers (1)

shollyman
shollyman

Reputation: 4384

You're setting the dryrun option in your request, which only validates the job but doesn't actually run the query. Dryrun jobs don't persist, which is why you get not found on the subsequent request.

Upvotes: 1

Related Questions