Movatterモバイル変換


[0]ホーム

URL:


BigQuery

BigQuery

SeeWhat is BigQuery?

Constructor

new BigQuery(options)

Parameters:
NameTypeDescription
optionsBigQueryOptions

Constructor options.

Examples
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();

Members

getDatasetsStream

List all or some of theDataset objects in your project asa readable object stream.

Example
```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();  });```

getJobsStream

List all or some of theJob objects in your project as areadable object stream.

Example
```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();  });```

Methods

buildQueryRequest_(query, options)

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.

Parameters:
NameTypeDescription
query

string | Query

options

QueryOptions

Returns:
TypeDescription

bigquery.IQueryRequest | undefined

createQueryStream(query)

Run a query scoped to your project as a readable object stream.

Parameters:
NameTypeDescription
query object

Configuration object. See BigQuery.query for a completelist of options.

Example
```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();  });```

dataset(id, optionsopt)

Create a reference to a dataset.

Parameters:
NameTypeAttributesDescription
id string

ID of the dataset.

options object <optional>

Dataset options.

Properties
NameTypeAttributesDescription
projectId string <optional>

The GCP project ID.

location string <optional>

The geographic location of the dataset.Required except for US and EU.

Example
```const {BigQuery} = require('@google-cloud/bigquery');const bigquery = new BigQuery();const dataset = bigquery.dataset('higher_education');```

date(value)

Parameters:
NameTypeDescription
value object | string

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

Properties
NameTypeDescription
year string | number

Four digits.

month string | number

One or two digits.

day string | number

One or two digits.

Example
```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});```

job(id, optionsopt)

Create a reference to an existing job.

Parameters:
NameTypeAttributesDescription
id string

ID of the job.

options object <optional>

Configuration object.

Properties
NameTypeAttributesDescription
location string <optional>

The geographic location of the job.Required except for US and EU.

Example
```const {BigQuery} = require('@google-cloud/bigquery');const bigquery = new BigQuery();const myExistingJob = bigquery.job('job-id');```

range(value, elementType)

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.

Parameters:
NameTypeDescription
value string | BigQueryRangeOptions

The range API string or start/end with dates/datetimes/timestamp ranges.

elementType string

The range element type - DATE|DATETIME|TIMESTAMP

Example
```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');```

timestamp(value)

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.

Parameters:
NameTypeDescription
value Date | string | string | number

The time.

Example
```const {BigQuery} = require('@google-cloud/bigquery');const bigquery = new BigQuery();const timestamp = bigquery.timestamp(new Date());```

(static)date(value)

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.

Parameters:
NameTypeDescription
value object | string

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

Properties
NameTypeDescription
year string | number

Four digits.

month string | number

One or two digits.

day string | number

One or two digits.

Example
```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});```

(static)datetime(value)

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.

Parameters:
NameTypeDescription
value object | string

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

Properties
NameTypeAttributesDescription
year string | number

Four digits.

month string | number

One or two digits.

day string | number

One or two digits.

hours string | number <optional>

One or two digits (00 -23).

minutes string | number <optional>

One or two digits (00 -59).

seconds string | number <optional>

One or two digits (00 -59).

fractional string | number <optional>

Up to six digits for microsecondprecision.

Example
```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});```

(static)datetime(value)

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.

Parameters:
NameTypeDescription
value object | string

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

Properties
NameTypeAttributesDescription
year string | number

Four digits.

month string | number

One or two digits.

day string | number

One or two digits.

hours string | number <optional>

One or two digits (00 -23).

minutes string | number <optional>

One or two digits (00 -59).

seconds string | number <optional>

One or two digits (00 -59).

fractional string | number <optional>

Up to six digits for microsecondprecision.

Example
```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});```

(static)geography(value)

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

Parameters:
NameTypeDescription
value string

The geospatial data.

Example
```const {BigQuery} = require('@google-cloud/bigquery');const bigquery = new BigQuery();const geography = bigquery.geography('POINT(1, 2)');```

(static)int(value, typeCastOptions) → {BigQueryInt}

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

Parameters:
NameTypeDescription
value string | number | IntegerTypeCastValue

The INT64 value to convert.

typeCastOptions IntegerTypeCastOptions

Configuration to convertvalue. Must provide anintegerTypeCastFunction to handle conversion.

Returns:
TypeDescription
BigQueryInt
Example
```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`.```

(static)range(value, elementType)

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.

Parameters:
NameTypeDescription
value string | BigQueryRangeOptions

The range API string or start/end with dates/datetimes/timestamp ranges.

elementType string

The range element type - DATE|DATETIME|TIMESTAMP

Example
```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');```

(static)time(value)

ATIME data type represents a time, independent of a specific date.

Parameters:
NameTypeDescription
value object | string

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

Properties
NameTypeAttributesDescription
hours string | number <optional>

One or two digits (00 -23).

minutes string | number <optional>

One or two digits (00 -59).

seconds string | number <optional>

One or two digits (00 -59).

fractional string | number <optional>

Up to six digits for microsecondprecision.

Example
```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});```

(static)time(value)

ATIME data type represents a time, independent of a specific date.

Parameters:
NameTypeDescription
value object | string

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

Properties
NameTypeAttributesDescription
hours string | number <optional>

One or two digits (00 -23).

minutes string | number <optional>

One or two digits (00 -59).

seconds string | number <optional>

One or two digits (00 -59).

fractional string | number <optional>

Up to six digits for microsecondprecision.

Example
```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});```

(static)timestamp(value)

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.

Parameters:
NameTypeDescription
value Date | string

The time.

Example
```const {BigQuery} = require('@google-cloud/bigquery');const timestamp = BigQuery.timestamp(new Date());```


[8]ページ先頭

©2009-2025 Movatter.jp