Class v1.BigQueryReadClient (4.7.0)

BigQuery Read API.

The Read API can be used to read data from BigQuery. v1

Package

@google-cloud/bigquery-storage

Constructors

(constructor)(opts, gaxInstance)

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

Construct an instance of BigQueryReadClient.

Parameters
Name Description
opts ClientOptions
gaxInstance typeof gax | typeof 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 BigQueryReadClient({fallback: true}, gax); ```

Properties

apiEndpoint

get apiEndpoint(): string;

The DNS address for this API service.

apiEndpoint

static get apiEndpoint(): string;

The DNS address for this API service - same as servicePath.

auth

auth: gax.GoogleAuth;

bigQueryReadStub

bigQueryReadStub?: 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.

universeDomain

get universeDomain(): string;

warn

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

Methods

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
Type Description
Promise<void>

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

createReadSession(request, options)

createReadSession(request?: protos.google.cloud.bigquery.storage.v1.ICreateReadSessionRequest, options?: CallOptions): Promise<[
        protos.google.cloud.bigquery.storage.v1.IReadSession,
        (protos.google.cloud.bigquery.storage.v1.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.

Data is assigned to each stream such that roughly the same number of rows can be read from each stream. Because the server-side unit for assigning data is collections of rows, the API does not guarantee that each stream will return the same number or rows. Additionally, the limits are enforced based on the number of pre-filtered rows, so some filters can lead to lopsided assignments.

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

Parameters
Name Description
request ICreateReadSessionRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

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

{Promise} - The promise which resolves to an array. The first element of the array is an object representing . Please see the documentation 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. The request project that owns the session, in the form of
   *  `projects/{project_id}`.
   */
  // const parent = 'abc123'
  /**
   *  Required. Session to be created.
   */
  // const readSession = {}
  /**
   *  Max initial number of streams. If unset or zero, the server 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.
   *  There is a default system max limit of 1,000.
   *  This must be greater than or equal to preferred_min_stream_count.
   *  Typically, clients should either leave this unset to let the system to
   *  determine an upper bound OR set this a size for the maximum "units of work"
   *  it can gracefully handle.
   */
  // const maxStreamCount = 1234
  /**
   *  The minimum preferred stream count. This parameter can be used to inform
   *  the service that there is a desired lower bound on the number of streams.
   *  This is typically a target parallelism of the client (e.g. a Spark
   *  cluster with N-workers would set this to a low multiple of N to ensure
   *  good cluster utilization).
   *  The system will make a best effort to provide at least this number of
   *  streams, but in some cases might provide less.
   */
  // const preferredMinStreamCount = 1234

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

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

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

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

  callCreateReadSession();

createReadSession(request, options, callback)

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

createReadSession(request, callback)

createReadSession(request: protos.google.cloud.bigquery.storage.v1.ICreateReadSessionRequest, callback: Callback<protos.google.cloud.bigquery.storage.v1.IReadSession, protos.google.cloud.bigquery.storage.v1.ICreateReadSessionRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request ICreateReadSessionRequest
callback Callback<protos.google.cloud.bigquery.storage.v1.IReadSession, protos.google.cloud.bigquery.storage.v1.ICreateReadSessionRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

getProjectId()

getProjectId(): Promise<string>;
Returns
Type Description
Promise<string>

getProjectId(callback)

getProjectId(callback: Callback<string, undefined, undefined>): void;
Parameter
Name Description
callback Callback<string, undefined, undefined>
Returns
Type Description
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
Type Description
Promise<{ [name: string]: Function; }>

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

matchDatasetFromTableName(tableName)

matchDatasetFromTableName(tableName: string): string | number;

Parse the dataset from Table resource.

Parameter
Name Description
tableName string

A fully-qualified path representing Table resource.

Returns
Type Description
string | number

{string} A string representing the dataset.

matchDatasetFromWriteStreamName(writeStreamName)

matchDatasetFromWriteStreamName(writeStreamName: string): string | number;

Parse the dataset from WriteStream resource.

Parameter
Name Description
writeStreamName string

A fully-qualified path representing WriteStream resource.

Returns
Type Description
string | number

{string} A string representing the dataset.

matchLocationFromReadSessionName(readSessionName)

matchLocationFromReadSessionName(readSessionName: string): string | number;

Parse the location from ReadSession resource.

Parameter
Name Description
readSessionName string

A fully-qualified path representing ReadSession resource.

Returns
Type Description
string | number

{string} A string representing the location.

matchLocationFromReadStreamName(readStreamName)

matchLocationFromReadStreamName(readStreamName: string): string | number;

Parse the location from ReadStream resource.

Parameter
Name Description
readStreamName string

A fully-qualified path representing ReadStream resource.

Returns
Type Description
string | number

{string} A string representing the location.

matchProjectFromProjectName(projectName)

matchProjectFromProjectName(projectName: string): string | number;

Parse the project from Project resource.

Parameter
Name Description
projectName string

A fully-qualified path representing Project resource.

Returns
Type Description
string | number

{string} A string representing the project.

matchProjectFromReadSessionName(readSessionName)

matchProjectFromReadSessionName(readSessionName: string): string | number;

Parse the project from ReadSession resource.

Parameter
Name Description
readSessionName string

A fully-qualified path representing ReadSession resource.

Returns
Type Description
string | number

{string} A string representing the project.

matchProjectFromReadStreamName(readStreamName)

matchProjectFromReadStreamName(readStreamName: string): string | number;

Parse the project from ReadStream resource.

Parameter
Name Description
readStreamName string

A fully-qualified path representing ReadStream resource.

Returns
Type Description
string | number

{string} A string representing the project.

matchProjectFromTableName(tableName)

matchProjectFromTableName(tableName: string): string | number;

Parse the project from Table resource.

Parameter
Name Description
tableName string

A fully-qualified path representing Table resource.

Returns
Type Description
string | number

{string} A string representing the project.

matchProjectFromWriteStreamName(writeStreamName)

matchProjectFromWriteStreamName(writeStreamName: string): string | number;

Parse the project from WriteStream resource.

Parameter
Name Description
writeStreamName string

A fully-qualified path representing WriteStream resource.

Returns
Type Description
string | number

{string} A string representing the project.

matchSessionFromReadSessionName(readSessionName)

matchSessionFromReadSessionName(readSessionName: string): string | number;

Parse the session from ReadSession resource.

Parameter
Name Description
readSessionName string

A fully-qualified path representing ReadSession resource.

Returns
Type Description
string | number

{string} A string representing the session.

matchSessionFromReadStreamName(readStreamName)

matchSessionFromReadStreamName(readStreamName: string): string | number;

Parse the session from ReadStream resource.

Parameter
Name Description
readStreamName string

A fully-qualified path representing ReadStream resource.

Returns
Type Description
string | number

{string} A string representing the session.

matchStreamFromReadStreamName(readStreamName)

matchStreamFromReadStreamName(readStreamName: string): string | number;

Parse the stream from ReadStream resource.

Parameter
Name Description
readStreamName string

A fully-qualified path representing ReadStream resource.

Returns
Type Description
string | number

{string} A string representing the stream.

matchStreamFromWriteStreamName(writeStreamName)

matchStreamFromWriteStreamName(writeStreamName: string): string | number;

Parse the stream from WriteStream resource.

Parameter
Name Description
writeStreamName string

A fully-qualified path representing WriteStream resource.

Returns
Type Description
string | number

{string} A string representing the stream.

matchTableFromTableName(tableName)

matchTableFromTableName(tableName: string): string | number;

Parse the table from Table resource.

Parameter
Name Description
tableName string

A fully-qualified path representing Table resource.

Returns
Type Description
string | number

{string} A string representing the table.

matchTableFromWriteStreamName(writeStreamName)

matchTableFromWriteStreamName(writeStreamName: string): string | number;

Parse the table from WriteStream resource.

Parameter
Name Description
writeStreamName string

A fully-qualified path representing WriteStream resource.

Returns
Type Description
string | number

{string} A string representing the table.

projectPath(project)

projectPath(project: string): string;

Return a fully-qualified project resource name string.

Parameter
Name Description
project string
Returns
Type Description
string

{string} Resource name string.

readRows(request, options)

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

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

Each request also returns a set of stream statistics reflecting the current state of the stream.

Parameters
Name Description
request IReadRowsRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
gax.CancellableStream

{Stream} An object stream which emits ReadRowsResponse on 'data' event. Please see the documentation 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 read rows from.
   */
  // const readStream = 'abc123'
  /**
   *  The offset requested must be less than the last row read from Read.
   *  Requesting a larger offset is undefined. If not specified, start reading
   *  from offset zero.
   */
  // const offset = 1234

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

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

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

    // 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
Name Description
project string
location string
session string
Returns
Type Description
string

{string} Resource name string.

readStreamPath(project, location, session, stream)

readStreamPath(project: string, location: string, session: string, stream: string): string;

Return a fully-qualified readStream resource name string.

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

{string} Resource name string.

splitReadStream(request, options)

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

Splits a given ReadStream into two ReadStream objects. These ReadStream objects are referred to as the primary and the residual streams of the split. The original ReadStream can still be read from in the same manner as before. Both of the returned ReadStream objects can also be read from, and the rows returned 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 ReadStream. 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.

Parameters
Name Description
request ISplitReadStreamRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
Promise<[ protos.google.cloud.bigquery.storage.v1.ISplitReadStreamResponse, (protos.google.cloud.bigquery.storage.v1.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 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. Name of the stream to split.
   */
  // const name = 'abc123'
  /**
   *  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 a data storage boundary on the server side.
   */
  // const fraction = 1234

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

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

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

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

  callSplitReadStream();

splitReadStream(request, options, callback)

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

splitReadStream(request, callback)

splitReadStream(request: protos.google.cloud.bigquery.storage.v1.ISplitReadStreamRequest, callback: Callback<protos.google.cloud.bigquery.storage.v1.ISplitReadStreamResponse, protos.google.cloud.bigquery.storage.v1.ISplitReadStreamRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request ISplitReadStreamRequest
callback Callback<protos.google.cloud.bigquery.storage.v1.ISplitReadStreamResponse, protos.google.cloud.bigquery.storage.v1.ISplitReadStreamRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

tablePath(project, dataset, table)

tablePath(project: string, dataset: string, table: string): string;

Return a fully-qualified table resource name string.

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

{string} Resource name string.

writeStreamPath(project, dataset, table, stream)

writeStreamPath(project: string, dataset: string, table: string, stream: string): string;

Return a fully-qualified writeStream resource name string.

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

{string} Resource name string.