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.
Methods
BigQueryStorageClient
BigQueryStorageClient(
transport=None,
channel=None,
credentials=None,
client_config=None,
client_info=None,
client_options=None,
)
Constructor.
Name | Description |
channel |
grpc.Channel
DEPRECATED. A |
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 |
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 |
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=<_MethodDefault._DEFAULT_VALUE: <object object>>, timeout=<_MethodDefault._DEFAULT_VALUE: <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)
Name | Description |
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 |
timeout |
Optional[float]
The amount of time, in seconds, to wait for the request to complete. Note that if |
metadata |
Optional[Sequence[Tuple[str, str]]]
Additional metadata that is provided to the method. |
Type | Description |
google.api_core.exceptions.GoogleAPICallError | If the request failed for any reason. |
google.api_core.exceptions.RetryError | If the request failed due to a retryable error and retry attempts failed. |
ValueError | If 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=<_MethodDefault._DEFAULT_VALUE: <object object>>, timeout=<_MethodDefault._DEFAULT_VALUE: <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 = {} parent = client.project_path('[PROJECT]')
response = client.create_read_session(table_reference, parent)
Name | Description |
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
A value in the range [0.0, 1.0] that represents the fraction of rows assigned to this stream that have been processed by the server. In the presence of read filters, the server may process more rows than it returns, so this value reflects progress through the pre-filtering rows. This value is only populated for sessions created through the BALANCED sharding strategy. |
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 |
timeout |
Optional[float]
The amount of time, in seconds, to wait for the request to complete. Note that if |
metadata |
Optional[Sequence[Tuple[str, str]]]
Additional metadata that is provided to the method. |
Type | Description |
google.api_core.exceptions.GoogleAPICallError | If the request failed for any reason. |
google.api_core.exceptions.RetryError | If the request failed due to a retryable error and retry attempts failed. |
ValueError | If the parameters are invalid. |
finalize_stream
finalize_stream(stream, retry=<_MethodDefault._DEFAULT_VALUE: <object object>>, timeout=<_MethodDefault._DEFAULT_VALUE: <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)
Name | Description |
stream |
Union[dict, Stream]
Required. 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 |
timeout |
Optional[float]
The amount of time, in seconds, to wait for the request to complete. Note that if |
metadata |
Optional[Sequence[Tuple[str, str]]]
Additional metadata that is provided to the method. |
Type | Description |
google.api_core.exceptions.GoogleAPICallError | If the request failed for any reason. |
google.api_core.exceptions.RetryError | If the request failed due to a retryable error and retry attempts failed. |
ValueError | If 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.
Name | Description |
filename |
str
The path to the service account private key json file. |
Type | Description |
BigQueryStorageClient | The constructed client. |
from_service_account_json
from_service_account_json(filename, *args, **kwargs)
Creates an instance of this client using the provided credentials file.
Name | Description |
filename |
str
The path to the service account private key json file. |
Type | Description |
BigQueryStorageClient | The constructed client. |
project_path
project_path(project)
Return a fully-qualified project string.
read_rows
read_rows(read_position, retry=<_MethodDefault._DEFAULT_VALUE: <object object>>, timeout=<_MethodDefault._DEFAULT_VALUE: <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
Name | Description |
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 |
timeout |
Optional[float]
The amount of time, in seconds, to wait for the request to complete. Note that if |
metadata |
Optional[Sequence[Tuple[str, str]]]
Additional metadata that is provided to the method. |
Type | Description |
google.api_core.exceptions.GoogleAPICallError | If the request failed for any reason. |
google.api_core.exceptions.RetryError | If the request failed due to a retryable error and retry attempts failed. |
ValueError | If the parameters are invalid. |
Type | Description |
ReadRowsStream | An iterable of ReadRowsResponse. |
read_session_path
read_session_path(project, location, session)
Return a fully-qualified read_session string.
split_read_stream
split_read_stream(original_stream, fraction=None, retry=<_MethodDefault._DEFAULT_VALUE: <object object>>, timeout=<_MethodDefault._DEFAULT_VALUE: <object object>>, metadata=None)
An annotation that describes a resource definition, see
ResourceDescriptor
.
.. 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)
Name | Description |
original_stream |
Union[dict, Stream]
Required. 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 |
timeout |
Optional[float]
The amount of time, in seconds, to wait for the request to complete. Note that if |
metadata |
Optional[Sequence[Tuple[str, str]]]
Additional metadata that is provided to the method. |
Type | Description |
google.api_core.exceptions.GoogleAPICallError | If the request failed for any reason. |
google.api_core.exceptions.RetryError | If the request failed due to a retryable error and retry attempts failed. |
ValueError | If the parameters are invalid. |
stream_path
stream_path(project, location, stream)
Return a fully-qualified stream string.