Class v1beta1.BigQueryStorageClient (3.2.0)

BigQuery storage API.

The BigQuery storage API can be used to read data stored in BigQuery. v1beta1

Package

@google-cloud/bigquery-storage

Constructors

(constructor)(opts, gaxInstance)

constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback);

Construct an instance of BigQueryStorageClient.

Parameters
NameDescription
opts ClientOptions
gaxInstance typeof gax | typeof gax.fallback

: loaded instance of google-gax. Useful if you need to avoid loading the default gRPC version and want to use the fallback HTTP implementation. Load only fallback version and pass it to the constructor: ``` const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC const client = new BigQueryStorageClient({fallback: 'rest'}, gax); ```

Properties

apiEndpoint

static get apiEndpoint(): string;

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

auth

auth: gax.GoogleAuth;

bigQueryStorageStub

bigQueryStorageStub?: Promise<{
        [name: string]: Function;
    }>;

descriptors

descriptors: Descriptors;

innerApiCalls

innerApiCalls: {
        [name: string]: Function;
    };

pathTemplates

pathTemplates: {
        [name: string]: gax.PathTemplate;
    };

port

static get port(): number;

The port for this API service.

scopes

static get scopes(): string[];

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

servicePath

static get servicePath(): string;

The DNS address for this API service.

warn

warn: (code: string, message: string, warnType?: string) => void;

Methods

batchCreateReadSessionStreams(request, options)

batchCreateReadSessionStreams(request?: protos.google.cloud.bigquery.storage.v1beta1.IBatchCreateReadSessionStreamsRequest, options?: CallOptions): Promise<[
        protos.google.cloud.bigquery.storage.v1beta1.IBatchCreateReadSessionStreamsResponse,
        (protos.google.cloud.bigquery.storage.v1beta1.IBatchCreateReadSessionStreamsRequest | undefined),
        {} | undefined
    ]>;

Creates additional streams for a ReadSession. This API can be used to dynamically adjust the parallelism of a batch processing task upwards by adding additional workers.

