UNPKG

4.86 kBTypeScriptView Raw
1/*!
2 * Copyright 2014 Google Inc. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16/*!
17 * @module bigquery/job
18 */
19import { MetadataCallback, Operation } from '@google-cloud/common';
20import { ResourceStream } from '@google-cloud/paginator';
21import { BigQuery, IntegerTypeCastOptions, JobRequest, PagedRequest, QueryRowsCallback, QueryRowsResponse, RequestCallback } from './bigquery';
22import { RowMetadata } from './table';
23import bigquery from './types';
24export declare type JobMetadata = bigquery.IJob;
25export declare type JobOptions = JobRequest<JobMetadata>;
26export declare type CancelCallback = RequestCallback<bigquery.IJobCancelResponse>;
27export declare type CancelResponse = [bigquery.IJobCancelResponse];
28export declare type QueryResultsOptions = {
29 job?: Job;
30 wrapIntegers?: boolean | IntegerTypeCastOptions;
31} & PagedRequest<bigquery.jobs.IGetQueryResultsParams>;
32/**
33 * @callback QueryResultsCallback
34 * @param {?Error} err An error returned while making this request.
35 * @param {array} rows The results of the job.
36 */
37/**
38 * @callback ManualQueryResultsCallback
39 * @param {?Error} err An error returned while making this request.
40 * @param {array} rows The results of the job.
41 * @param {?object} nextQuery A pre-made configuration object for your next
42 * request. This will be `null` if no additional results are available.
43 * If the query is not yet complete, you may get empty `rows` and
44 * non-`null` `nextQuery` that you should use for your next request.
45 * @param {object} apiResponse The full API response.
46 */
47/**
48 * Job objects are returned from various places in the BigQuery API:
49 *
50 * - {@link BigQuery#getJobs}
51 * - {@link BigQuery#job}
52 * - {@link BigQuery#query}
53 * - {@link BigQuery#createJob}
54 * - {@link Table#copy}
55 * - {@link Table#createWriteStream}
56 * - {@link Table#extract}
57 * - {@link Table#load}
58 *
59 * They can be used to check the status of a running job or fetching the results
60 * of a previously-executed one.
61 *
62 * @class
63 * @param {BigQuery} bigQuery {@link BigQuery} instance.
64 * @param {string} id The ID of the job.
65 * @param {object} [options] Configuration object.
66 * @param {string} [options.location] The geographic location of the job.
67 * Required except for US and EU.
68 *
69 * @example
70 * const {BigQuery} = require('@google-cloud/bigquery');
71 * const bigquery = new BigQuery();
72 *
73 * const job = bigquery.job('job-id');
74 *
75 * //-
76 * // All jobs are event emitters. The status of each job is polled
77 * // continuously, starting only after you register a "complete" listener.
78 * //-
79 * job.on('complete', (metadata) => {
80 * // The job is complete.
81 * });
82 *
83 * //-
84 * // Be sure to register an error handler as well to catch any issues which
85 * // impeded the job.
86 * //-
87 * job.on('error', (err) => {
88 * // An error occurred during the job.
89 * });
90 *
91 * //-
92 * // To force the Job object to stop polling for updates, simply remove any
93 * // "complete" listeners you've registered.
94 * //
95 * // The easiest way to do this is with `removeAllListeners()`.
96 * //-
97 * job.removeAllListeners();
98 */
99declare class Job extends Operation {
100 bigQuery: BigQuery;
101 location?: string;
102 getQueryResultsStream: (options?: QueryResultsOptions) => ResourceStream<RowMetadata>;
103 constructor(bigQuery: BigQuery, id: string, options?: JobOptions);
104 cancel(): Promise<CancelResponse>;
105 cancel(callback: CancelCallback): void;
106 getQueryResults(options?: QueryResultsOptions): Promise<QueryRowsResponse>;
107 getQueryResults(options: QueryResultsOptions, callback: QueryRowsCallback): void;
108 getQueryResults(callback: QueryRowsCallback): void;
109 /**
110 * This method will be called by `getQueryResultsStream()`. It is required to
111 * properly set the `autoPaginate` option value.
112 *
113 * @private
114 */
115 getQueryResultsAsStream_(options: QueryResultsOptions, callback: QueryRowsCallback): void;
116 /**
117 * Poll for a status update. Execute the callback:
118 *
119 * - callback(err): Job failed
120 * - callback(): Job incomplete
121 * - callback(null, metadata): Job complete
122 *
123 * @private
124 *
125 * @param {function} callback
126 */
127 poll_(callback: MetadataCallback): void;
128}
129/**
130 * Reference to the {@link Job} class.
131 * @name module:@google-cloud/bigquery.Job
132 * @see Job
133 */
134export { Job };