UNPKG

43.7 kBTypeScriptView Raw
1/*!
2 * Copyright 2019 Google LLC
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 */
16import { Service, GoogleAuthOptions } from '@google-cloud/common';
17import * as common from '@google-cloud/common';
18import { ResourceStream } from '@google-cloud/paginator';
19import { PreciseDate } from '@google-cloud/precise-date';
20import { Dataset, DatasetOptions } from './dataset';
21import { Job, JobOptions, QueryResultsOptions } from './job';
22import { Table, TableField, TableSchema, TableRow, JobCallback, JobResponse, RowMetadata } from './table';
23import bigquery from './types';
24export { common };
25export interface RequestCallback<T> {
26 (err: Error | null, response?: T | null): void;
27}
28export interface ResourceCallback<T, R> {
29 (err: Error | null, resource?: T | null, response?: R | null): void;
30}
31export type PagedResponse<T, Q, R> = [T[]] | [T[], Q | null, R];
32export interface PagedCallback<T, Q, R> {
33 (err: Error | null, resource?: T[] | null, nextQuery?: Q | null, response?: R | null): void;
34}
35export type JobRequest<J> = J & {
36 jobId?: string;
37 jobPrefix?: string;
38 location?: string;
39 projectId?: string;
40};
41export type PagedRequest<P> = P & {
42 autoPaginate?: boolean;
43 maxApiCalls?: number;
44};
45export type QueryRowsResponse = PagedResponse<RowMetadata, Query, bigquery.IGetQueryResultsResponse>;
46export type QueryRowsCallback = PagedCallback<RowMetadata, Query, bigquery.IGetQueryResultsResponse>;
47export type SimpleQueryRowsResponse = [RowMetadata[], bigquery.IJob];
48export type SimpleQueryRowsCallback = ResourceCallback<RowMetadata[], bigquery.IJob>;
49export type Query = JobRequest<bigquery.IJobConfigurationQuery> & {
50 destination?: Table;
51 params?: any[] | {
52 [param: string]: any;
53 };
54 dryRun?: boolean;
55 labels?: {
56 [label: string]: string;
57 };
58 types?: QueryParamTypes;
59 job?: Job;
60 maxResults?: number;
61 jobTimeoutMs?: number;
62 pageToken?: string;
63 wrapIntegers?: boolean | IntegerTypeCastOptions;
64 parseJSON?: boolean;
65};
66export type QueryParamTypeStruct = {
67 [type: string]: string | string[] | QueryParamTypeStruct | QueryParamTypeStruct[];
68};
69export type QueryParamTypes = string[] | string[][] | QueryParamTypeStruct | QueryParamTypeStruct[];
70export type QueryOptions = QueryResultsOptions;
71export type QueryStreamOptions = {
72 wrapIntegers?: boolean | IntegerTypeCastOptions;
73 parseJSON?: boolean;
74};
75export type DatasetResource = bigquery.IDataset & {
76 projectId?: string;
77};
78export type ValueType = bigquery.IQueryParameterType;
79export type GetDatasetsOptions = PagedRequest<bigquery.datasets.IListParams> & {
80 projectId?: string;
81};
82export type DatasetsResponse = PagedResponse<Dataset, GetDatasetsOptions, bigquery.IDatasetList>;
83export type DatasetsCallback = PagedCallback<Dataset, GetDatasetsOptions, bigquery.IDatasetList>;
84export type DatasetResponse = [Dataset, bigquery.IDataset];
85export type DatasetCallback = ResourceCallback<Dataset, bigquery.IDataset>;
86export type GetJobsOptions = PagedRequest<bigquery.jobs.IListParams>;
87export type GetJobsResponse = PagedResponse<Job, GetJobsOptions, bigquery.IJobList>;
88export type GetJobsCallback = PagedCallback<Job, GetJobsOptions, bigquery.IJobList>;
89export interface BigQueryTimeOptions {
90 hours?: number | string;
91 minutes?: number | string;
92 seconds?: number | string;
93 fractional?: number | string;
94}
95export interface BigQueryDateOptions {
96 year?: number | string;
97 month?: number | string;
98 day?: number | string;
99}
100export interface BigQueryDatetimeOptions {
101 year?: string | number;
102 month?: string | number;
103 day?: string | number;
104 hours?: string | number;
105 minutes?: string | number;
106 seconds?: string | number;
107 fractional?: string | number;
108}
109export type ProvidedTypeArray = Array<ProvidedTypeStruct | string | []>;
110export interface ProvidedTypeStruct {
111 [key: string]: string | ProvidedTypeArray | ProvidedTypeStruct;
112}
113export type QueryParameter = bigquery.IQueryParameter;
114export interface BigQueryOptions extends GoogleAuthOptions {
115 /**
116 * Automatically retry requests if the
117 * response is related to rate limits or certain intermittent server errors.
118 * We will exponentially backoff subsequent requests by default.
119 *
120 * Defaults to `true`.
121 */
122 autoRetry?: boolean;
123 /**
124 * Maximum number of automatic retries
125 * attempted before returning the error.
126 *
127 * Defaults to 3.
128 */
129 maxRetries?: number;
130 /**
131 * The geographic location of all datasets and
132 * jobs referenced and created through the client.
133 */
134 location?: string;
135 /**
136 * The value to be prepended to the User-Agent
137 * header in API requests.
138 */
139 userAgent?: string;
140 /**
141 * The API endpoint of the service used to make requests.
142 * Defaults to `bigquery.googleapis.com`.
143 */
144 apiEndpoint?: string;
145}
146export interface IntegerTypeCastOptions {
147 integerTypeCastFunction: Function;
148 fields?: string | string[];
149}
150export type IntegerTypeCastValue = {
151 integerValue: string | number;
152 schemaFieldName?: string;
153};
154export declare const PROTOCOL_REGEX: RegExp;
155/**
156 * @typedef {object} BigQueryOptions
157 * @property {string} [projectId] The project ID from the Google Developer's
158 * Console, e.g. 'grape-spaceship-123'. We will also check the environment
159 * variable `GCLOUD_PROJECT` for your project ID. If your app is running in
160 * an environment which supports {@link
161 * https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application
162 * Application Default Credentials}, your project ID will be detected
163 * automatically.
164 * @property {string} [keyFilename] Full path to the a .json, .pem, or .p12 key
165 * downloaded from the Google Developers Console. If you provide a path to a
166 * JSON file, the `projectId` option above is not necessary. NOTE: .pem and
167 * .p12 require you to specify the `email` option as well.
168 * @property {string} [token] An OAUTH access token. If provided, we will not
169 * manage fetching, re-using, and re-minting access tokens.
170 * @property {string} [email] Account email address. Required when using a .pem
171 * or .p12 keyFilename.
172 * @property {object} [credentials] Credentials object.
173 * @property {string} [credentials.client_email]
174 * @property {string} [credentials.private_key]
175 * @property {Constructor} [promise] Custom promise module to use instead of
176 * native Promises.
177 * @property {string[]} [scopes] Additional OAuth scopes to use in requests. For
178 * example, to access an external data source, you may need the
179 * `https://www.googleapis.com/auth/drive.readonly` scope.
180 */
181/**
182 * In the following examples from this page and the other modules (`Dataset`,
183 * `Table`, etc.), we are going to be using a dataset from
184 * {@link http://goo.gl/f2SXcb| data.gov} of higher education institutions.
185 *
186 * We will create a table with the correct schema, import the public CSV file
187 * into that table, and query it for data.
188 *
189 * @class
190 *
191 * See {@link https://cloud.google.com/bigquery/what-is-bigquery| What is BigQuery?}
192 *
193 * @param {BigQueryOptions} options Constructor options.
194 *
195 * @example Install the client library with <a href="https://www.npmjs.com/">npm</a>:
196 * ```
197 * npm install @google-cloud/bigquery
198 *
199 * ```
200 * @example Import the client library
201 * ```
202 * const {BigQuery} = require('@google-cloud/bigquery');
203 *
204 * ```
205 * @example Create a client that uses <a href="https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application">Application Default Credentials (ADC)</a>:
206 * ```
207 * const bigquery = new BigQuery();
208 *
209 * ```
210 * @example Create a client with <a href="https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually">explicit credentials</a>:
211 * ```
212 * const bigquery = new BigQuery({
213 * projectId: 'your-project-id',
214 * keyFilename: '/path/to/keyfile.json'
215 * });
216 *
217 * ```
218 * @example <caption>include:samples/quickstart.js</caption>
219 * region_tag:bigquery_quickstart
220 * Full quickstart example:
221 */
222export declare class BigQuery extends Service {
223 location?: string;
224 createQueryStream(options?: Query | string): ResourceStream<RowMetadata>;
225 getDatasetsStream(options?: GetDatasetsOptions): ResourceStream<Dataset>;
226 getJobsStream(options?: GetJobsOptions): ResourceStream<Job>;
227 constructor(options?: BigQueryOptions);
228 private static sanitizeEndpoint;
229 /**
230 * Merge a rowset returned from the API with a table schema.
231 *
232 * @private
233 *
234 * @param {object} schema
235 * @param {array} rows
236 * @param {object} options
237 * @param {boolean|IntegerTypeCastOptions} options.wrapIntegers Wrap values of
238 * 'INT64' type in {@link BigQueryInt} objects.
239 * If a `boolean`, this will wrap values in {@link BigQueryInt} objects.
240 * If an `object`, this will return a value returned by
241 * `wrapIntegers.integerTypeCastFunction`.
242 * Please see {@link IntegerTypeCastOptions} for options descriptions.
243 * @param {array} options.selectedFields List of fields to return.
244 * If unspecified, all fields are returned.
245 * @param {array} options.parseJSON parse a 'JSON' field into a JSON object.
246 * @returns Fields using their matching names from the table's schema.
247 */
248 static mergeSchemaWithRows_(schema: TableSchema | TableField, rows: TableRow[], options: {
249 wrapIntegers: boolean | IntegerTypeCastOptions;
250 selectedFields?: string[];
251 parseJSON?: boolean;
252 }): any[];
253 /**
254 * The `DATE` type represents a logical calendar date, independent of time
255 * zone. It does not represent a specific 24-hour time period. Rather, a given
256 * DATE value represents a different 24-hour period when interpreted in
257 * different time zones, and may represent a shorter or longer day during
258 * Daylight Savings Time transitions.
259 *
260 * @param {object|string} value The date. If a string, this should be in the
261 * format the API describes: `YYYY-[M]M-[D]D`.
262 * Otherwise, provide an object.
263 * @param {string|number} value.year Four digits.
264 * @param {string|number} value.month One or two digits.
265 * @param {string|number} value.day One or two digits.
266 *
267 * @example
268 * ```
269 * const {BigQuery} = require('@google-cloud/bigquery');
270 * const bigquery = new BigQuery();
271 * const date = bigquery.date('2017-01-01');
272 *
273 * //-
274 * // Alternatively, provide an object.
275 * //-
276 * const date2 = bigquery.date({
277 * year: 2017,
278 * month: 1,
279 * day: 1
280 * });
281 * ```
282 */
283 static date(value: BigQueryDateOptions | string): BigQueryDate;
284 /**
285 * @param {object|string} value The date. If a string, this should be in the
286 * format the API describes: `YYYY-[M]M-[D]D`.
287 * Otherwise, provide an object.
288 * @param {string|number} value.year Four digits.
289 * @param {string|number} value.month One or two digits.
290 * @param {string|number} value.day One or two digits.
291 *
292 * @example
293 * ```
294 * const {BigQuery} = require('@google-cloud/bigquery');
295 * const date = BigQuery.date('2017-01-01');
296 *
297 * //-
298 * // Alternatively, provide an object.
299 * //-
300 * const date2 = BigQuery.date({
301 * year: 2017,
302 * month: 1,
303 * day: 1
304 * });
305 * ```
306 */
307 date(value: BigQueryDateOptions | string): BigQueryDate;
308 /**
309 * A `DATETIME` data type represents a point in time. Unlike a `TIMESTAMP`,
310 * this does not refer to an absolute instance in time. Instead, it is the
311 * civil time, or the time that a user would see on a watch or calendar.
312 *
313 * @method BigQuery.datetime
314 * @param {object|string} value The time. If a string, this should be in the
315 * format the API describes: `YYYY-[M]M-[D]D[ [H]H:[M]M:[S]S[.DDDDDD]]`.
316 * Otherwise, provide an object.
317 * @param {string|number} value.year Four digits.
318 * @param {string|number} value.month One or two digits.
319 * @param {string|number} value.day One or two digits.
320 * @param {string|number} [value.hours] One or two digits (`00` - `23`).
321 * @param {string|number} [value.minutes] One or two digits (`00` - `59`).
322 * @param {string|number} [value.seconds] One or two digits (`00` - `59`).
323 * @param {string|number} [value.fractional] Up to six digits for microsecond
324 * precision.
325 *
326 * @example
327 * ```
328 * const {BigQuery} = require('@google-cloud/bigquery');
329 * const datetime = BigQuery.datetime('2017-01-01 13:00:00');
330 *
331 * //-
332 * // Alternatively, provide an object.
333 * //-
334 * const datetime = BigQuery.datetime({
335 * year: 2017,
336 * month: 1,
337 * day: 1,
338 * hours: 14,
339 * minutes: 0,
340 * seconds: 0
341 * });
342 * ```
343 */
344 /**
345 * A `DATETIME` data type represents a point in time. Unlike a `TIMESTAMP`,
346 * this does not refer to an absolute instance in time. Instead, it is the
347 * civil time, or the time that a user would see on a watch or calendar.
348 *
349 * @param {object|string} value The time. If a string, this should be in the
350 * format the API describes: `YYYY-[M]M-[D]D[ [H]H:[M]M:[S]S[.DDDDDD]]`.
351 * Otherwise, provide an object.
352 * @param {string|number} value.year Four digits.
353 * @param {string|number} value.month One or two digits.
354 * @param {string|number} value.day One or two digits.
355 * @param {string|number} [value.hours] One or two digits (`00` - `23`).
356 * @param {string|number} [value.minutes] One or two digits (`00` - `59`).
357 * @param {string|number} [value.seconds] One or two digits (`00` - `59`).
358 * @param {string|number} [value.fractional] Up to six digits for microsecond
359 * precision.
360 *
361 * @example
362 * ```
363 * const {BigQuery} = require('@google-cloud/bigquery');
364 * const bigquery = new BigQuery();
365 * const datetime = bigquery.datetime('2017-01-01 13:00:00');
366 *
367 * //-
368 * // Alternatively, provide an object.
369 * //-
370 * const datetime = bigquery.datetime({
371 * year: 2017,
372 * month: 1,
373 * day: 1,
374 * hours: 14,
375 * minutes: 0,
376 * seconds: 0
377 * });
378 * ```
379 */
380 static datetime(value: BigQueryDatetimeOptions | string): BigQueryDatetime;
381 datetime(value: BigQueryDatetimeOptions | string): BigQueryDatetime;
382 /**
383 * A `TIME` data type represents a time, independent of a specific date.
384 *
385 * @method BigQuery.time
386 * @param {object|string} value The time. If a string, this should be in the
387 * format the API describes: `[H]H:[M]M:[S]S[.DDDDDD]`. Otherwise, provide
388 * an object.
389 * @param {string|number} [value.hours] One or two digits (`00` - `23`).
390 * @param {string|number} [value.minutes] One or two digits (`00` - `59`).
391 * @param {string|number} [value.seconds] One or two digits (`00` - `59`).
392 * @param {string|number} [value.fractional] Up to six digits for microsecond
393 * precision.
394 *
395 * @example
396 * ```
397 * const {BigQuery} = require('@google-cloud/bigquery');
398 * const time = BigQuery.time('14:00:00'); // 2:00 PM
399 *
400 * //-
401 * // Alternatively, provide an object.
402 * //-
403 * const time = BigQuery.time({
404 * hours: 14,
405 * minutes: 0,
406 * seconds: 0
407 * });
408 * ```
409 */
410 /**
411 * A `TIME` data type represents a time, independent of a specific date.
412 *
413 * @param {object|string} value The time. If a string, this should be in the
414 * format the API describes: `[H]H:[M]M:[S]S[.DDDDDD]`. Otherwise, provide
415 * an object.
416 * @param {string|number} [value.hours] One or two digits (`00` - `23`).
417 * @param {string|number} [value.minutes] One or two digits (`00` - `59`).
418 * @param {string|number} [value.seconds] One or two digits (`00` - `59`).
419 * @param {string|number} [value.fractional] Up to six digits for microsecond
420 * precision.
421 *
422 * @example
423 * ```
424 * const {BigQuery} = require('@google-cloud/bigquery');
425 * const bigquery = new BigQuery();
426 * const time = bigquery.time('14:00:00'); // 2:00 PM
427 *
428 * //-
429 * // Alternatively, provide an object.
430 * //-
431 * const time = bigquery.time({
432 * hours: 14,
433 * minutes: 0,
434 * seconds: 0
435 * });
436 * ```
437 */
438 static time(value: BigQueryTimeOptions | string): BigQueryTime;
439 time(value: BigQueryTimeOptions | string): BigQueryTime;
440 /**
441 * A timestamp represents an absolute point in time, independent of any time
442 * zone or convention such as Daylight Savings Time.
443 *
444 * @method BigQuery.timestamp
445 * @param {Date|string} value The time.
446 *
447 * @example
448 * ```
449 * const {BigQuery} = require('@google-cloud/bigquery');
450 * const timestamp = BigQuery.timestamp(new Date());
451 * ```
452 */
453 /**
454 * A timestamp represents an absolute point in time, independent of any time
455 * zone or convention such as Daylight Savings Time.
456 *
457 * @param {Date|string} value The time.
458 *
459 * @example
460 * ```
461 * const {BigQuery} = require('@google-cloud/bigquery');
462 * const bigquery = new BigQuery();
463 * const timestamp = bigquery.timestamp(new Date());
464 * ```
465 */
466 static timestamp(value: Date | PreciseDate | string | number): BigQueryTimestamp;
467 timestamp(value: Date | PreciseDate | string | number): BigQueryTimestamp;
468 /**
469 * A BigQueryInt wraps 'INT64' values. Can be used to maintain precision.
470 *
471 * @param {string|number|IntegerTypeCastValue} value The INT64 value to convert.
472 * @param {IntegerTypeCastOptions} typeCastOptions Configuration to convert
473 * value. Must provide an `integerTypeCastFunction` to handle conversion.
474 * @returns {BigQueryInt}
475 *
476 * @example
477 * ```
478 * const {BigQuery} = require('@google-cloud/bigquery');
479 * const bigquery = new BigQuery();
480 *
481 * const largeIntegerValue = Number.MAX_SAFE_INTEGER + 1;
482 *
483 * const options = {
484 * integerTypeCastFunction: value => value.split(),
485 * };
486 *
487 * const bqInteger = bigquery.int(largeIntegerValue, options);
488 *
489 * const customValue = bqInteger.valueOf();
490 * // customValue is the value returned from your `integerTypeCastFunction`.
491 * ```
492 */
493 static int(value: string | number | IntegerTypeCastValue, typeCastOptions?: IntegerTypeCastOptions): BigQueryInt;
494 int(value: string | number | IntegerTypeCastValue, typeCastOptions?: IntegerTypeCastOptions): BigQueryInt;
495 /**
496 * A geography value represents a surface area on the Earth
497 * in Well-known Text (WKT) format.
498 *
499 * @param {string} value The geospatial data.
500 *
501 * @example
502 * ```
503 * const {BigQuery} = require('@google-cloud/bigquery');
504 * const bigquery = new BigQuery();
505 * const geography = bigquery.geography('POINT(1, 2)');
506 * ```
507 */
508 static geography(value: string): Geography;
509 geography(value: string): Geography;
510 /**
511 * Convert an INT64 value to Number.
512 *
513 * @private
514 * @param {object} value The INT64 value to convert.
515 */
516 static decodeIntegerValue_(value: IntegerTypeCastValue): number;
517 /**
518 * Return a value's provided type.
519 *
520 * @private
521 *
522 * @throws {error} If the type provided is invalid.
523 *
524 * See {@link https://cloud.google.com/bigquery/data-types| Data Type}
525 *
526 * @param {*} providedType The type.
527 * @returns {string} The valid type provided.
528 */
529 static getTypeDescriptorFromProvidedType_(providedType: string | ProvidedTypeStruct | ProvidedTypeArray): ValueType;
530 /**
531 * Detect a value's type.
532 *
533 * @private
534 *
535 * @throws {error} If the type could not be detected.
536 *
537 * See {@link https://cloud.google.com/bigquery/data-types| Data Type}
538 *
539 * @param {*} value The value.
540 * @returns {string} The type detected from the value.
541 */
542 static getTypeDescriptorFromValue_(value: unknown): ValueType;
543 /**
544 * Convert a value into a `queryParameter` object.
545 *
546 * @private
547 *
548 * See {@link https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/query#request-body| Jobs.query API Reference Docs (see `queryParameters`)}
549 *
550 * @param {*} value The value.
551 * @param {string|ProvidedTypeStruct|ProvidedTypeArray} providedType Provided
552 * query parameter type.
553 * @returns {object} A properly-formed `queryParameter` object.
554 */
555 static valueToQueryParameter_(value: any, providedType?: string | ProvidedTypeStruct | ProvidedTypeArray): bigquery.IQueryParameter;
556 private static _getValue;
557 private static _isCustomType;
558 /**
559 * @callback DatasetCallback
560 * @param {?Error} err Request error, if any.
561 * @param {object} dataset The [dataset resource]{@link https://cloud.google.com/bigquery/docs/reference/rest/v2/datasets#resource}.
562 * @param {object} apiResponse The full API response.
563 */
564 /**
565 * Create a dataset.
566 *
567 * See {@link https://cloud.google.com/bigquery/docs/reference/v2/datasets/insert| Datasets: insert API Documentation}
568 *
569 * @param {string} id ID of the dataset to create.
570 * @param {object} [options] See a
571 * {@link https://cloud.google.com/bigquery/docs/reference/v2/datasets#resource| Dataset resource}.
572 * @param {DatasetCallback} [callback] The callback function.
573 * @param {?error} callback.err An error returned while making this request
574 * @param {Dataset} callback.dataset The newly created dataset
575 * @param {object} callback.apiResponse The full API response.
576 *
577 * @example
578 * ```
579 * const {BigQuery} = require('@google-cloud/bigquery');
580 * const bigquery = new BigQuery();
581 *
582 * bigquery.createDataset('my-dataset', function(err, dataset, apiResponse)
583 * {});
584 *
585 * //-
586 * // If the callback is omitted, we'll return a Promise.
587 * //-
588 * bigquery.createDataset('my-dataset').then(function(data) {
589 * const dataset = data[0];
590 * const apiResponse = data[1];
591 * });
592 * ```
593 */
594 createDataset(id: string, options?: DatasetResource): Promise<DatasetResponse>;
595 createDataset(id: string, options: DatasetResource, callback: DatasetCallback): void;
596 createDataset(id: string, callback: DatasetCallback): void;
597 /**
598 * @callback JobCallback
599 * @param {?Error} err Request error, if any.
600 * @param {object} job The newly created job for your query.
601 * @param {object} apiResponse The full API response.
602 */
603 /**
604 * Run a query as a job. No results are immediately returned. Instead, your
605 * callback will be executed with a {@link Job} object that you must
606 * ping for the results. See the Job documentation for explanations of how to
607 * check on the status of the job.
608 *
609 * See {@link https://cloud.google.com/bigquery/docs/reference/v2/jobs/insert| Jobs: insert API Documentation}
610 *
611 * @param {object|string} options The configuration object. This must be in
612 * the format of the {@link https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationQuery| `configuration.query`}
613 * property of a Jobs resource. If a string is provided, this is used as the
614 * query string, and all other options are defaulted.
615 * @param {Table} [options.destination] The table to save the
616 * query's results to. If omitted, a new table will be created.
617 * @param {boolean} [options.dryRun] If set, don't actually run this job. A
618 * valid query will update the job with processing statistics. These can
619 * be accessed via `job.metadata`.
620 * @param {object} [options.labels] String key/value pairs to be attached as
621 * labels to the newly created Job.
622 * @param {string} [options.location] The geographic location of the job.
623 * Required except for US and EU.
624 * @param {number} [options.jobTimeoutMs] Job timeout in milliseconds.
625 * If this time limit is exceeded, BigQuery might attempt to stop the job.
626 * @param {string} [options.jobId] Custom job id.
627 * @param {string} [options.jobPrefix] Prefix to apply to the job id.
628 * @param {string} options.query A query string, following the BigQuery query
629 * syntax, of the query to execute.
630 * @param {boolean} [options.useLegacySql=false] Option to use legacy sql syntax.
631 * @param {object} [options.defaultDataset] The dataset. This must be in
632 * the format of the {@link https://cloud.google.com/bigquery/docs/reference/rest/v2/datasets#DatasetReference| `DatasetReference`}
633 * @param {boolean} [options.wrapIntegers] Optionally wrap INT64 in BigQueryInt
634 * or custom INT64 value type.
635 * @param {boolean} [options.parseJSON] Optionally parse JSON as a JSON Object.
636 * @param {object|array} [options.params] Option to provide query prarameters.
637 * @param {JobCallback} [callback] The callback function.
638 * @param {?error} callback.err An error returned while making this request.
639 * @param {Job} callback.job The newly created job for your query.
640 * @param {object} callback.apiResponse The full API response.
641 *
642 * @throws {Error} If a query is not specified.
643 * @throws {Error} If a Table is not provided as a destination.
644 *
645 * @example
646 * ```
647 * const {BigQuery} = require('@google-cloud/bigquery');
648 * const bigquery = new BigQuery();
649 *
650 * const query = 'SELECT url FROM `publicdata.samples.github_nested` LIMIT
651 * 100';
652 *
653 * //-
654 * // You may pass only a query string, having a new table created to store
655 * the
656 * // results of the query.
657 * //-
658 * bigquery.createQueryJob(query, function(err, job) {});
659 *
660 * //-
661 * // You can also control the destination table by providing a
662 * // {@link Table} object.
663 * //-
664 * bigquery.createQueryJob({
665 * destination: bigquery.dataset('higher_education').table('institutions'),
666 * query: query
667 * }, function(err, job) {});
668 *
669 * //-
670 * // After you have run `createQueryJob`, your query will execute in a job.
671 * Your
672 * // callback is executed with a {@link Job} object so that you may
673 * // check for the results.
674 * //-
675 * bigquery.createQueryJob(query, function(err, job) {
676 * if (!err) {
677 * job.getQueryResults(function(err, rows, apiResponse) {});
678 * }
679 * });
680 *
681 * //-
682 * // If the callback is omitted, we'll return a Promise.
683 * //-
684 * bigquery.createQueryJob(query).then(function(data) {
685 * const job = data[0];
686 * const apiResponse = data[1];
687 *
688 * return job.getQueryResults();
689 * });
690 * ```
691 */
692 createQueryJob(options: Query | string): Promise<JobResponse>;
693 createQueryJob(options: Query | string, callback: JobCallback): void;
694 /**
695 * Creates a job. Typically when creating a job you'll have a very specific
696 * task in mind. For this we recommend one of the following methods:
697 *
698 * - {@link BigQuery.createQueryJob}
699 * - {@link Table#createCopyJob}
700 * - {@link Table#createCopyFromJob}
701 * - {@link Table#createExtractJob}
702 * - {@link Table#createLoadJob}
703 *
704 * However in the event you need a finer level of control over the job
705 * creation, you can use this method to pass in a raw {@link https://cloud.google.com/bigquery/docs/reference/rest/v2/Job| Job resource}
706 * object.
707 *
708 * See {@link https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs| Jobs Overview}
709 * See {@link https://cloud.google.com/bigquery/docs/reference/v2/jobs/insert| Jobs: insert API Documentation}
710 *
711 * @param {object} options Object in the form of a {@link https://cloud.google.com/bigquery/docs/reference/rest/v2/Job| Job resource};
712 * @param {string} [options.jobId] Custom job id.
713 * @param {string} [options.jobPrefix] Prefix to apply to the job id.
714 * @param {string} [options.location] The geographic location of the job.
715 * Required except for US and EU.
716 * @param {JobCallback} [callback] The callback function.
717 * @param {?error} callback.err An error returned while making this request.
718 * @param {Job} callback.job The newly created job.
719 * @param {object} callback.apiResponse The full API response.
720 *
721 * @example
722 * ```
723 * const {BigQuery} = require('@google-cloud/bigquery');
724 * const bigquery = new BigQuery();
725 *
726 * const options = {
727 * configuration: {
728 * query: {
729 * query: 'SELECT url FROM `publicdata.samples.github_nested` LIMIT 100'
730 * }
731 * }
732 * };
733 *
734 * bigquery.createJob(options, function(err, job) {
735 * if (err) {
736 * // Error handling omitted.
737 * }
738 *
739 * job.getQueryResults(function(err, rows) {});
740 * });
741 *
742 * //-
743 * // If the callback is omitted, we'll return a Promise.
744 * //-
745 * bigquery.createJob(options).then(function(data) {
746 * const job = data[0];
747 *
748 * return job.getQueryResults();
749 * });
750 * ```
751 */
752 createJob(options: JobOptions): Promise<JobResponse>;
753 createJob(options: JobOptions, callback: JobCallback): void;
754 /**
755 * Create a reference to a dataset.
756 *
757 * @param {string} id ID of the dataset.
758 * @param {object} [options] Dataset options.
759 * @param {string} [options.projectId] The GCP project ID.
760 * @param {string} [options.location] The geographic location of the dataset.
761 * Required except for US and EU.
762 *
763 * @example
764 * ```
765 * const {BigQuery} = require('@google-cloud/bigquery');
766 * const bigquery = new BigQuery();
767 * const dataset = bigquery.dataset('higher_education');
768 * ```
769 */
770 dataset(id: string, options?: DatasetOptions): Dataset;
771 /**
772 * List all or some of the datasets in a project.
773 *
774 * See {@link https://cloud.google.com/bigquery/docs/reference/v2/datasets/list| Datasets: list API Documentation}
775 *
776 * @param {object} [options] Configuration object.
777 * @param {boolean} [options.all] List all datasets, including hidden ones.
778 * @param {string} [options.projectId] The GCP project ID.
779 * @param {boolean} [options.autoPaginate] Have pagination handled automatically.
780 * Default: true.
781 * @param {number} [options.maxApiCalls] Maximum number of API calls to make.
782 * @param {number} [options.maxResults] Maximum number of results to return.
783 * @param {string} [options.pageToken] Token returned from a previous call, to
784 * request the next page of results.
785 * @param {DatasetsCallback} [callback] The callback function.
786 * @param {?error} callback.err An error returned while making this request
787 * @param {Dataset[]} callback.datasets The list of datasets in your project.
788 *
789 * @example
790 * ```
791 * const {BigQuery} = require('@google-cloud/bigquery');
792 * const bigquery = new BigQuery();
793 *
794 * bigquery.getDatasets(function(err, datasets) {
795 * if (!err) {
796 * // datasets is an array of Dataset objects.
797 * }
798 * });
799 *
800 * //-
801 * // To control how many API requests are made and page through the results
802 * // manually, set `autoPaginate` to `false`.
803 * //-
804 * function manualPaginationCallback(err, datasets, nextQuery, apiResponse) {
805 * if (nextQuery) {
806 * // More results exist.
807 * bigquery.getDatasets(nextQuery, manualPaginationCallback);
808 * }
809 * }
810 *
811 * bigquery.getDatasets({
812 * autoPaginate: false
813 * }, manualPaginationCallback);
814 *
815 * //-
816 * // If the callback is omitted, we'll return a Promise.
817 * //-
818 * bigquery.getDatasets().then(function(datasets) {});
819 * ```
820 */
821 getDatasets(options?: GetDatasetsOptions): Promise<DatasetsResponse>;
822 getDatasets(options: GetDatasetsOptions, callback: DatasetsCallback): void;
823 getDatasets(callback: DatasetsCallback): void;
824 /**
825 * @callback GetJobsCallback
826 * @param {?Error} err Request error, if any.
827 * @param {object} jobs An array of [Job]{@link https://cloud.google.com/bigquery/docs/reference/v2/Job} objects.
828 */
829 /**
830 * @typedef {array} GetJobsResponse
831 * @property {object} 0 An array of Job objects.
832 */
833 /**
834 * Get all of the jobs from your project.
835 *
836 * See {@link https://cloud.google.com/bigquery/docs/reference/v2/jobs/list| Jobs: list API Documentation}
837 *
838 * @param {object} [options] Configuration object.
839 * @param {boolean} [options.allUsers] Display jobs owned by all users in the
840 * project.
841 * @param {boolean} [options.autoPaginate] Have pagination handled
842 * automatically. Default: true.
843 * @param {number} [options.maxApiCalls] Maximum number of API calls to make.
844 * @param {number} [options.maxResults] Maximum number of results to return.
845 * @param {string} [options.pageToken] Token returned from a previous call, to
846 * request the next page of results.
847 * @param {string} [options.projection] Restrict information returned to a set
848 * of selected fields. Acceptable values are "full", for all job data, and
849 * "minimal", to not include the job configuration.
850 * @param {string} [options.stateFilter] Filter for job state. Acceptable
851 * values are "done", "pending", and "running". Sending an array to this
852 * option performs a disjunction.
853 * @param {GetJobsCallback} [callback] The callback function.
854 * @param {?error} callback.err An error returned while making this request
855 * @param {Job[]} callback.jobs The list of jobs in your
856 * project.
857 *
858 * @example
859 * ```
860 * const {BigQuery} = require('@google-cloud/bigquery');
861 * const bigquery = new BigQuery();
862 *
863 * bigquery.getJobs(function(err, jobs) {
864 * if (!err) {
865 * // jobs is an array of Job objects.
866 * }
867 * });
868 *
869 * //-
870 * // To control how many API requests are made and page through the results
871 * // manually, set `autoPaginate` to `false`.
872 * //-
873 * function manualPaginationCallback(err, jobs, nextQuery, apiRespose) {
874 * if (nextQuery) {
875 * // More results exist.
876 * bigquery.getJobs(nextQuery, manualPaginationCallback);
877 * }
878 * }
879 *
880 * bigquery.getJobs({
881 * autoPaginate: false
882 * }, manualPaginationCallback);
883 *
884 * //-
885 * // If the callback is omitted, we'll return a Promise.
886 * //-
887 * bigquery.getJobs().then(function(data) {
888 * const jobs = data[0];
889 * });
890 * ```
891 */
892 getJobs(options?: GetJobsOptions): Promise<GetJobsResponse>;
893 getJobs(options: GetJobsOptions, callback: GetJobsCallback): void;
894 getJobs(callback: GetJobsCallback): void;
895 /**
896 * Create a reference to an existing job.
897 *
898 * @param {string} id ID of the job.
899 * @param {object} [options] Configuration object.
900 * @param {string} [options.location] The geographic location of the job.
901 * Required except for US and EU.
902 *
903 * @example
904 * ```
905 * const {BigQuery} = require('@google-cloud/bigquery');
906 * const bigquery = new BigQuery();
907 *
908 * const myExistingJob = bigquery.job('job-id');
909 * ```
910 */
911 job(id: string, options?: JobOptions): Job;
912 /**
913 * Run a query scoped to your project. For manual pagination please refer to
914 * {@link BigQuery.createQueryJob}.
915 *
916 * See {@link https://cloud.google.com/bigquery/docs/reference/v2/jobs/query| Jobs: query API Documentation}
917 *
918 * @param {string|object} query A string SQL query or configuration object.
919 * For all available options, see
920 * {@link https://cloud.google.com/bigquery/docs/reference/v2/jobs/query#request-body| Jobs: query request body}.
921 * @param {string} [query.location] The geographic location of the job.
922 * Required except for US and EU.
923 * @param {string} [query.jobId] Custom id for the underlying job.
924 * @param {string} [query.jobPrefix] Prefix to apply to the underlying job id.
925 * @param {object|Array<*>} query.params For positional SQL parameters, provide
926 * an array of values. For named SQL parameters, provide an object which
927 * maps each named parameter to its value. The supported types are
928 * integers, floats, {@link BigQuery.date} objects, {@link BigQuery.datetime}
929 * objects, {@link BigQuery.time} objects, {@link BigQuery.timestamp}
930 * objects, Strings, Booleans, and Objects.
931 * @param {string} query.query A query string, following the BigQuery query
932 * syntax, of the query to execute.
933 * @param {object|Array<*>} query.types Provided types for query parameters.
934 * For positional SQL parameters, provide an array of types. For named
935 * SQL parameters, provide an object which maps each named parameter to
936 * its type.
937 * @param {boolean} [query.useLegacySql=false] Option to use legacy sql syntax.
938 * @param {object} [options] Configuration object for query results.
939 * @param {number} [options.maxResults] Maximum number of results to read.
940 * @param {number} [options.timeoutMs] How long to wait for the query to
941 * complete, in milliseconds, before returning. Default is 10 seconds.
942 * If the timeout passes before the job completes, an error will be returned
943 * and the 'jobComplete' field in the response will be false.
944 * @param {boolean|IntegerTypeCastOptions} [options.wrapIntegers=false] Wrap values
945 * of 'INT64' type in {@link BigQueryInt} objects.
946 * If a `boolean`, this will wrap values in {@link BigQueryInt} objects.
947 * If an `object`, this will return a value returned by
948 * `wrapIntegers.integerTypeCastFunction`.
949 * Please see {@link IntegerTypeCastOptions} for options descriptions.
950 * @param {function} [callback] The callback function.
951 * @param {?error} callback.err An error returned while making this request
952 * @param {array} callback.rows The list of results from your query.
953 *
954 * @example
955 * ```
956 * const {BigQuery} = require('@google-cloud/bigquery');
957 * const bigquery = new BigQuery();
958 *
959 * const query = 'SELECT url FROM `publicdata.samples.github_nested` LIMIT
960 * 100';
961 *
962 * bigquery.query(query, function(err, rows) {
963 * if (!err) {
964 * // rows is an array of results.
965 * }
966 * });
967 *
968 * //-
969 * // Positional SQL parameters are supported.
970 * //-
971 * bigquery.query({
972 * query: [
973 * 'SELECT url',
974 * 'FROM `publicdata.samples.github_nested`',
975 * 'WHERE repository.owner = ?'
976 * ].join(' '),
977 *
978 * params: [
979 * 'google'
980 * ]
981 * }, function(err, rows) {});
982 *
983 * //-
984 * // Or if you prefer to name them, that's also supported.
985 * //-
986 * bigquery.query({
987 * query: [
988 * 'SELECT url',
989 * 'FROM `publicdata.samples.github_nested`',
990 * 'WHERE repository.owner = @owner'
991 * ].join(' '),
992 * params: {
993 * owner: 'google'
994 * }
995 * }, function(err, rows) {});
996 *
997 * //-
998 * // Providing types for SQL parameters is supported.
999 * //-
1000 * bigquery.query({
1001 * query: [
1002 * 'SELECT url',
1003 * 'FROM `publicdata.samples.github_nested`',
1004 * 'WHERE repository.owner = ?'
1005 * ].join(' '),
1006 *
1007 * params: [
1008 * null
1009 * ],
1010 *
1011 * types: ['string']
1012 * }, function(err, rows) {});
1013 *
1014 * //-
1015 * // If you need to use a `DATE`, `DATETIME`, `TIME`, or `TIMESTAMP` type in
1016 * // your query, see {@link BigQuery.date}, {@link BigQuery.datetime},
1017 * // {@link BigQuery.time}, and {@link BigQuery.timestamp}.
1018 * //-
1019 *
1020 * //-
1021 * // If the callback is omitted, we'll return a Promise.
1022 * //-
1023 * bigquery.query(query).then(function(data) {
1024 * const rows = data[0];
1025 * });
1026 * ```
1027 */
1028 query(query: string, options?: QueryOptions): Promise<QueryRowsResponse>;
1029 query(query: Query, options?: QueryOptions): Promise<SimpleQueryRowsResponse>;
1030 query(query: string, options: QueryOptions, callback?: QueryRowsCallback): void;
1031 query(query: Query, options: QueryOptions, callback?: SimpleQueryRowsCallback): void;
1032 query(query: string, callback?: QueryRowsCallback): void;
1033 query(query: Query, callback?: SimpleQueryRowsCallback): void;
1034 /**
1035 * This method will be called by `createQueryStream()`. It is required to
1036 * properly set the `autoPaginate` option value.
1037 *
1038 * @private
1039 */
1040 queryAsStream_(query: Query, callback?: SimpleQueryRowsCallback): void;
1041}
1042/**
1043 * Date class for BigQuery.
1044 */
1045export declare class BigQueryDate {
1046 value: string;
1047 constructor(value: BigQueryDateOptions | string);
1048}
1049/**
1050 * Geography class for BigQuery.
1051 */
1052export declare class Geography {
1053 value: string;
1054 constructor(value: string);
1055}
1056/**
1057 * Timestamp class for BigQuery.
1058 */
1059export declare class BigQueryTimestamp {
1060 value: string;
1061 constructor(value: Date | PreciseDate | string | number);
1062 fromFloatValue_(value: number): PreciseDate;
1063}
1064/**
1065 * Datetime class for BigQuery.
1066 */
1067export declare class BigQueryDatetime {
1068 value: string;
1069 constructor(value: BigQueryDatetimeOptions | string);
1070}
1071/**
1072 * Time class for BigQuery.
1073 */
1074export declare class BigQueryTime {
1075 value: string;
1076 constructor(value: BigQueryTimeOptions | string);
1077}
1078/**
1079 * Build a BigQueryInt object. For long integers, a string can be provided.
1080 *
1081 * @class
1082 * @param {string|number|IntegerTypeCastValue} value The 'INT64' value.
1083 * @param {object} [typeCastOptions] Configuration to convert
1084 * values of 'INT64' type to a custom value. Must provide an
1085 * `integerTypeCastFunction` to handle conversion.
1086 * @param {function} typeCastOptions.integerTypeCastFunction A custom user
1087 * provided function to convert value.
1088 * @param {string|string[]} [typeCastOptions.fields] Schema field
1089 * names to be converted using `integerTypeCastFunction`.
1090 *
1091 * @example
1092 * ```
1093 * const {BigQuery} = require('@google-cloud/bigquery');
1094 * const bigquery = new BigQuery();
1095 * const anInt = bigquery.int(7);
1096 * ```
1097 */
1098export declare class BigQueryInt extends Number {
1099 type: string;
1100 value: string;
1101 typeCastFunction?: Function;
1102 private _schemaFieldName;
1103 constructor(value: string | number | IntegerTypeCastValue, typeCastOptions?: IntegerTypeCastOptions);
1104 valueOf(): any;
1105 toJSON(): Json;
1106}
1107export interface Json {
1108 [field: string]: string;
1109}
1110
\No newline at end of file