Class BigQueryStorageClient (1.0.0)

BigQueryStorageClient(
    transport=None,
    channel=None,
    credentials=None,
    client_config=None,
    client_info=None,
    client_options=None,
)

Client for interacting with BigQuery Storage API.

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

Inheritance

builtins.object > google.cloud.bigquery_storage_v1beta1.gapic.big_query_storage_client.BigQueryStorageClient > google.cloud.bigquery_storage_v1beta1.client.BigQueryStorageClient > BigQueryStorageClient

Methods

BigQueryStorageClient

BigQueryStorageClient(
    transport=None,
    channel=None,
    credentials=None,
    client_config=None,
    client_info=None,
    client_options=None,
)

Constructor.

Parameters
NameDescription
channel grpc.Channel

DEPRECATED. A Channel instance through which to make calls. This argument is mutually exclusive with credentials; providing both will raise an exception.

credentials google.auth.credentials.Credentials

The authorization credentials to attach to requests. These credentials identify this application to the service. If none are specified, the client will attempt to ascertain the credentials from the environment. This argument is mutually exclusive with providing a transport instance to transport; doing so will raise an exception.

client_config dict

DEPRECATED. A dictionary of call options for each method. If not specified, the default configuration is used.

client_info google.api_core.gapic_v1.client_info.ClientInfo

The client info used to send a user-agent string along with API requests. If None, then default info will be used. Generally, you only need to set this if you're developing your own client library.

client_options Union[dict, google.api_core.client_options.ClientOptions]

Client options used to set user options on the client. API Endpoint should be set through client_options.

batch_create_read_session_streams

batch_create_read_session_streams(session, requested_streams, retry=<object object>, timeout=<object object>, metadata=None)

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.

.. rubric:: Example

from google.cloud import bigquery_storage_v1beta1

client = bigquery_storage_v1beta1.BigQueryStorageClient()

TODO: Initialize session:

session = {}

TODO: Initialize requested_streams:

requested_streams = 0

response = client.batch_create_read_session_streams(session, requested_streams)

Parameters
NameDescription
session Union[dict, ReadSession]

Required. Must be a non-expired session obtained from a call to CreateReadSession. Only the name field needs to be set. If a dict is provided, it must be of the same form as the protobuf message ReadSession

requested_streams int

Required. Number of new streams requested. Must be positive. Number of added streams may be less than this, see CreateReadSessionRequest for more information.

retry Optional[google.api_core.retry.Retry]

A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

timeout Optional[float]

The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

metadata Optional[Sequence[Tuple[str, str]]]

Additional metadata that is provided to the method.

Exceptions
TypeDescription
google.api_core.exceptions.GoogleAPICallErrorIf the request failed for any reason.
google.api_core.exceptions.RetryErrorIf the request failed due to a retryable error and retry attempts failed.
ValueErrorIf the parameters are invalid.

create_read_session

create_read_session(table_reference, parent, table_modifiers=None, requested_streams=None, read_options=None, format_=None, sharding_strategy=None, retry=<object object>, timeout=<object object>, metadata=None)

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.

.. rubric:: Example

from google.cloud import bigquery_storage_v1beta1

client = bigquery_storage_v1beta1.BigQueryStorageClient()

TODO: Initialize table_reference:

table_reference = {}

TODO: Initialize parent:

parent = ''

response = client.create_read_session(table_reference, parent)

Parameters
NameDescription
table_reference Union[dict, TableReference]

Required. Reference to the table to read. If a dict is provided, it must be of the same form as the protobuf message TableReference

parent str

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.

table_modifiers Union[dict, TableModifiers]

Any modifiers to the Table (e.g. snapshot timestamp). If a dict is provided, it must be of the same form as the protobuf message TableModifiers

requested_streams int

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.

read_options Union[dict, TableReadOptions]

Read options for this session (e.g. column selection, filters). If a dict is provided, it must be of the same form as the protobuf message TableReadOptions

format_ DataFormat

Data output format. Currently default to Avro.

sharding_strategy ShardingStrategy

The strategy to use for distributing data among multiple streams. Currently defaults to liquid sharding.

retry Optional[google.api_core.retry.Retry]

A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

timeout Optional[float]

The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

metadata Optional[Sequence[Tuple[str, str]]]

