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