| Name | Type | Description |
|---|---|---|
options | BigQueryOptions | Constructor options. |
Install the client library with <a href="https://www.npmjs.com/">npm</a>:```npm install @google-cloud/bigquery```Import the client library```const {BigQuery} = require('@google-cloud/bigquery');```Create a client that uses <a href="https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application">Application Default Credentials (ADC)</a>:```const bigquery = new BigQuery();```Create a client with <a href="https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually">explicit credentials</a>:```const bigquery = new BigQuery({ projectId: 'your-project-id', keyFilename: '/path/to/keyfile.json'});```Full quickstart example:
// Imports the Google Cloud client library const {BigQuery} = require('@google-cloud/bigquery'); async function createDataset() { // Creates a client const bigqueryClient = new BigQuery(); // Create the dataset const [dataset] = await bigqueryClient.createDataset(datasetName); console.log(`Dataset ${dataset.id} created.`); } createDataset();List all or some of theDataset objects in your project asa readable object stream.
```const {BigQuery} = require('@google-cloud/bigquery');const bigquery = new BigQuery();bigquery.getDatasetsStream() .on('error', console.error) .on('data', function(dataset) { // dataset is a Dataset object. }) .on('end', function() { // All datasets retrieved. });//-// If you anticipate many results, you can end a stream early to prevent// unnecessary processing and API requests.//-bigquery.getDatasetsStream() .on('data', function(dataset) { this.end(); });```List all or some of theJob objects in your project as areadable object stream.
```const {BigQuery} = require('@google-cloud/bigquery');const bigquery = new BigQuery();bigquery.getJobsStream() .on('error', console.error) .on('data', function(job) { // job is a Job object. }) .on('end', function() { // All jobs retrieved. });//-// If you anticipate many results, you can end a stream early to prevent// unnecessary processing and API requests.//-bigquery.getJobsStream() .on('data', function(job) { this.end(); });```Check if the given Query can run using thejobs.query endpoint.Returns a bigquery.IQueryRequest that can be used to calljobs.query.Return undefined if is not possible to convert to a bigquery.IQueryRequest.
| Name | Type | Description |
|---|---|---|
query | string | Query | |
options | QueryOptions |
| Type | Description |
|---|---|
bigquery.IQueryRequest | undefined |
Run a query scoped to your project as a readable object stream.
| Name | Type | Description |
|---|---|---|
query | object | Configuration object. See BigQuery.query for a completelist of options. |
```const {BigQuery} = require('@google-cloud/bigquery');const bigquery = new BigQuery();const query = 'SELECT url FROM `publicdata.samples.github_nested` LIMIT100';bigquery.createQueryStream(query) .on('error', console.error) .on('data', function(row) { // row is a result from your query. }) .on('end', function() { // All rows retrieved. });//-// If you anticipate many results, you can end a stream early to prevent// unnecessary processing and API requests.//-bigquery.createQueryStream(query) .on('data', function(row) { this.end(); });```Create a reference to a dataset.
| Name | Type | Attributes | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | string | ID of the dataset. | |||||||||||||
options | object | <optional> | Dataset options. Properties
|
```const {BigQuery} = require('@google-cloud/bigquery');const bigquery = new BigQuery();const dataset = bigquery.dataset('higher_education');```| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
value | object | string | The date. If a string, this should be in theformat the API describes: Properties
|
```const {BigQuery} = require('@google-cloud/bigquery');const date = BigQuery.date('2017-01-01');//-// Alternatively, provide an object.//-const date2 = BigQuery.date({ year: 2017, month: 1, day: 1});```Create a reference to an existing job.
| Name | Type | Attributes | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
id | string | ID of the job. | |||||||||
options | object | <optional> | Configuration object. Properties
|
```const {BigQuery} = require('@google-cloud/bigquery');const bigquery = new BigQuery();const myExistingJob = bigquery.job('job-id');```A range represents contiguous range between two dates, datetimes, or timestamps.The lower and upper bound for the range are optional.The lower bound is inclusive and the upper bound is exclusive.
| Name | Type | Description |
|---|---|---|
value | string | BigQueryRangeOptions | The range API string or start/end with dates/datetimes/timestamp ranges. |
elementType | string | The range element type - DATE|DATETIME|TIMESTAMP |
```const {BigQuery} = require('@google-cloud/bigquery');const bigquery = new BigQuery();const timestampRange = bigquery.range('[2020-10-01 12:00:00+08, 2020-12-31 12:00:00+08)', 'TIMESTAMP');```A timestamp represents an absolute point in time, independent of any timezone or convention such as Daylight Savings Time.
The recommended input here is aDate orPreciseDate class.If passing as astring, it should be Timestamp literals: https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#timestamp_literals.When passing anumber input, it should be epoch seconds in float representation.
| Name | Type | Description |
|---|---|---|
value | Date | string | string | number | The time. |
```const {BigQuery} = require('@google-cloud/bigquery');const bigquery = new BigQuery();const timestamp = bigquery.timestamp(new Date());```TheDATE type represents a logical calendar date, independent of timezone. It does not represent a specific 24-hour time period. Rather, a givenDATE value represents a different 24-hour period when interpreted indifferent time zones, and may represent a shorter or longer day duringDaylight Savings Time transitions.
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
value | object | string | The date. If a string, this should be in theformat the API describes: Properties
|
```const {BigQuery} = require('@google-cloud/bigquery');const bigquery = new BigQuery();const date = bigquery.date('2017-01-01');//-// Alternatively, provide an object.//-const date2 = bigquery.date({ year: 2017, month: 1, day: 1});```ADATETIME data type represents a point in time. Unlike aTIMESTAMP,this does not refer to an absolute instance in time. Instead, it is thecivil time, or the time that a user would see on a watch or calendar.
| Name | Type | Description | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
value | object | string | The time. If a string, this should be in theformat the API describes: Properties
|
```const {BigQuery} = require('@google-cloud/bigquery');const datetime = BigQuery.datetime('2017-01-01 13:00:00');//-// Alternatively, provide an object.//-const datetime = BigQuery.datetime({ year: 2017, month: 1, day: 1, hours: 14, minutes: 0, seconds: 0});```ADATETIME data type represents a point in time. Unlike aTIMESTAMP,this does not refer to an absolute instance in time. Instead, it is thecivil time, or the time that a user would see on a watch or calendar.
| Name | Type | Description | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
value | object | string | The time. If a string, this should be in theformat the API describes: Properties
|
```const {BigQuery} = require('@google-cloud/bigquery');const bigquery = new BigQuery();const datetime = bigquery.datetime('2017-01-01 13:00:00');//-// Alternatively, provide an object.//-const datetime = bigquery.datetime({ year: 2017, month: 1, day: 1, hours: 14, minutes: 0, seconds: 0});```A geography value represents a surface area on the Earthin Well-known Text (WKT) format.
| Name | Type | Description |
|---|---|---|
value | string | The geospatial data. |
```const {BigQuery} = require('@google-cloud/bigquery');const bigquery = new BigQuery();const geography = bigquery.geography('POINT(1, 2)');```A BigQueryInt wraps 'INT64' values. Can be used to maintain precision.
| Name | Type | Description |
|---|---|---|
value | string | number | IntegerTypeCastValue | The INT64 value to convert. |
typeCastOptions | IntegerTypeCastOptions | Configuration to convertvalue. Must provide an |
| Type | Description |
|---|---|
| BigQueryInt |
```const {BigQuery} = require('@google-cloud/bigquery');const bigquery = new BigQuery();const largeIntegerValue = Number.MAX_SAFE_INTEGER + 1;const options = { integerTypeCastFunction: value => value.split(),};const bqInteger = bigquery.int(largeIntegerValue, options);const customValue = bqInteger.valueOf();// customValue is the value returned from your `integerTypeCastFunction`.```A range represents contiguous range between two dates, datetimes, or timestamps.The lower and upper bound for the range are optional.The lower bound is inclusive and the upper bound is exclusive.
| Name | Type | Description |
|---|---|---|
value | string | BigQueryRangeOptions | The range API string or start/end with dates/datetimes/timestamp ranges. |
elementType | string | The range element type - DATE|DATETIME|TIMESTAMP |
```const {BigQuery} = require('@google-cloud/bigquery');const timestampRange = BigQuery.range('[2020-10-01 12:00:00+08, 2020-12-31 12:00:00+08)', 'TIMESTAMP');```ATIME data type represents a time, independent of a specific date.
| Name | Type | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
value | object | string | The time. If a string, this should be in theformat the API describes: Properties
|
```const {BigQuery} = require('@google-cloud/bigquery');const time = BigQuery.time('14:00:00'); // 2:00 PM//-// Alternatively, provide an object.//-const time = BigQuery.time({ hours: 14, minutes: 0, seconds: 0});```ATIME data type represents a time, independent of a specific date.
| Name | Type | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
value | object | string | The time. If a string, this should be in theformat the API describes: Properties
|
```const {BigQuery} = require('@google-cloud/bigquery');const bigquery = new BigQuery();const time = bigquery.time('14:00:00'); // 2:00 PM//-// Alternatively, provide an object.//-const time = bigquery.time({ hours: 14, minutes: 0, seconds: 0});```A timestamp represents an absolute point in time, independent of any timezone or convention such as Daylight Savings Time.
The recommended input here is aDate orPreciseDate class.If passing as astring, it should be Timestamp literals: https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#timestamp_literals.When passing anumber input, it should be epoch seconds in float representation.
| Name | Type | Description |
|---|---|---|
value | Date | string | The time. |