BigQueryWriteClient

BigQueryWriteClient

BigQuery Write API.

The Write API can be used to write data to BigQuery.

For supplementary information about the Write API, see: https://cloud.google.com/bigquery/docs/write-api

Constructor

new BigQueryWriteClient(optionsopt)

Construct an instance of BigQueryWriteClient.

Parameters:
Name Type Attributes Description
options object <optional>

The configuration object. The options accepted by the constructor are described in detail in this document. The common options are:

Properties
Name Type Attributes Description
credentials object <optional>

Credentials object.

Properties
Name Type Attributes Description
client_email string <optional>
private_key string <optional>
email string <optional>

Account email address. Required when using a .pem or .p12 keyFilename.

keyFilename string <optional>

Full path to the a .json, .pem, or .p12 key downloaded from the Google Developers Console. If you provide a path to a JSON file, the projectId option below is not necessary. NOTE: .pem and .p12 require you to specify options.email as well.

port number <optional>

The port on which to connect to the remote host.

projectId string <optional>

The project ID from the Google Developer's Console, e.g. 'grape-spaceship-123'. We will also check the environment variable GCLOUD_PROJECT for your project ID. If your app is running in an environment which supports Application Default Credentials, your project ID will be detected automatically.

apiEndpoint string <optional>

The domain name of the API remote host.

clientConfig gax.ClientConfig <optional>

Client configuration override. Follows the structure of gapicConfig.

fallback boolean <optional>

Use HTTP fallback mode. In fallback mode, a special browser-compatible transport implementation is used instead of gRPC transport. In browser context (if the window object is defined) the fallback mode is enabled automatically; set options.fallback to false if you need to override this behavior.

Members

apiEndpoint

The DNS address for this API service - same as servicePath(), exists for compatibility reasons.

port

The port for this API service.

scopes

The scopes needed to make gRPC calls for every method defined in this service.

servicePath

The DNS address for this API service.

Methods

appendRows(optionsopt) → {Stream}

Appends data to the given stream.

If offset is specified, the offset is checked against the end of stream. The server returns OUT_OF_RANGE in AppendRowsResponse if an attempt is made to append to an offset beyond the current end of the stream or ALREADY_EXISTS if user provides an offset that has already been written to. User can retry with adjusted offset within the same RPC connection. If offset is not specified, append happens at the end of the stream.

The response contains an optional offset at which the append happened. No offset information will be returned for appends to a default stream.

Responses are received in the same order in which requests are sent. There will be one response for each successful inserted request. Responses may optionally embed error information if the originating AppendRequest was not successfully processed.

The specifics of when successfully appended data is made visible to the table are governed by the type of stream:

  • For COMMITTED streams (which includes the default stream), data is visible immediately upon successful append.

  • For BUFFERED streams, data is made visible via a subsequent FlushRows rpc which advances a cursor to a newer offset in the stream.

  • For PENDING streams, data is not made visible until the stream itself is finalized (via the FinalizeWriteStream rpc), and the stream is explicitly committed via the BatchCommitWriteStreams rpc.

Parameters:
Name Type Attributes Description
options object <optional>

Call options. See CallOptions for more details.

Returns:
Type Description
Stream

An object stream which is both readable and writable. It accepts objects representing AppendRowsRequest for write() method, and will emit objects representing AppendRowsResponse on 'data' event asynchronously. Please see the documentation for more details and examples.

Example
const stream = client.appendRows();
stream.on('data', (response) => { ... });
stream.on('end', () => { ... });
stream.write(request);
stream.end();

batchCommitWriteStreams(request, optionsopt) → {Promise}

Atomically commits a group of PENDING streams that belong to the same parent table.

Streams must be finalized before commit and cannot be committed multiple times. Once a stream is committed, data in the stream becomes available for read operations.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
parent string

Required. Parent table that all the streams should belong to, in the form of projects/{project}/datasets/{dataset}/tables/{table}.

writeStreams Array.<string>

Required. The group of streams that will be committed atomically.

options object <optional>

