Movatterモバイル変換


[0]ホーム

URL:


Table

Table

Table objects are returned by methods such asDataset#table, Dataset#createTable, andDataset#getTables.

Constructor

new Table(dataset, id, optionsopt)

Parameters:
NameTypeAttributesDescription
datasetDataset

Dataset instance.

id string

The ID of the table.

options object <optional>

Table options.

Properties
NameTypeAttributesDescription
location string <optional>

The geographic location of the table, bydefault this value is inherited from the dataset. This can be used toconfigure the location of all jobs created through a table instance. Itcannot be used to set the actual location of the table. This value willbe superseded by any API responses containing location data for thetable.

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

Members

createReadStream

Create a readable stream of the rows of data in your table. This methodis simply a wrapper aroundTable#getRows.

SeeTabledata: list API Documentation

Example
```const {BigQuery} = require('@google-cloud/bigquery');const bigquery = new BigQuery();const dataset = bigquery.dataset('my-dataset');const table = dataset.table('my-table');table.createReadStream(options)  .on('error', console.error)  .on('data', row => {})  .on('end', function() {    // All rows have been retrieved.  });//-// If you anticipate many results, you can end a stream early to prevent// unnecessary processing and API requests.//-table.createReadStream()  .on('data', function(row) {    this.end();  });```

Methods

create(optionsopt, callbackopt) → {Promise.<CreateTableResponse>}

Create a table.

Parameters:
NameTypeAttributesDescription
options object <optional>

See Dataset#createTable.

callbackCreateTableCallback <optional>
Properties
NameTypeAttributesDescription
err error <nullable>

An error returned while making thisrequest.

tableTable

The newTable.

apiResponse object

The full API response.

Returns:
TypeDescription
Promise.<CreateTableResponse>
Example
```const {BigQuery} = require('@google-cloud/bigquery');const bigquery = new BigQuery();const dataset = bigquery.dataset('my-dataset');const table = dataset.table('my-table');table.create((err, table, apiResponse) => {  if (!err) {    // The table was created successfully.  }});//-// If the callback is omitted, we'll return a Promise.//-table.create().then((data) => {  const table = data[0];  const apiResponse = data[1];});```

createQueryStream(query) → {stream}

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

SeeBigQuery#createQueryStream for full documentation of thismethod.

Parameters:
NameTypeDescription
query object

SeeBigQuery#createQueryStream for fulldocumentation of this method.

Returns:
TypeDescription
stream

SeeBigQuery#createQueryStream for fulldocumentation of this method.

createWriteStream(metadataopt) → {WritableStream}

Load data into your table from a readable stream of AVRO, CSV, JSON, ORC,or PARQUET data.

SeeJobs: insert API Documentation

Parameters:
NameTypeAttributesDescription
metadata string | object <optional>

Metadata to set with the load operation.The metadata object should be in the format of theconfiguration.loadproperty of a Jobs resource. If a string is given,it will be used as the filetype.

Properties
NameTypeAttributesDescription
jobId string <optional>

Custom job id.

jobPrefix string <optional>

Prefix to apply to the job id.

Returns:
TypeDescription
WritableStream
Throws:

If source format isn't recognized.

Type
Error
Example
```const {BigQuery} = require('@google-cloud/bigquery');const bigquery = new BigQuery();const dataset = bigquery.dataset('my-dataset');const table = dataset.table('my-table');//-// Load data from a CSV file.//-const request = require('request');const csvUrl = 'http://goo.gl/kSE7z6';const metadata = {  allowJaggedRows: true,  skipLeadingRows: 1};request.get(csvUrl)  .pipe(table.createWriteStream(metadata))  .on('job', (job) => {    // `job` is a Job object that can be used to check the status of the    // request.  })  .on('complete', (job) => {    // The job has completed successfully.  });//-// Load data from a JSON file.//-const fs = require('fs');fs.createReadStream('./test/testdata/testfile.json')  .pipe(table.createWriteStream('json'))  .on('job', (job) => {    // `job` is a Job object that can be used to check the status of the    // request.  })  .on('complete', (job) => {    // The job has completed successfully.  });```

delete(callbackopt) → {Promise.<DeleteTableResponse>}

Delete a table and all its data.

SeeTables: delete API Documentation

Parameters:
NameTypeAttributesDescription
callbackDeleteTableCallback <optional>
Properties
NameTypeAttributesDescription
err error <nullable>

An error returned while making thisrequest.

apiResponse object

The full API response.

Returns:
TypeDescription
Promise.<DeleteTableResponse>
Example
```const {BigQuery} = require('@google-cloud/bigquery');const bigquery = new BigQuery();const dataset = bigquery.dataset('my-dataset');const table = dataset.table('my-table');table.delete((err, apiResponse) => {});//-// If the callback is omitted, we'll return a Promise.//-table.delete().then((data) => {  const apiResponse = data[0];});```

exists(callbackopt) → {Promise.<TableExistsCallback>}

