Class BigQuery (5.7.1)

In the following examples from this page and the other modules (Dataset, Table, etc.), we are going to be using a dataset from [data.gov](http://goo.gl/f2SXcb) of higher education institutions.

We will create a table with the correct schema, import the public CSV file into that table, and query it for data.

[What is BigQuery?]https://cloud.google.com/bigquery/what-is-bigquery

Inheritance

common.Service > BigQuery

Package

@google-cloud/bigquery!

Constructors

(constructor)(options)

constructor(options?: BigQueryOptions);

Constructs a new instance of the BigQuery class

Parameter
NameDescription
options BigQueryOptions

Properties

createQueryStream

createQueryStream: (options?: Query | string) => ResourceStream<RowMetadata>;
Property Value
TypeDescription
(options?: Query | string) => ResourceStream<RowMetadata>

getDatasetsStream

getDatasetsStream: (options?: GetDatasetsOptions) => ResourceStream<Dataset>;
Property Value
TypeDescription
(options?: GetDatasetsOptions) => ResourceStream<Dataset>

getJobsStream

getJobsStream: (options?: GetJobsOptions) => ResourceStream<Job>;
Property Value
TypeDescription
(options?: GetJobsOptions) => ResourceStream<Job>

location

location?: string;
Property Value
TypeDescription
string

Methods

createDataset(id, options)

createDataset(id: string, options?: DatasetResource): Promise<DatasetResponse>;
Parameters
NameDescription
id string
options DatasetResource
Returns
TypeDescription
Promise<DatasetResponse>

createDataset(id, options, callback)

createDataset(id: string, options: DatasetResource, callback: DatasetCallback): void;
Parameters
NameDescription
id string
options DatasetResource
callback DatasetCallback
Returns
TypeDescription
void

createDataset(id, callback)

createDataset(id: string, callback: DatasetCallback): void;
Parameters
NameDescription
id string
callback DatasetCallback
Returns
TypeDescription
void

createJob(options)

createJob(options: JobOptions): Promise<JobResponse>;
Parameter
NameDescription
options JobOptions
Returns
TypeDescription
Promise<JobResponse>

createJob(options, callback)

createJob(options: JobOptions, callback: JobCallback): void;
Parameters
NameDescription
options JobOptions
callback JobCallback
Returns
TypeDescription
void

createQueryJob(options)

createQueryJob(options: Query | string): Promise<JobResponse>;
Parameter
NameDescription
options Query | string
Returns
TypeDescription
Promise<JobResponse>

createQueryJob(options, callback)

createQueryJob(options: Query | string, callback: JobCallback): void;
Parameters
NameDescription
options Query | string
callback JobCallback
Returns
TypeDescription
void

dataset(id, options)

dataset(id: string, options?: DatasetOptions): Dataset;

Create a reference to a dataset.

Parameters
NameDescription
id string

ID of the dataset.

options DatasetOptions

Dataset options.

Returns
TypeDescription
Dataset

{Dataset}

date(value)

date(value: BigQueryDateOptions | string): BigQueryDate;
Parameter
NameDescription
value BigQueryDateOptions | string

The date. If a string, this should be in the format the API describes: YYYY-[M]M-[D]D. Otherwise, provide an object.

Returns
TypeDescription
BigQueryDate

date(value)

static date(value: BigQueryDateOptions | string): BigQueryDate;

The DATE type represents a logical calendar date, independent of time zone. It does not represent a specific 24-hour time period. Rather, a given DATE value represents a different 24-hour period when interpreted in different time zones, and may represent a shorter or longer day during Daylight Savings Time transitions.

Parameter
NameDescription
value BigQueryDateOptions | string

The date. If a string, this should be in the format the API describes: YYYY-[M]M-[D]D. Otherwise, provide an object.

Returns
TypeDescription
BigQueryDate

datetime(value)

datetime(value: BigQueryDatetimeOptions | string): BigQueryDatetime;
Parameter
NameDescription
value BigQueryDatetimeOptions | string
Returns
TypeDescription
BigQueryDatetime

datetime(value)

static datetime(value: BigQueryDatetimeOptions | string): BigQueryDatetime;

A DATETIME data type represents a point in time. Unlike a TIMESTAMP, this does not refer to an absolute instance in time. Instead, it is the civil time, or the time that a user would see on a watch or calendar.

BigQuery#datetime

Parameter
NameDescription
value BigQueryDatetimeOptions | string

The time. If a string, this should be in the format the API describes: YYYY-[M]M-[D]D[ [H]H:[M]M:[S]S[.DDDDDD]]. Otherwise, provide an object.

Returns
TypeDescription
BigQueryDatetime

decodeIntegerValue_(value)

static decodeIntegerValue_(value: IntegerTypeCastValue): number;

Convert an INT64 value to Number.

Parameter
NameDescription
value IntegerTypeCastValue

The INT64 value to convert.

Returns
TypeDescription
number

geography(value)

geography(value: string): Geography;
Parameter
NameDescription
value string
Returns
TypeDescription
Geography

geography(value)

static geography(value: string): Geography;

A geography value represents a surface area on the Earth in Well-known Text (WKT) format.

BigQuery#geography

Parameter
NameDescription
value string

The geospatial data.

Returns
TypeDescription
Geography

getDatasets(options)

getDatasets(options?: GetDatasetsOptions): Promise<DatasetsResponse>;
Parameter
NameDescription
options GetDatasetsOptions
Returns
TypeDescription
Promise<DatasetsResponse>

getDatasets(options, callback)

getDatasets(options: GetDatasetsOptions, callback: DatasetsCallback): void;
Parameters
NameDescription
options GetDatasetsOptions
callback DatasetsCallback
Returns
TypeDescription
void

getDatasets(callback)

getDatasets(callback: DatasetsCallback): void;
Parameter
NameDescription
callback DatasetsCallback
Returns
TypeDescription
void

getJobs(options)

getJobs(options?: GetJobsOptions): Promise<GetJobsResponse>;
Parameter
NameDescription
options GetJobsOptions
Returns
TypeDescription
Promise<GetJobsResponse>

getJobs(options, callback)

getJobs(options: GetJobsOptions, callback: GetJobsCallback): void;
Parameters
NameDescription
options GetJobsOptions
callback GetJobsCallback
Returns
TypeDescription
void

getJobs(callback)

getJobs(callback: GetJobsCallback): void;
Parameter
NameDescription
callback GetJobsCallback
Returns
TypeDescription
void

getTypeDescriptorFromProvidedType_(providedType)

static getTypeDescriptorFromProvidedType_(providedType: string | ProvidedTypeStruct | ProvidedTypeArray): ValueType;

Return a value's provided type.

Parameter
NameDescription
providedType string | ProvidedTypeStruct | ProvidedTypeArray

The type.

Returns
TypeDescription
ValueType

{string} The valid type provided.

getTypeDescriptorFromValue_(value)

static getTypeDescriptorFromValue_(value: unknown): ValueType;

Detect a value's type.

Parameter
NameDescription
value unknown

The value.

Returns
TypeDescription
ValueType

{string} The type detected from the value.

int(value, typeCastOptions)

int(value: string | number | IntegerTypeCastValue, typeCastOptions?: IntegerTypeCastOptions): BigQueryInt;
Parameters
NameDescription
value string | number | IntegerTypeCastValue
typeCastOptions IntegerTypeCastOptions
Returns
TypeDescription
BigQueryInt

int(value, typeCastOptions)

static int(value: string | number | IntegerTypeCastValue, typeCastOptions?: IntegerTypeCastOptions): BigQueryInt;

A BigQueryInt wraps 'INT64' values. Can be used to maintain precision.

BigQuery#int

Parameters
NameDescription
value string | number | IntegerTypeCastValue

The INT64 value to convert.

typeCastOptions IntegerTypeCastOptions

Configuration to convert value. Must provide an integerTypeCastFunction to handle conversion.

Returns
TypeDescription
BigQueryInt

job(id, options)

job(id: string, options?: JobOptions): Job;

Create a reference to an existing job.

Parameters
NameDescription
id string

ID of the job.

options JobOptions

Configuration object.

Returns
TypeDescription
Job

{Job}

mergeSchemaWithRows_(schema, rows, wrapIntegers, selectedFields)

static mergeSchemaWithRows_(schema: TableSchema | TableField, rows: TableRow[], wrapIntegers: boolean | IntegerTypeCastOptions, selectedFields?: string[]): any[];

Merge a rowset returned from the API with a table schema.

Parameters
NameDescription
schema TableSchema | TableField
rows TableRow[]
wrapIntegers boolean | IntegerTypeCastOptions

Wrap values of 'INT64' type in BigQueryInt objects. If a boolean, this will wrap values in BigQueryInt objects. If an object, this will return a value returned by wrapIntegers.integerTypeCastFunction. Please see IntegerTypeCastOptions for options descriptions.

selectedFields string[]

List of fields to return. If unspecified, all fields are returned.

Returns
TypeDescription
any[]

{array} Fields using their matching names from the table's schema.

query(query, options)

query(query: string, options?: QueryOptions): Promise<QueryRowsResponse>;
Parameters
NameDescription
query string
options QueryOptions
Returns
TypeDescription
Promise<QueryRowsResponse>

query(query, options)

query(query: Query, options?: QueryOptions): Promise<SimpleQueryRowsResponse>;
Parameters
NameDescription
query Query
options QueryOptions
Returns
TypeDescription
Promise<SimpleQueryRowsResponse>

query(query, options, callback)

query(query: string, options: QueryOptions, callback?: QueryRowsCallback): void;
Parameters
NameDescription
query string
options QueryOptions
callback QueryRowsCallback
Returns
TypeDescription
void

query(query, options, callback)

query(query: Query, options: QueryOptions, callback?: SimpleQueryRowsCallback): void;
Parameters
NameDescription
query Query
options QueryOptions
callback SimpleQueryRowsCallback
Returns
TypeDescription
void

query(query, callback)

query(query: string, callback?: QueryRowsCallback): void;
Parameters
NameDescription
query string
callback QueryRowsCallback
Returns
TypeDescription
void

query(query, callback)

query(query: Query, callback?: SimpleQueryRowsCallback): void;
Parameters
NameDescription
query Query
callback SimpleQueryRowsCallback
Returns
TypeDescription
void

queryAsStream_(query, optionsOrCallback, cb)

queryAsStream_(query: Query, optionsOrCallback?: QueryStreamOptions, cb?: SimpleQueryRowsCallback): void;

This method will be called by createQueryStream(). It is required to properly set the autoPaginate option value.

Parameters
NameDescription
query Query
optionsOrCallback QueryStreamOptions
cb SimpleQueryRowsCallback
Returns
TypeDescription
void

time(value)

time(value: BigQueryTimeOptions | string): BigQueryTime;
Parameter
NameDescription
value BigQueryTimeOptions | string
Returns
TypeDescription
BigQueryTime

time(value)

static time(value: BigQueryTimeOptions | string): BigQueryTime;

A TIME data type represents a time, independent of a specific date.

BigQuery#time

Parameter
NameDescription
value BigQueryTimeOptions | string

The time. If a string, this should be in the format the API describes: [H]H:[M]M:[S]S[.DDDDDD]. Otherwise, provide an object.

Returns
TypeDescription
BigQueryTime

timestamp(value)

timestamp(value: Date | string): BigQueryTimestamp;
Parameter
NameDescription
value Date | string
Returns
TypeDescription
BigQueryTimestamp

timestamp(value)

static timestamp(value: Date | string): BigQueryTimestamp;

A timestamp represents an absolute point in time, independent of any time zone or convention such as Daylight Savings Time.

BigQuery#timestamp

Parameter
NameDescription
value Date | string

The time.

Returns
TypeDescription
BigQueryTimestamp

valueToQueryParameter_(value, providedType)

static valueToQueryParameter_(value: any, providedType?: string | ProvidedTypeStruct | ProvidedTypeArray): bigquery.IQueryParameter;

Convert a value into a queryParameter object.

[Jobs.query API Reference Docs (see queryParameters)]https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/query#request-body

Parameters
NameDescription
value any

The value.

providedType string | ProvidedTypeStruct | ProvidedTypeArray

Provided query parameter type.

Returns
TypeDescription
bigquery.IQueryParameter

{object} A properly-formed queryParameter object.