UNPKG

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