Class Job (5.11.0)
Stay organized with collections
Save and categorize content based on your preferences.
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.
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
Parameters
Properties
bigQuery
location
Methods
cancel()
cancel(): Promise<CancelResponse>;
Returns
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;
Parameter
Returns
getQueryResults(options)
getQueryResults(options?: QueryResultsOptions): Promise<QueryRowsResponse>;
Parameter
Returns
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;
Parameters
Returns
getQueryResults(callback)
getQueryResults(callback: QueryRowsCallback): void;
Parameter
Returns
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.
Parameters
Returns
getQueryResultsStream(options)
getQueryResultsStream(options?: QueryResultsOptions): ResourceStream<RowMetadata>;
Parameter
Returns
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
Parameter
Returns
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-09-19 UTC.
[{
"type": "thumb-down",
"id": "hardToUnderstand",
"label":"Hard to understand"
},{
"type": "thumb-down",
"id": "incorrectInformationOrSampleCode",
"label":"Incorrect information or sample code"
},{
"type": "thumb-down",
"id": "missingTheInformationSamplesINeed",
"label":"Missing the information/samples I need"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
{"lastModified": "Last updated 2024-09-19 UTC."}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-09-19 UTC."]]