Reputation: 11
I tried to get pageToken in response by adding maxResults as 2 in options with query, When I used that pageToken (that I got in response from my previous code) in options with maxResults then I didn't get the next set of results, I got empty array in response, how should we pass pageToken with query and maxResults to get the next set of results?
If I use pageToken in options->
const { BigQuery } = require('@google-cloud/bigquery')
const projectId = 'bigqueryproject1-279307'
const keyFilename = './credentials/client_secrets.json'
async function query () {
const bigqueryClient = new BigQuery({ projectId, keyFilename })
// Queries the U.S. given names dataset for the state of Texas.
const query = 'SELECT * FROM bigqueryproject1-279307.abcdef12k3.__TABLES__ WHERE type = 2'
const options = {
maxResults: 2,
pageToken: 'BE6GBKCXOMAQAAASA4EAAEEAQCAAKGQEBABBAARAWCXBK==='
}
const job = await bigqueryClient.query(query, options)
console.log('******job*****', job)
}
query()
Result=>
[ [],
null,
{ kind: 'bigquery#getQueryResultsResponse',
etag: 'taA51Ro5PrAMPypjzfMwCg==',
schema: { fields: [Array] },
jobReference:
{ projectId: 'bigqueryproject1-279307',
jobId: 'a212f570-0d92-4208-92ac-71aa2da82364',
location: 'US' },
totalRows: '0',
totalBytesProcessed: '0',
jobComplete: true,
cacheHit: false } ]
I am getting empty array as response rather than getting next 2 view
Upvotes: 1
Views: 919
Reputation: 5253
I admit that pageToken
parameter doesn't exist in generic query request body of the jobs.query
Bigquery API method, thus you can't also find it in the relevant bigquery.query(query, options, callback)
NodeJS Bigquery client library class method as well.
In order to get the desired effect for the user query results pagination, you can consider adjusting job.getQueryResults() method in your code, fetching the certain rows from the query Job as per defined maxResults
and pageToken
properties.
Upvotes: 1