Additional metadata that is provided to the method.

Exceptions
TypeDescription
google.api_core.exceptions.GoogleAPICallErrorIf the request failed for any reason.
google.api_core.exceptions.RetryErrorIf the request failed due to a retryable error and retry attempts failed.
ValueErrorIf the parameters are invalid.

finalize_stream

finalize_stream(stream, retry=<object object>, timeout=<object object>, metadata=None)

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.

.. rubric:: Example

from google.cloud import bigquery_storage_v1beta1

client = bigquery_storage_v1beta1.BigQueryStorageClient()

TODO: Initialize stream:

stream = {}

client.finalize_stream(stream)

Parameters
NameDescription
stream Union[dict, Stream]

Stream to finalize. If a dict is provided, it must be of the same form as the protobuf message Stream

retry Optional[google.api_core.retry.Retry]

A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

timeout Optional[float]

The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

metadata Optional[Sequence[Tuple[str, str]]]

Additional metadata that is provided to the method.

Exceptions
TypeDescription
google.api_core.exceptions.GoogleAPICallErrorIf the request failed for any reason.
google.api_core.exceptions.RetryErrorIf the request failed due to a retryable error and retry attempts failed.
ValueErrorIf the parameters are invalid.

from_service_account_file

from_service_account_file(filename, *args, **kwargs)

Creates an instance of this client using the provided credentials file.

Parameter
NameDescription
filename str

The path to the service account private key json file.

Returns
TypeDescription
BigQueryStorageClientThe constructed client.

from_service_account_json

from_service_account_json(filename, *args, **kwargs)

Creates an instance of this client using the provided credentials file.

Parameter
NameDescription
filename str

The path to the service account private key json file.

Returns
TypeDescription
BigQueryStorageClientThe constructed client.

read_rows

read_rows(read_position, retry=<object object>, timeout=<object object>, metadata=None)

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.

.. rubric:: Example

from google.cloud import bigquery_storage_v1beta1

client = bigquery_storage_v1beta1.BigQueryStorageClient()

TODO: Initialize table_reference:

table_reference = { ... 'project_id': 'your-data-project-id', ... 'dataset_id': 'your_dataset_id', ... 'table_id': 'your_table_id', ... }

TODO: Initialize parent:

parent = 'projects/your-billing-project-id'

session = client.create_read_session(table_reference, parent) read_position = bigquery_storage_v1beta1.types.StreamPosition( ... stream=session.streams[0], # TODO: Read the other streams. ... )

for element in client.read_rows(read_position): ... # process element ... pass

Parameters
NameDescription
read_position Union[ dict, StreamPosition ]

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. If a dict is provided, it must be of the same form as the protobuf message StreamPosition

retry Optional[google.api_core.retry.Retry]

A retry object used to retry requests. If None is specified, requests will not be retried.

timeout Optional[float]

The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

metadata Optional[Sequence[Tuple[str, str]]]

Additional metadata that is provided to the method.

Exceptions
TypeDescription
google.api_core.exceptions.GoogleAPICallErrorIf the request failed for any reason.
google.api_core.exceptions.RetryErrorIf the request failed due to a retryable error and retry attempts failed.
ValueErrorIf the parameters are invalid.
Returns
TypeDescription
ReadRowsStreamAn iterable of ReadRowsResponse.

split_read_stream

split_read_stream(original_stream, fraction=None, retry=<object object>, timeout=<object object>, metadata=None)

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.

.. rubric:: Example

from google.cloud import bigquery_storage_v1beta1

client = bigquery_storage_v1beta1.BigQueryStorageClient()

TODO: Initialize original_stream:

original_stream = {}

response = client.split_read_stream(original_stream)

Parameters
NameDescription
original_stream Union[dict, Stream]

Stream to split. If a dict is provided, it must be of the same form as the protobuf message Stream

fraction float

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.

retry Optional[google.api_core.retry.Retry]

A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

timeout Optional[float]

The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

metadata Optional[Sequence[Tuple[str, str]]]

Additional metadata that is provided to the method.

Exceptions
TypeDescription
google.api_core.exceptions.GoogleAPICallErrorIf the request failed for any reason.
google.api_core.exceptions.RetryErrorIf the request failed due to a retryable error and retry attempts failed.
ValueErrorIf the parameters are invalid.