Call options. See CallOptions for more details.

Returns:
Type Description
Promise
Example
const [response] = await client.batchCommitWriteStreams(request);

close() → {Promise}

Terminate the gRPC channel and close the client.

The client will no longer be usable and all future behavior is undefined.

Returns:
Type Description
Promise

A promise that resolves when the client is closed.

createWriteStream(request, optionsopt) → {Promise}

Creates a write stream to the given table. Additionally, every table has a special stream named '_default' to which data can be written. This stream doesn't need to be created using CreateWriteStream. It is a stream that can be used simultaneously by any number of clients. Data written to this stream is considered committed as soon as an acknowledgement is received.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
parent string

Required. Reference to the table to which the stream belongs, in the format of projects/{project}/datasets/{dataset}/tables/{table}.

writeStream google.cloud.bigquery.storage.v1.WriteStream

Required. Stream to be created.

options object <optional>

Call options. See CallOptions for more details.

Returns:
Type Description
Promise
  • The promise which resolves to an array. The first element of the array is an object representing WriteStream. Please see the documentation for more details and examples.
Example
const [response] = await client.createWriteStream(request);

finalizeWriteStream(request, optionsopt) → {Promise}

Finalize a write stream so that no new data can be appended to the stream. Finalize is not supported on the '_default' stream.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
name string

Required. Name of the stream to finalize, in the form of projects/{project}/datasets/{dataset}/tables/{table}/streams/{stream}.

options object <optional>

Call options. See CallOptions for more details.

Returns:
Type Description
Promise
Example
const [response] = await client.finalizeWriteStream(request);

flushRows(request, optionsopt) → {Promise}

Flushes rows to a BUFFERED stream.

If users are appending rows to BUFFERED stream, flush operation is required in order for the rows to become available for reading. A Flush operation flushes up to any previously flushed offset in a BUFFERED stream, to the offset specified in the request.

Flush is not supported on the _default stream, since it is not BUFFERED.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
writeStream string

Required. The stream that is the target of the flush operation.

offset google.protobuf.Int64Value

Ending offset of the flush operation. Rows before this offset(including this offset) will be flushed.

options object <optional>

Call options. See CallOptions for more details.

Returns:
Type Description
Promise
  • The promise which resolves to an array. The first element of the array is an object representing FlushRowsResponse. Please see the documentation for more details and examples.
Example
const [response] = await client.flushRows(request);

getProjectId() → {Promise}

Return the project ID used by this class.

Returns:
Type Description
Promise

A promise that resolves to string containing the project ID.

getWriteStream(request, optionsopt) → {Promise}

Gets information about a write stream.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
name string

Required. Name of the stream to get, in the form of projects/{project}/datasets/{dataset}/tables/{table}/streams/{stream}.

options object <optional>

Call options. See CallOptions for more details.

Returns:
Type Description
Promise
  • The promise which resolves to an array. The first element of the array is an object representing WriteStream. Please see the documentation for more details and examples.
Example
const [response] = await client.getWriteStream(request);

initialize() → {Promise}

Initialize the client. Performs asynchronous operations (such as authentication) and prepares the client. This function will be called automatically when any class method is called for the first time, but if you need to initialize it before calling an actual method, feel free to call initialize() directly.

You can await on this method if you want to make sure the client is initialized.

Returns:
Type Description
Promise

A promise that resolves to an authenticated service stub.

matchDatasetFromTableName(tableName) → {string}

Parse the dataset from Table resource.

Parameters:
Name Type Description
tableName string

A fully-qualified path representing Table resource.

Returns:
Type Description
string

A string representing the dataset.

matchDatasetFromWriteStreamName(writeStreamName) → {string}

Parse the dataset from WriteStream resource.

Parameters:
Name Type Description
writeStreamName string

A fully-qualified path representing WriteStream resource.

Returns:
Type Description
string

A string representing the dataset.

matchLocationFromReadSessionName(readSessionName) → {string}

Parse the location from ReadSession resource.

Parameters:
Name Type Description
readSessionName string

