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
Properties
createQueryStream
createQueryStream: (options?: Query | string) => ResourceStream<RowMetadata>;
Property Value
Type | Description |
(options?: Query | string) => ResourceStream<RowMetadata> | |
getDatasetsStream
getDatasetsStream: (options?: GetDatasetsOptions) => ResourceStream<Dataset>;
Property Value
Type | Description |
(options?: GetDatasetsOptions) => ResourceStream<Dataset> | |
getJobsStream
getJobsStream: (options?: GetJobsOptions) => ResourceStream<Job>;
Property Value
Type | Description |
(options?: GetJobsOptions) => ResourceStream<Job> | |
location
Property Value
Methods
createDataset(id, options)
createDataset(id: string, options?: DatasetResource): Promise<DatasetResponse>;
Parameters
Name | Description |
id |
string
|
options |
DatasetResource
|
Returns
Type | Description |
Promise<DatasetResponse> | |
createDataset(id, options, callback)
createDataset(id: string, options: DatasetResource, callback: DatasetCallback): void;
Parameters
Name | Description |
id |
string
|
options |
DatasetResource
|
callback |
DatasetCallback
|
Returns
createDataset(id, callback)
createDataset(id: string, callback: DatasetCallback): void;
Parameters
Name | Description |
id |
string
|
callback |
DatasetCallback
|
Returns
createJob(options)
createJob(options: JobOptions): Promise<JobResponse>;
Parameter
Name | Description |
options |
JobOptions
|
Returns
Type | Description |
Promise<JobResponse> | |
createJob(options, callback)
createJob(options: JobOptions, callback: JobCallback): void;
Parameters
Name | Description |
options |
JobOptions
|
callback |
JobCallback
|
Returns
createQueryJob(options)
createQueryJob(options: Query | string): Promise<JobResponse>;
Parameter
Name | Description |
options |
Query | string
|
Returns
Type | Description |
Promise<JobResponse> | |
createQueryJob(options, callback)
createQueryJob(options: Query | string, callback: JobCallback): void;
Parameters
Name | Description |
options |
Query | string
|
callback |
JobCallback
|
Returns
dataset(id, options)
dataset(id: string, options?: DatasetOptions): Dataset;
Create a reference to a dataset.
Parameters
Name | Description |
id |
string
ID of the dataset.
|
options |
DatasetOptions
Dataset options.
|
Returns
Type | Description |
Dataset | {Dataset}
|
date(value)
date(value: BigQueryDateOptions | string): BigQueryDate;
Parameter
Name | Description |
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
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
Name | Description |
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
datetime(value)
datetime(value: BigQueryDatetimeOptions | string): BigQueryDatetime;
Parameter
Returns
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
Name | Description |
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
decodeIntegerValue_(value)
static decodeIntegerValue_(value: IntegerTypeCastValue): number;
Convert an INT64 value to Number.
Parameter
Name | Description |
value |
IntegerTypeCastValue
The INT64 value to convert.
|
Returns
geography(value)
geography(value: string): Geography;
Parameter
Name | Description |
value |
string
|
Returns
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
Name | Description |
value |
string
The geospatial data.
|
Returns
getDatasets(options)
getDatasets(options?: GetDatasetsOptions): Promise<DatasetsResponse>;
Parameter
Name | Description |
options |
GetDatasetsOptions
|
Returns
Type | Description |
Promise<DatasetsResponse> | |
getDatasets(options, callback)
getDatasets(options: GetDatasetsOptions, callback: DatasetsCallback): void;
Parameters
Name | Description |
options |
GetDatasetsOptions
|
callback |
DatasetsCallback
|
Returns
getDatasets(callback)
getDatasets(callback: DatasetsCallback): void;
Parameter
Name | Description |
callback |
DatasetsCallback
|
Returns
getJobs(options)
getJobs(options?: GetJobsOptions): Promise<GetJobsResponse>;
Parameter
Name | Description |
options |
GetJobsOptions
|
Returns
Type | Description |
Promise<GetJobsResponse> | |
getJobs(options, callback)
getJobs(options: GetJobsOptions, callback: GetJobsCallback): void;
Parameters
Name | Description |
options |
GetJobsOptions
|
callback |
GetJobsCallback
|
Returns
getJobs(callback)
getJobs(callback: GetJobsCallback): void;
Parameter
Name | Description |
callback |
GetJobsCallback
|
Returns
getTypeDescriptorFromProvidedType_(providedType)
static getTypeDescriptorFromProvidedType_(providedType: string | ProvidedTypeStruct | ProvidedTypeArray): ValueType;
Return a value's provided type.
Parameter
Returns
Type | Description |
ValueType | {string} The valid type provided.
|
getTypeDescriptorFromValue_(value)
static getTypeDescriptorFromValue_(value: unknown): ValueType;
Parameter
Name | Description |
value |
unknown
The value.
|
Returns
Type | Description |
ValueType | {string} The type detected from the value.
|
int(value, typeCastOptions)
int(value: string | number | IntegerTypeCastValue, typeCastOptions?: IntegerTypeCastOptions): BigQueryInt;
Parameters
Returns
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
Name | Description |
value |
string | number | IntegerTypeCastValue
The INT64 value to convert.
|
typeCastOptions |
IntegerTypeCastOptions
Configuration to convert value. Must provide an integerTypeCastFunction to handle conversion.
|
Returns
job(id, options)
job(id: string, options?: JobOptions): Job;
Create a reference to an existing job.
Parameters
Name | Description |
id |
string
ID of the job.
|
options |
JobOptions
Configuration object.
|
Returns
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
Name | Description |
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
Type | Description |
any[] | {array} Fields using their matching names from the table's schema.
|
query(query, options)
query(query: string, options?: QueryOptions): Promise<QueryRowsResponse>;
Parameters
Name | Description |
query |
string
|
options |
QueryOptions
|
Returns
Type | Description |
Promise<QueryRowsResponse> | |
query(query, options)
query(query: Query, options?: QueryOptions): Promise<SimpleQueryRowsResponse>;
Parameters
Name | Description |
query |
Query
|
options |
QueryOptions
|
Returns
Type | Description |
Promise<SimpleQueryRowsResponse> | |
query(query, options, callback)
query(query: string, options: QueryOptions, callback?: QueryRowsCallback): void;
Parameters
Name | Description |
query |
string
|
options |
QueryOptions
|
callback |
QueryRowsCallback
|
Returns
query(query, options, callback)
query(query: Query, options: QueryOptions, callback?: SimpleQueryRowsCallback): void;
Parameters
Name | Description |
query |
Query
|
options |
QueryOptions
|
callback |
SimpleQueryRowsCallback
|
Returns
query(query, callback)
query(query: string, callback?: QueryRowsCallback): void;
Parameters
Name | Description |
query |
string
|
callback |
QueryRowsCallback
|
Returns
query(query, callback)
query(query: Query, callback?: SimpleQueryRowsCallback): void;
Parameters
Name | Description |
query |
Query
|
callback |
SimpleQueryRowsCallback
|
Returns
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
Name | Description |
query |
Query
|
optionsOrCallback |
QueryStreamOptions
|
cb |
SimpleQueryRowsCallback
|
Returns
time(value)
time(value: BigQueryTimeOptions | string): BigQueryTime;
Parameter
Returns
time(value)
static time(value: BigQueryTimeOptions | string): BigQueryTime;
A TIME
data type represents a time, independent of a specific date.
BigQuery#time
Parameter
Name | Description |
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
timestamp(value)
timestamp(value: Date | string): BigQueryTimestamp;
Parameter
Name | Description |
value |
Date | string
|
Returns
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
Name | Description |
value |
Date | string
The time.
|
Returns
valueToQueryParameter_(value, providedType)
static valueToQueryParameter_(value: any, providedType?: string | ProvidedTypeStruct | ProvidedTypeArray): bigquery.IQueryParameter;
Parameters
Name | Description |
value |
any
The value.
|
providedType |
string | ProvidedTypeStruct | ProvidedTypeArray
Provided query parameter type.
|
Returns
Type | Description |
bigquery.IQueryParameter | {object} A properly-formed queryParameter object.
|