Class v1.BigQueryReadClient

BigQuery Read API.

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

Package

@google-cloud/bigquery-storage

Constructors

(constructor)(opts)

constructor(opts?: ClientOptions);

Construct an instance of BigQueryReadClient.

Parameter
NameDescription
opts ClientOptions

Properties

apiEndpoint

static get apiEndpoint(): string;

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

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.

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
TypeDescription
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
NameDescription
request protos.google.cloud.bigquery.storage.v1.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.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 [ReadSession]. Please see the [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) for more details and examples.

Example

  /**
   * 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. Error
   *  will be returned if the max count is greater than the current system
   *  max limit of 1,000.
   *  Streams must be read starting from offset 0.
   */
  // const maxStreamCount = 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
NameDescription
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>
Returns
TypeDescription
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
NameDescription
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>
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.

matchDatasetFromTableName(tableName)

matchDatasetFromTableName(tableName: string): string | number;

Parse the dataset from Table resource.

Parameter
NameDescription
tableName string

A fully-qualified path representing Table resource.

Returns
TypeDescription
string | number

{string} A string representing the dataset.

matchDatasetFromWriteStreamName(writeStreamName)

matchDatasetFromWriteStreamName(writeStreamName: string): string | number;

Parse the dataset from WriteStream resource.

Parameter
NameDescription
writeStreamName string

A fully-qualified path representing WriteStream resource.

Returns
TypeDescription
string | number

{string} A string representing the dataset.

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.

matchLocationFromReadStreamName(readStreamName)

matchLocationFromReadStreamName(readStreamName: string): string | number;

Parse the location from ReadStream resource.

Parameter
NameDescription
readStreamName string

A fully-qualified path representing ReadStream 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.

matchProjectFromReadStreamName(readStreamName)

matchProjectFromReadStreamName(readStreamName: string): string | number;

Parse the project from ReadStream resource.

Parameter
NameDescription
readStreamName string

A fully-qualified path representing ReadStream resource.

Returns
TypeDescription
string | number

{string} A string representing the project.

matchProjectFromTableName(tableName)

matchProjectFromTableName(tableName: string): string | number;

Parse the project from Table resource.

Parameter
NameDescription
tableName string

A fully-qualified path representing Table resource.

Returns
TypeDescription
string | number

{string} A string representing the project.

matchProjectFromWriteStreamName(writeStreamName)

matchProjectFromWriteStreamName(writeStreamName: string): string | number;

Parse the project from WriteStream resource.

Parameter
NameDescription
writeStreamName string

A fully-qualified path representing WriteStream 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.

matchSessionFromReadStreamName(readStreamName)

matchSessionFromReadStreamName(readStreamName: string): string | number;

Parse the session from ReadStream resource.

Parameter
NameDescription
readStreamName string

A fully-qualified path representing ReadStream resource.

Returns
TypeDescription
string | number

{string} A string representing the session.

matchStreamFromReadStreamName(readStreamName)

matchStreamFromReadStreamName(readStreamName: string): string | number;

Parse the stream from ReadStream resource.

Parameter
NameDescription
readStreamName string

A fully-qualified path representing ReadStream resource.

Returns
TypeDescription
string | number

{string} A string representing the stream.

matchStreamFromWriteStreamName(writeStreamName)

matchStreamFromWriteStreamName(writeStreamName: string): string | number;

Parse the stream from WriteStream resource.

Parameter
NameDescription
writeStreamName string

A fully-qualified path representing WriteStream resource.

Returns
TypeDescription
string | number

{string} A string representing the stream.

matchTableFromTableName(tableName)

matchTableFromTableName(tableName: string): string | number;

Parse the table from Table resource.

Parameter
NameDescription
tableName string

A fully-qualified path representing Table resource.

Returns
TypeDescription
string | number

{string} A string representing the table.

matchTableFromWriteStreamName(writeStreamName)

matchTableFromWriteStreamName(writeStreamName: string): string | number;

Parse the table from WriteStream resource.

Parameter
NameDescription
writeStreamName string

A fully-qualified path representing WriteStream resource.

Returns
TypeDescription
string | number

{string} A string representing the table.

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.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
NameDescription
request protos.google.cloud.bigquery.storage.v1.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

  /**
   * 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
NameDescription
project string
location string
session string
Returns
TypeDescription
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
NameDescription
project string
location string
session string
stream string
Returns
TypeDescription
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
NameDescription
request protos.google.cloud.bigquery.storage.v1.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.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](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) for more details and examples.

Example

  /**
   * 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
NameDescription
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>
Returns
TypeDescription
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
NameDescription
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>
Returns
TypeDescription
void

tablePath(project, dataset, table)

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

Return a fully-qualified table resource name string.

Parameters
NameDescription
project string
dataset string
table string
Returns
TypeDescription
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
NameDescription
project string
dataset string
table string
stream string
Returns
TypeDescription
string

{string} Resource name string.