Class managedwriter.WriterClient (4.8.0)

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

This class provides the ability to make remote calls to the backing service through method calls that map to API methods.

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

managedwriter

Package

@google-cloud/bigquery-storage

Constructors

(constructor)(opts)

constructor(opts?: ClientOptions);

Constructs a new instance of the WriterClient class

Parameter
Name Description
opts ClientOptions

Properties

getClient

getClient: () => BigQueryWriteClient;

initialize

initialize: () => Promise<void>;

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.

setClient

setClient: (client: BigQueryWriteClient) => void;

Methods

batchCommitWriteStream(request)

batchCommitWriteStream(request: BatchCommitWriteStreamsRequest): Promise<BatchCommitWriteStreamsResponse>;

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.

Parameter
Name Description
request BatchCommitWriteStreamsRequest

The request object that will be sent.

Returns
Type Description
Promise<BatchCommitWriteStreamsResponse>

{Promise} - a promise which resolves to an .

close()

close(): void;
Returns
Type Description
void

createStreamConnection(request, options)

createStreamConnection(request: {
        streamId?: string;
        destinationTable?: string;
        streamType?: WriteStreamType;
    }, options?: CallOptions): Promise<StreamConnection>;

Open StreamConnection in which data can be appended to the given stream.

If a stream is created beforehand with createWriteStream, the streamId can be passed here.

Or destinationTable + streamType can be passed so the WriteStreamStream is created under the hood.

Parameters
Name Description
request { streamId?: string; destinationTable?: string; streamType?: WriteStreamType; }
options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
Promise<StreamConnection>

{StreamConnection} - stream which rows can be appended to.

createWriteStream(request, options)

createWriteStream(request: {
        streamType: WriteStreamType;
        destinationTable: string;
    }, options?: CallOptions): Promise<string>;

Creates a write stream to the given table and return just the streamId.

Additionally, every table has a special stream named DefaultStream 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 Description
request { streamType: WriteStreamType; destinationTable: string; }

The request object that will be sent.

options CallOptions
Returns
Type Description
Promise<string>

{Promise

createWriteStreamFullResponse(request, options)

createWriteStreamFullResponse(request: {
        streamType: WriteStreamType;
        destinationTable: string;
    }, options?: CallOptions): Promise<WriteStream>;

Creates a write stream to the given table and return all information about it.

Additionally, every table has a special stream named DefaultStream 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 Description
request { streamType: WriteStreamType; destinationTable: string; }

The request object that will be sent.

options CallOptions
Returns
Type Description
Promise<WriteStream>

{Promise

enableWriteRetries(enable)

enableWriteRetries(enable: boolean): void;

Enables StreamConnections to automatically retry failed appends.

Enabling retries is best suited for cases where users want to achieve at-least-once append semantics. Use of automatic retries may complicate patterns where the user is designing for exactly-once append semantics.

Parameter
Name Description
enable boolean
Returns
Type Description
void

finalizeWriteStream(request)

finalizeWriteStream(request: FinalizeWriteStreamRequest): Promise<FinalizeWriteStreamResponse>;

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

Parameter
Name Description
request FinalizeWriteStreamRequest

The request object that will be sent.

Returns
Type Description
Promise<FinalizeWriteStreamResponse_2>

{Promise

flushRows(request)

flushRows(request?: FlushRowsRequest): Promise<FlushRowsResponse>;

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.

Parameter
Name Description
request FlushRowsRequest

The request object that will be sent.

Returns
Type Description
Promise<FlushRowsResponse_2>

{Promise} - The promise which resolves to a .

getWriteStream(request, options)

getWriteStream(request: {
        streamId: string;
        view?: WriteStreamView;
    }, options?: CallOptions): Promise<WriteStream>;

Gets information about a write stream.

Parameters
Name Description
request { streamId: string; view?: WriteStreamView; }

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
Promise<WriteStream>

{Promise

isOpen()

isOpen(): boolean;

Check if client is open and ready to send requests.

Returns
Type Description
boolean

setMaxRetryAttempts(retryAttempts)

setMaxRetryAttempts(retryAttempts: number): void;

Change max retries attempts on child StreamConnections.

The default valuen is to retry 4 times.

Only valid right now when write retries are enabled.

Parameter
Name Description
retryAttempts number
Returns
Type Description
void