Parameters
NameDescription
request protos.google.cloud.bigquery.storage.v1beta1.IBatchCreateReadSessionStreamsRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[ protos.google.cloud.bigquery.storage.v1beta1.IBatchCreateReadSessionStreamsResponse, (protos.google.cloud.bigquery.storage.v1beta1.IBatchCreateReadSessionStreamsRequest | undefined), {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing [BatchCreateReadSessionStreamsResponse]. Please see the [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Must be a non-expired session obtained from a call to
   *  CreateReadSession. Only the name field needs to be set.
   */
  // const session = {}
  /**
   *  Required. Number of new streams requested. Must be positive.
   *  Number of added streams may be less than this, see CreateReadSessionRequest
   *  for more information.
   */
  // const requestedStreams = 1234

  // Imports the Storage library
  const {BigQueryStorageClient} = require('@google-cloud/bigquery-storage').v1beta1;

  // Instantiates a client
  const storageClient = new BigQueryStorageClient();

  async function callBatchCreateReadSessionStreams() {
    // Construct request
    const request = {
      session,
      requestedStreams,
    };

    // Run request
    const response = await storageClient.batchCreateReadSessionStreams(request);
    console.log(response);
  }

  callBatchCreateReadSessionStreams();

batchCreateReadSessionStreams(request, options, callback)

batchCreateReadSessionStreams(request: protos.google.cloud.bigquery.storage.v1beta1.IBatchCreateReadSessionStreamsRequest, options: CallOptions, callback: Callback<protos.google.cloud.bigquery.storage.v1beta1.IBatchCreateReadSessionStreamsResponse, protos.google.cloud.bigquery.storage.v1beta1.IBatchCreateReadSessionStreamsRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.bigquery.storage.v1beta1.IBatchCreateReadSessionStreamsRequest
options CallOptions
callback Callback<protos.google.cloud.bigquery.storage.v1beta1.IBatchCreateReadSessionStreamsResponse, protos.google.cloud.bigquery.storage.v1beta1.IBatchCreateReadSessionStreamsRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

batchCreateReadSessionStreams(request, callback)

batchCreateReadSessionStreams(request: protos.google.cloud.bigquery.storage.v1beta1.IBatchCreateReadSessionStreamsRequest, callback: Callback<protos.google.cloud.bigquery.storage.v1beta1.IBatchCreateReadSessionStreamsResponse, protos.google.cloud.bigquery.storage.v1beta1.IBatchCreateReadSessionStreamsRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.bigquery.storage.v1beta1.IBatchCreateReadSessionStreamsRequest
callback Callback<protos.google.cloud.bigquery.storage.v1beta1.IBatchCreateReadSessionStreamsResponse, protos.google.cloud.bigquery.storage.v1beta1.IBatchCreateReadSessionStreamsRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

close()

close(): Promise<void>;

Terminate the gRPC channel and close the client.

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

Returns
TypeDescription
Promise<void>

{Promise} A promise that resolves when the client is closed.

createReadSession(request, options)

createReadSession(request?: protos.google.cloud.bigquery.storage.v1beta1.ICreateReadSessionRequest, options?: CallOptions): Promise<[
        protos.google.cloud.bigquery.storage.v1beta1.IReadSession,
        (protos.google.cloud.bigquery.storage.v1beta1.ICreateReadSessionRequest | undefined),
        {} | undefined
    ]>;

Creates a new read session. A read session divides the contents of a BigQuery table into one or more streams, which can then be used to read data from the table. The read session also specifies properties of the data to be read, such as a list of columns or a push-down filter describing the rows to be returned.

A particular row can be read by at most one stream. When the caller has reached the end of each stream in the session, then all the data in the table has been read.

Read sessions automatically expire 24 hours after they are created and do not require manual clean-up by the caller.

Parameters
NameDescription
request protos.google.cloud.bigquery.storage.v1beta1.ICreateReadSessionRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[ protos.google.cloud.bigquery.storage.v1beta1.IReadSession, (protos.google.cloud.bigquery.storage.v1beta1.ICreateReadSessionRequest | undefined), {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing [ReadSession]. Please see the [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Reference to the table to read.
   */
  // const tableReference = {}
  /**
   *  Required. String of the form `projects/{project_id}` indicating the
   *  project this ReadSession is associated with. This is the project that will
   *  be billed for usage.
   */
  // const parent = 'abc123'
  /**
   *  Any modifiers to the Table (e.g. snapshot timestamp).
   */
  // const tableModifiers = {}
  /**
   *  Initial number of streams. If unset or 0, we will
   *  provide a value of streams so as to produce reasonable throughput. Must be
   *  non-negative. The number of streams may be lower than the requested number,
   *  depending on the amount parallelism that is reasonable for the table and
   *  the maximum amount of parallelism allowed by the system.
   *  Streams must be read starting from offset 0.
   */
  // const requestedStreams = 1234
  /**
   *  Read options for this session (e.g. column selection, filters).
   */
  // const readOptions = {}
  /**
   *  Data output format. Currently default to Avro.
   */
  // const format = {}
  /**
   *  The strategy to use for distributing data among multiple streams. Currently
   *  defaults to liquid sharding.
   */
  // const shardingStrategy = {}

  // Imports the Storage library
  const {BigQueryStorageClient} = require('@google-cloud/bigquery-storage').v1beta1;

  // Instantiates a client
  const storageClient = new BigQueryStorageClient();

  async function callCreateReadSession() {
    // Construct request
    const request = {
      tableReference,
      parent,
    };

    // Run request
    const response = await storageClient.createReadSession(request);
    console.log(response);
  }

  callCreateReadSession();

createReadSession(request, options, callback)

createReadSession(request: protos.google.cloud.bigquery.storage.v1beta1.ICreateReadSessionRequest, options: CallOptions, callback: Callback<protos.google.cloud.bigquery.storage.v1beta1.IReadSession, protos.google.cloud.bigquery.storage.v1beta1.ICreateReadSessionRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.bigquery.storage.v1beta1.ICreateReadSessionRequest
options CallOptions
callback Callback<protos.google.cloud.bigquery.storage.v1beta1.IReadSession, protos.google.cloud.bigquery.storage.v1beta1.ICreateReadSessionRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

createReadSession(request, callback)

createReadSession(request: protos.google.cloud.bigquery.storage.v1beta1.ICreateReadSessionRequest, callback: Callback<protos.google.cloud.bigquery.storage.v1beta1.IReadSession, protos.google.cloud.bigquery.storage.v1beta1.ICreateReadSessionRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.bigquery.storage.v1beta1.ICreateReadSessionRequest
callback Callback<protos.google.cloud.bigquery.storage.v1beta1.IReadSession, protos.google.cloud.bigquery.storage.v1beta1.ICreateReadSessionRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

finalizeStream(request, options)

finalizeStream(request?: protos.google.cloud.bigquery.storage.v1beta1.IFinalizeStreamRequest, options?: CallOptions): Promise<[
        protos.google.protobuf.IEmpty,
        (protos.google.cloud.bigquery.storage.v1beta1.IFinalizeStreamRequest | undefined),
        {} | undefined
    ]>;

Triggers the graceful termination of a single stream in a ReadSession. This API can be used to dynamically adjust the parallelism of a batch processing task downwards without losing data.

This API does not delete the stream -- it remains visible in the ReadSession, and any data processed by the stream is not released to other streams. However, no additional data will be assigned to the stream once this call completes. Callers must continue reading data on the stream until the end of the stream is reached so that data which has already been assigned to the stream will be processed.

This method will return an error if there are no other live streams in the Session, or if SplitReadStream() has been called on the given Stream.

Parameters
NameDescription
request protos.google.cloud.bigquery.storage.v1beta1.IFinalizeStreamRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[ protos.google.protobuf.IEmpty, (protos.google.cloud.bigquery.storage.v1beta1.IFinalizeStreamRequest | undefined), {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing [Empty]. Please see the [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Stream to finalize.
   */
  // const stream = {}

  // Imports the Storage library
  const {BigQueryStorageClient} = require('@google-cloud/bigquery-storage').v1beta1;

  // Instantiates a client
  const storageClient = new BigQueryStorageClient();

  async function callFinalizeStream() {
    // Construct request
    const request = {
      stream,
    };

    // Run request
    const response = await storageClient.finalizeStream(request);
    console.log(response);
  }

  callFinalizeStream();

finalizeStream(request, options, callback)

finalizeStream(request: protos.google.cloud.bigquery.storage.v1beta1.IFinalizeStreamRequest, options: CallOptions, callback: Callback<protos.google.protobuf.IEmpty, protos.google.cloud.bigquery.storage.v1beta1.IFinalizeStreamRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.bigquery.storage.v1beta1.IFinalizeStreamRequest
options CallOptions
callback Callback<protos.google.protobuf.IEmpty, protos.google.cloud.bigquery.storage.v1beta1.IFinalizeStreamRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

finalizeStream(request, callback)

finalizeStream(request: protos.google.cloud.bigquery.storage.v1beta1.IFinalizeStreamRequest, callback: Callback<protos.google.protobuf.IEmpty, protos.google.cloud.bigquery.storage.v1beta1.IFinalizeStreamRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.bigquery.storage.v1beta1.IFinalizeStreamRequest
callback Callback<protos.google.protobuf.IEmpty, protos.google.cloud.bigquery.storage.v1beta1.IFinalizeStreamRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

getProjectId()

getProjectId(): Promise<string>;
Returns
TypeDescription
Promise<string>

getProjectId(callback)

getProjectId(callback: Callback<string, undefined, undefined>): void;
Parameter
NameDescription
callback Callback<string, undefined, undefined>
Returns
TypeDescription
void

initialize()

initialize(): Promise<{
        [name: string]: Function;
    }>;

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
TypeDescription
Promise<{ [name: string]: Function; }>

{Promise} A promise that resolves to an authenticated service stub.

matchLocationFromReadSessionName(readSessionName)

matchLocationFromReadSessionName(readSessionName: string): string | number;

Parse the location from ReadSession resource.

Parameter
NameDescription
readSessionName string

A fully-qualified path representing ReadSession resource.

Returns
TypeDescription
string | number

{string} A string representing the location.

matchLocationFromStreamName(streamName)

matchLocationFromStreamName(streamName: string): string | number;

Parse the location from Stream resource.

Parameter
NameDescription
streamName string

A fully-qualified path representing Stream resource.

Returns
TypeDescription
string | number

{string} A string representing the location.

matchProjectFromProjectName(projectName)

matchProjectFromProjectName(projectName: string): string | number;

Parse the project from Project resource.

Parameter
NameDescription
projectName string

A fully-qualified path representing Project resource.

Returns
TypeDescription
string | number

{string} A string representing the project.

matchProjectFromReadSessionName(readSessionName)

matchProjectFromReadSessionName(readSessionName: string): string | number;

Parse the project from ReadSession resource.

Parameter
NameDescription
readSessionName string

A fully-qualified path representing ReadSession resource.

Returns
TypeDescription
string | number

{string} A string representing the project.

matchProjectFromStreamName(streamName)

matchProjectFromStreamName(streamName: string): string | number;

Parse the project from Stream resource.

Parameter
NameDescription
streamName string

A fully-qualified path representing Stream resource.

Returns
TypeDescription
string | number

{string} A string representing the project.

matchSessionFromReadSessionName(readSessionName)

matchSessionFromReadSessionName(readSessionName: string): string | number;

Parse the session from ReadSession resource.

Parameter
NameDescription
readSessionName string

A fully-qualified path representing ReadSession resource.

Returns
TypeDescription
string | number

{string} A string representing the session.

matchStreamFromStreamName(streamName)

matchStreamFromStreamName(streamName: string): string | number;

Parse the stream from Stream resource.

Parameter
NameDescription
streamName string

A fully-qualified path representing Stream resource.

Returns
TypeDescription
string | number

{string} A string representing the stream.

projectPath(project)

projectPath(project: string): string;

Return a fully-qualified project resource name string.

Parameter
NameDescription
project string
Returns
TypeDescription
string

{string} Resource name string.

readRows(request, options)

readRows(request?: protos.google.cloud.bigquery.storage.v1beta1.IReadRowsRequest, options?: CallOptions): gax.CancellableStream;

Reads rows from the table in the format prescribed by the read session. Each response contains one or more table rows, up to a maximum of 10 MiB per response; read requests which attempt to read individual rows larger than this will fail.

Each request also returns a set of stream statistics reflecting the estimated total number of rows in the read stream. This number is computed based on the total table size and the number of active streams in the read session, and may change as other streams continue to read data.

Parameters
NameDescription
request protos.google.cloud.bigquery.storage.v1beta1.IReadRowsRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
gax.CancellableStream

{Stream} An object stream which emits [ReadRowsResponse] on 'data' event. Please see the [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#server-streaming) for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Identifier of the position in the stream to start reading from.
   *  The offset requested must be less than the last row read from ReadRows.
   *  Requesting a larger offset is undefined.
   */
  // const readPosition = {}

  // Imports the Storage library
  const {BigQueryStorageClient} = require('@google-cloud/bigquery-storage').v1beta1;

  // Instantiates a client
  const storageClient = new BigQueryStorageClient();

  async function callReadRows() {
    // Construct request
    const request = {
      readPosition,
    };

    // Run request
    const stream = await storageClient.readRows(request);
    stream.on('data', (response) => { console.log(response) });
    stream.on('error', (err) => { throw(err) });
    stream.on('end', () => { /* API call completed */ });
  }

  callReadRows();

readSessionPath(project, location, session)

readSessionPath(project: string, location: string, session: string): string;

Return a fully-qualified readSession resource name string.

Parameters
NameDescription
project string
location string
session string
Returns
TypeDescription
string

{string} Resource name string.

splitReadStream(request, options)

splitReadStream(request?: protos.google.cloud.bigquery.storage.v1beta1.ISplitReadStreamRequest, options?: CallOptions): Promise<[
        protos.google.cloud.bigquery.storage.v1beta1.ISplitReadStreamResponse,
        (protos.google.cloud.bigquery.storage.v1beta1.ISplitReadStreamRequest | undefined),
        {} | undefined
    ]>;

Splits a given read stream into two Streams. These streams are referred to as the primary and the residual of the split. The original stream can still be read from in the same manner as before. Both of the returned streams can also be read from, and the total rows return by both child streams will be the same as the rows read from the original stream.

Moreover, the two child streams will be allocated back to back in the original Stream. Concretely, it is guaranteed that for streams Original, Primary, and Residual, that Original[0-j] = Primary[0-j] and Original[j-n] = Residual[0-m] once the streams have been read to completion.

This method is guaranteed to be idempotent.

Parameters
NameDescription
request protos.google.cloud.bigquery.storage.v1beta1.ISplitReadStreamRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[ protos.google.cloud.bigquery.storage.v1beta1.ISplitReadStreamResponse, (protos.google.cloud.bigquery.storage.v1beta1.ISplitReadStreamRequest | undefined), {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing [SplitReadStreamResponse]. Please see the [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Stream to split.
   */
  // const originalStream = {}
  /**
   *  A value in the range (0.0, 1.0) that specifies the fractional point at
   *  which the original stream should be split. The actual split point is
   *  evaluated on pre-filtered rows, so if a filter is provided, then there is
   *  no guarantee that the division of the rows between the new child streams
   *  will be proportional to this fractional value. Additionally, because the
   *  server-side unit for assigning data is collections of rows, this fraction
   *  will always map to to a data storage boundary on the server side.
   */
  // const fraction = 1234

  // Imports the Storage library
  const {BigQueryStorageClient} = require('@google-cloud/bigquery-storage').v1beta1;

  // Instantiates a client
  const storageClient = new BigQueryStorageClient();

  async function callSplitReadStream() {
    // Construct request
    const request = {
      originalStream,
    };

    // Run request
    const response = await storageClient.splitReadStream(request);
    console.log(response);
  }

  callSplitReadStream();

splitReadStream(request, options, callback)

splitReadStream(request: protos.google.cloud.bigquery.storage.v1beta1.ISplitReadStreamRequest, options: CallOptions, callback: Callback<protos.google.cloud.bigquery.storage.v1beta1.ISplitReadStreamResponse, protos.google.cloud.bigquery.storage.v1beta1.ISplitReadStreamRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.bigquery.storage.v1beta1.ISplitReadStreamRequest
options CallOptions
callback Callback<protos.google.cloud.bigquery.storage.v1beta1.ISplitReadStreamResponse, protos.google.cloud.bigquery.storage.v1beta1.ISplitReadStreamRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

splitReadStream(request, callback)

splitReadStream(request: protos.google.cloud.bigquery.storage.v1beta1.ISplitReadStreamRequest, callback: Callback<protos.google.cloud.bigquery.storage.v1beta1.ISplitReadStreamResponse, protos.google.cloud.bigquery.storage.v1beta1.ISplitReadStreamRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.bigquery.storage.v1beta1.ISplitReadStreamRequest
callback Callback<protos.google.cloud.bigquery.storage.v1beta1.ISplitReadStreamResponse, protos.google.cloud.bigquery.storage.v1beta1.ISplitReadStreamRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

streamPath(project, location, stream)

streamPath(project: string, location: string, stream: string): string;

Return a fully-qualified stream resource name string.

Parameters
NameDescription
project string
location string
stream string
Returns
TypeDescription
string

{string} Resource name string.