A fully-qualified path representing ReadSession resource.

Returns:
Type Description
string

A string representing the location.

matchLocationFromReadStreamName(readStreamName) → {string}

Parse the location from ReadStream resource.

Parameters:
Name Type Description
readStreamName string

A fully-qualified path representing ReadStream resource.

Returns:
Type Description
string

A string representing the location.

matchProjectFromProjectName(projectName) → {string}

Parse the project from Project resource.

Parameters:
Name Type Description
projectName string

A fully-qualified path representing Project resource.

Returns:
Type Description
string

A string representing the project.

matchProjectFromReadSessionName(readSessionName) → {string}

Parse the project from ReadSession resource.

Parameters:
Name Type Description
readSessionName string

A fully-qualified path representing ReadSession resource.

Returns:
Type Description
string

A string representing the project.

matchProjectFromReadStreamName(readStreamName) → {string}

Parse the project from ReadStream resource.

Parameters:
Name Type Description
readStreamName string

A fully-qualified path representing ReadStream resource.

Returns:
Type Description
string

A string representing the project.

matchProjectFromTableName(tableName) → {string}

Parse the project from Table resource.

Parameters:
Name Type Description
tableName string

A fully-qualified path representing Table resource.

Returns:
Type Description
string

A string representing the project.

matchProjectFromWriteStreamName(writeStreamName) → {string}

Parse the project from WriteStream resource.

Parameters:
Name Type Description
writeStreamName string

A fully-qualified path representing WriteStream resource.

Returns:
Type Description
string

A string representing the project.

matchSessionFromReadSessionName(readSessionName) → {string}

Parse the session from ReadSession resource.

Parameters:
Name Type Description
readSessionName string

A fully-qualified path representing ReadSession resource.

Returns:
Type Description
string

A string representing the session.

matchSessionFromReadStreamName(readStreamName) → {string}

Parse the session from ReadStream resource.

Parameters:
Name Type Description
readStreamName string

A fully-qualified path representing ReadStream resource.

Returns:
Type Description
string

A string representing the session.

matchStreamFromReadStreamName(readStreamName) → {string}

Parse the stream from ReadStream resource.

Parameters:
Name Type Description
readStreamName string

A fully-qualified path representing ReadStream resource.

Returns:
Type Description
string

A string representing the stream.

matchStreamFromWriteStreamName(writeStreamName) → {string}

Parse the stream from WriteStream resource.

Parameters:
Name Type Description
writeStreamName string

A fully-qualified path representing WriteStream resource.

Returns:
Type Description
string

A string representing the stream.

matchTableFromTableName(tableName) → {string}

Parse the table from Table resource.

Parameters:
Name Type Description
tableName string

A fully-qualified path representing Table resource.

Returns:
Type Description
string

A string representing the table.

matchTableFromWriteStreamName(writeStreamName) → {string}

Parse the table from WriteStream resource.

Parameters:
Name Type Description
writeStreamName string

A fully-qualified path representing WriteStream resource.

Returns:
Type Description
string

A string representing the table.

projectPath(project) → {string}

Return a fully-qualified project resource name string.

Parameters:
Name Type Description
project string
Returns:
Type Description
string

Resource name string.

readSessionPath(project, location, session) → {string}

Return a fully-qualified readSession resource name string.

Parameters:
Name Type Description
project string
location string
session string
Returns:
Type Description
string

Resource name string.

readStreamPath(project, location, session, stream) → {string}

Return a fully-qualified readStream resource name string.

Parameters:
Name Type Description
project string
location string
session string
stream string
Returns:
Type Description
string

Resource name string.

tablePath(project, dataset, table) → {string}

Return a fully-qualified table resource name string.

Parameters:
Name Type Description
project string
dataset string
table string
Returns:
Type Description
string

Resource name string.

writeStreamPath(project, dataset, table, stream) → {string}

Return a fully-qualified writeStream resource name string.

Parameters:
Name Type Description
project string
dataset string
table string
stream string
Returns:
Type Description
string

Resource name string.