Check if the table exists.

Parameters:
NameTypeAttributesDescription
callbackTableExistsCallback <optional>
Properties
NameTypeAttributesDescription
err error <nullable>

An error returned while making thisrequest.

exists boolean

Whether the table exists or not.

Returns:
TypeDescription
Promise.<TableExistsCallback>
Example
```const {BigQuery} = require('@google-cloud/bigquery');const bigquery = new BigQuery();const dataset = bigquery.dataset('my-dataset');const table = dataset.table('my-table');table.exists((err, exists) => {});//-// If the callback is omitted, we'll return a Promise.//-table.exists().then((data) => {  const exists = data[0];});```

get(optionsopt, callbackopt) → {Promise.<GetTableResponse>}

Get a table if it exists.

You may optionally use this to "get or create" an object by providingan object withautoCreate set totrue. Any extra configuration thatis normally required for thecreate method must be contained withinthis object as well.

If you wish to get a selection of metadata instead of the full table metadata(retrieved by both Table#get by default and by Table#getMetadata), usetheoptions parameter to set theview and/orselectedFields query parameters.

SeeTables.get and TableMetadataView

Parameters:
NameTypeAttributesDescription
options options <optional>

Configuration object.

Properties
NameTypeAttributesDefaultDescription
autoCreate boolean <optional>
false

Automatically create theobject if it does not exist.

callback function <optional>
Properties
NameTypeAttributesDescription
err error <nullable>

An error returned while making thisrequest.

tableTable

TheTable.

apiResponse object

The full API response.

Returns:
TypeDescription
Promise.<GetTableResponse>
Example
```const {BigQuery} = require('@google-cloud/bigquery');const bigquery = new BigQuery();const dataset = bigquery.dataset('my-dataset');const table = dataset.table('my-table');const options = {  view: "BASIC"}table.get((err, table, apiResponse) => {  // `table.metadata` has been populated.});table.get(options, (err, table, apiResponse) => {  // A selection of `table.metadata` has been populated})//-// If the callback is omitted, we'll return a Promise.//-table.get().then((data) => {  const table = data[0];  const apiResponse = data[1];});```

getMetadata(callbackopt) → {Promise.<GetTableMetadataResponse>}

Return the metadata associated with the Table.

SeeTables: get API Documentation

Parameters:
NameTypeAttributesDescription
callbackGetTableMetadataCallback <optional>

The callback function.

Properties
NameTypeAttributesDescription
err error <nullable>

An error returned while making thisrequest.

metadata object

The metadata of the Table.

apiResponse object

The full API response.

Returns:
TypeDescription
Promise.<GetTableMetadataResponse>
Example
```const {BigQuery} = require('@google-cloud/bigquery');const bigquery = new BigQuery();const dataset = bigquery.dataset('my-dataset');const table = dataset.table('my-table');table.getMetadata((err, metadata, apiResponse) => {});//-// If the callback is omitted, we'll return a Promise.//-table.getMetadata().then((data) => {  const metadata = data[0];  const apiResponse = data[1];});```

getRows(optionsopt, callbackopt) → {Promise.<RowsResponse>}

Retrieves table data from a specified set of rows. The rows are returned toyour callback as an array of objects matching your table's schema.

SeeTabledata: list API Documentation

Parameters:
NameTypeAttributesDescription
options object <optional>

The configuration object.

Properties
NameTypeAttributesDefaultDescription
autoPaginate boolean <optional>
true

Have pagination handledautomatically.

maxApiCalls number <optional>

Maximum number of API calls to make.

maxResults number <optional>

Maximum number of results to return.

wrapIntegers boolean | IntegerTypeCastOptions <optional>
false

Wrap valuesof 'INT64' type inBigQueryInt objects.If aboolean, this will wrap values inBigQueryInt objects.If anobject, this will return a value returned bywrapIntegers.integerTypeCastFunction.

callback RowsCallback <optional>

The callback function. IfautoPaginateis set to false aManualQueryResultsCallback should be used.

Properties
NameTypeAttributesDescription
err error <nullable>

An error returned while making this request

rows array

The table data from specified set of rows.

Returns:
TypeDescription
Promise.<RowsResponse>
Example
```const {BigQuery} = require('@google-cloud/bigquery');const bigquery = new BigQuery();const dataset = bigquery.dataset('my-dataset');const table = dataset.table('my-table');table.getRows((err, rows) => {  if (!err) {    // rows is an array of results.  }});//-// To control how many API requests are made and page through the results// manually, set `autoPaginate` to `false`.//-function manualPaginationCallback(err, rows, nextQuery, apiResponse) {  if (nextQuery) {    // More results exist.    table.getRows(nextQuery, manualPaginationCallback);  }}table.getRows({  autoPaginate: false}, manualPaginationCallback);//-// If the callback is omitted, we'll return a Promise.//-table.getRows().then((data) => {  const rows = data[0];  });```


[8]ページ先頭

©2009-2025 Movatter.jp