Job objects are returned from various places in the BigQuery API:
They can be used to check the status of a running job or fetching the results of a previously-executed one.
Inheritance
ServiceObject<T>
>
Operation
>
Job
Package
@google-cloud/bigquery
Example
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const job = bigquery.job('job-id');
//-
// All jobs are event emitters. The status of each job is polled
// continuously, starting only after you register a "complete" listener.
//-
job.on('complete', (metadata) => {
// The job is complete.
});
//-
// Be sure to register an error handler as well to catch any issues which
// impeded the job.
//-
job.on('error', (err) => {
// An error occurred during the job.
});
//-
// To force the Job object to stop polling for updates, simply remove any
// "complete" listeners you've registered.
//
// The easiest way to do this is with `removeAllListeners()`.
//-
job.removeAllListeners();
Constructors
(constructor)(bigQuery, id, options)
constructor(bigQuery: BigQuery, id: string, options?: JobOptions);
Constructs a new instance of the Job
class
Properties
bigQuery
location
projectId
Methods
cancel()
cancel(): Promise<CancelResponse>;
Example
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const job = bigquery.job('job-id');
job.cancel((err, apiResponse) =>{
// Check to see if the job completes successfully.
job.on('error', (err) => {});
job.on('complete', (metadata) => {});
});
//-
// If the callback is omitted, we'll return a Promise.
//-
job.cancel().then((data) => {
const apiResponse = data[0];
});
cancel(callback)
cancel(callback: CancelCallback): void;
Returns |
Type |
Description |
void |
|
getQueryResults(options)
getQueryResults(options?: QueryResultsOptions): Promise<QueryRowsResponse>;
Example
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const job = bigquery.job('job-id');
//-
// Get all of the results of a query.
//-
job.getQueryResults((err, rows) => {
if (!err) {
// rows is an array of results.
}
});
//-
// Customize the results you want to fetch.
//-
job.getQueryResults({
maxResults: 100
}, (err, rows) => {});
//-
// To control how many API requests are made and page through the results
// manually, set `autoPaginate` to `false`.
//-
function manualPaginationCallback(err, rows, nextQuery, apiResponse) {
if (nextQuery) {
// More results exist.
job.getQueryResults(nextQuery, manualPaginationCallback);
}
}
job.getQueryResults({
autoPaginate: false
}, manualPaginationCallback);
//-
// If the callback is omitted, we'll return a Promise.
//-
job.getQueryResults().then((data) => {
const rows = data[0];
});
getQueryResults(options, callback)
getQueryResults(options: QueryResultsOptions, callback: QueryRowsCallback): void;
Returns |
Type |
Description |
void |
|
getQueryResults(callback)
getQueryResults(callback: QueryRowsCallback): void;
Returns |
Type |
Description |
void |
|
getQueryResultsAsStream_(options, callback)
getQueryResultsAsStream_(options: QueryResultsOptions, callback: QueryRowsCallback): void;
This method will be called by getQueryResultsStream()
. It is required to properly set the autoPaginate
option value.
Returns |
Type |
Description |
void |
|
getQueryResultsStream(options)
getQueryResultsStream(options?: QueryResultsOptions): ResourceStream<RowMetadata>;
poll_(callback)
poll_(callback: MetadataCallback): void;
Poll for a status update. Execute the callback:
- callback(err): Job failed - callback(): Job incomplete - callback(null, metadata): Job complete
Returns |
Type |
Description |
void |
|