google-cloud-spanner 3.55.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- google/cloud/spanner.py +47 -0
- google/cloud/spanner_admin_database_v1/__init__.py +146 -0
- google/cloud/spanner_admin_database_v1/gapic_metadata.json +418 -0
- google/cloud/spanner_admin_database_v1/gapic_version.py +16 -0
- google/cloud/spanner_admin_database_v1/py.typed +2 -0
- google/cloud/spanner_admin_database_v1/services/__init__.py +15 -0
- google/cloud/spanner_admin_database_v1/services/database_admin/__init__.py +22 -0
- google/cloud/spanner_admin_database_v1/services/database_admin/async_client.py +4097 -0
- google/cloud/spanner_admin_database_v1/services/database_admin/client.py +4602 -0
- google/cloud/spanner_admin_database_v1/services/database_admin/pagers.py +989 -0
- google/cloud/spanner_admin_database_v1/services/database_admin/transports/__init__.py +38 -0
- google/cloud/spanner_admin_database_v1/services/database_admin/transports/base.py +820 -0
- google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc.py +1303 -0
- google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc_asyncio.py +1688 -0
- google/cloud/spanner_admin_database_v1/services/database_admin/transports/rest.py +6512 -0
- google/cloud/spanner_admin_database_v1/services/database_admin/transports/rest_base.py +1650 -0
- google/cloud/spanner_admin_database_v1/types/__init__.py +144 -0
- google/cloud/spanner_admin_database_v1/types/backup.py +1106 -0
- google/cloud/spanner_admin_database_v1/types/backup_schedule.py +369 -0
- google/cloud/spanner_admin_database_v1/types/common.py +180 -0
- google/cloud/spanner_admin_database_v1/types/spanner_database_admin.py +1303 -0
- google/cloud/spanner_admin_instance_v1/__init__.py +110 -0
- google/cloud/spanner_admin_instance_v1/gapic_metadata.json +343 -0
- google/cloud/spanner_admin_instance_v1/gapic_version.py +16 -0
- google/cloud/spanner_admin_instance_v1/py.typed +2 -0
- google/cloud/spanner_admin_instance_v1/services/__init__.py +15 -0
- google/cloud/spanner_admin_instance_v1/services/instance_admin/__init__.py +22 -0
- google/cloud/spanner_admin_instance_v1/services/instance_admin/async_client.py +3466 -0
- google/cloud/spanner_admin_instance_v1/services/instance_admin/client.py +3881 -0
- google/cloud/spanner_admin_instance_v1/services/instance_admin/pagers.py +856 -0
- google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/__init__.py +38 -0
- google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/base.py +545 -0
- google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc.py +1347 -0
- google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc_asyncio.py +1539 -0
- google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/rest.py +4834 -0
- google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/rest_base.py +1198 -0
- google/cloud/spanner_admin_instance_v1/types/__init__.py +104 -0
- google/cloud/spanner_admin_instance_v1/types/common.py +99 -0
- google/cloud/spanner_admin_instance_v1/types/spanner_instance_admin.py +2375 -0
- google/cloud/spanner_dbapi/__init__.py +93 -0
- google/cloud/spanner_dbapi/_helpers.py +113 -0
- google/cloud/spanner_dbapi/batch_dml_executor.py +135 -0
- google/cloud/spanner_dbapi/checksum.py +80 -0
- google/cloud/spanner_dbapi/client_side_statement_executor.py +140 -0
- google/cloud/spanner_dbapi/client_side_statement_parser.py +106 -0
- google/cloud/spanner_dbapi/connection.py +818 -0
- google/cloud/spanner_dbapi/cursor.py +609 -0
- google/cloud/spanner_dbapi/exceptions.py +172 -0
- google/cloud/spanner_dbapi/parse_utils.py +392 -0
- google/cloud/spanner_dbapi/parsed_statement.py +63 -0
- google/cloud/spanner_dbapi/parser.py +258 -0
- google/cloud/spanner_dbapi/partition_helper.py +41 -0
- google/cloud/spanner_dbapi/transaction_helper.py +294 -0
- google/cloud/spanner_dbapi/types.py +106 -0
- google/cloud/spanner_dbapi/utils.py +147 -0
- google/cloud/spanner_dbapi/version.py +20 -0
- google/cloud/spanner_v1/__init__.py +154 -0
- google/cloud/spanner_v1/_helpers.py +751 -0
- google/cloud/spanner_v1/_opentelemetry_tracing.py +165 -0
- google/cloud/spanner_v1/backup.py +397 -0
- google/cloud/spanner_v1/batch.py +433 -0
- google/cloud/spanner_v1/client.py +538 -0
- google/cloud/spanner_v1/data_types.py +350 -0
- google/cloud/spanner_v1/database.py +1968 -0
- google/cloud/spanner_v1/database_sessions_manager.py +249 -0
- google/cloud/spanner_v1/gapic_metadata.json +268 -0
- google/cloud/spanner_v1/gapic_version.py +16 -0
- google/cloud/spanner_v1/instance.py +735 -0
- google/cloud/spanner_v1/keyset.py +193 -0
- google/cloud/spanner_v1/merged_result_set.py +146 -0
- google/cloud/spanner_v1/metrics/constants.py +71 -0
- google/cloud/spanner_v1/metrics/metrics_capture.py +75 -0
- google/cloud/spanner_v1/metrics/metrics_exporter.py +384 -0
- google/cloud/spanner_v1/metrics/metrics_interceptor.py +156 -0
- google/cloud/spanner_v1/metrics/metrics_tracer.py +588 -0
- google/cloud/spanner_v1/metrics/metrics_tracer_factory.py +328 -0
- google/cloud/spanner_v1/metrics/spanner_metrics_tracer_factory.py +172 -0
- google/cloud/spanner_v1/param_types.py +110 -0
- google/cloud/spanner_v1/pool.py +813 -0
- google/cloud/spanner_v1/py.typed +2 -0
- google/cloud/spanner_v1/request_id_header.py +64 -0
- google/cloud/spanner_v1/services/__init__.py +15 -0
- google/cloud/spanner_v1/services/spanner/__init__.py +22 -0
- google/cloud/spanner_v1/services/spanner/async_client.py +2205 -0
- google/cloud/spanner_v1/services/spanner/client.py +2624 -0
- google/cloud/spanner_v1/services/spanner/pagers.py +196 -0
- google/cloud/spanner_v1/services/spanner/transports/__init__.py +38 -0
- google/cloud/spanner_v1/services/spanner/transports/base.py +520 -0
- google/cloud/spanner_v1/services/spanner/transports/grpc.py +911 -0
- google/cloud/spanner_v1/services/spanner/transports/grpc_asyncio.py +1144 -0
- google/cloud/spanner_v1/services/spanner/transports/rest.py +3468 -0
- google/cloud/spanner_v1/services/spanner/transports/rest_base.py +981 -0
- google/cloud/spanner_v1/session.py +631 -0
- google/cloud/spanner_v1/session_options.py +133 -0
- google/cloud/spanner_v1/snapshot.py +1057 -0
- google/cloud/spanner_v1/streamed.py +402 -0
- google/cloud/spanner_v1/table.py +181 -0
- google/cloud/spanner_v1/testing/__init__.py +0 -0
- google/cloud/spanner_v1/testing/database_test.py +121 -0
- google/cloud/spanner_v1/testing/interceptors.py +118 -0
- google/cloud/spanner_v1/testing/mock_database_admin.py +38 -0
- google/cloud/spanner_v1/testing/mock_spanner.py +261 -0
- google/cloud/spanner_v1/testing/spanner_database_admin_pb2_grpc.py +1267 -0
- google/cloud/spanner_v1/testing/spanner_pb2_grpc.py +882 -0
- google/cloud/spanner_v1/transaction.py +747 -0
- google/cloud/spanner_v1/types/__init__.py +118 -0
- google/cloud/spanner_v1/types/commit_response.py +94 -0
- google/cloud/spanner_v1/types/keys.py +248 -0
- google/cloud/spanner_v1/types/mutation.py +201 -0
- google/cloud/spanner_v1/types/query_plan.py +220 -0
- google/cloud/spanner_v1/types/result_set.py +379 -0
- google/cloud/spanner_v1/types/spanner.py +1815 -0
- google/cloud/spanner_v1/types/transaction.py +818 -0
- google/cloud/spanner_v1/types/type.py +288 -0
- google_cloud_spanner-3.55.0.dist-info/LICENSE +202 -0
- google_cloud_spanner-3.55.0.dist-info/METADATA +318 -0
- google_cloud_spanner-3.55.0.dist-info/RECORD +119 -0
- google_cloud_spanner-3.55.0.dist-info/WHEEL +5 -0
- google_cloud_spanner-3.55.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,2205 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Copyright 2025 Google LLC
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
#
|
|
16
|
+
import logging as std_logging
|
|
17
|
+
from collections import OrderedDict
|
|
18
|
+
import re
|
|
19
|
+
from typing import (
|
|
20
|
+
Dict,
|
|
21
|
+
Callable,
|
|
22
|
+
Mapping,
|
|
23
|
+
MutableMapping,
|
|
24
|
+
MutableSequence,
|
|
25
|
+
Optional,
|
|
26
|
+
AsyncIterable,
|
|
27
|
+
Awaitable,
|
|
28
|
+
Sequence,
|
|
29
|
+
Tuple,
|
|
30
|
+
Type,
|
|
31
|
+
Union,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
from google.cloud.spanner_v1 import gapic_version as package_version
|
|
35
|
+
|
|
36
|
+
from google.api_core.client_options import ClientOptions
|
|
37
|
+
from google.api_core import exceptions as core_exceptions
|
|
38
|
+
from google.api_core import gapic_v1
|
|
39
|
+
from google.api_core import retry_async as retries
|
|
40
|
+
from google.auth import credentials as ga_credentials # type: ignore
|
|
41
|
+
from google.oauth2 import service_account # type: ignore
|
|
42
|
+
import google.protobuf
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
try:
|
|
46
|
+
OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None]
|
|
47
|
+
except AttributeError: # pragma: NO COVER
|
|
48
|
+
OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore
|
|
49
|
+
|
|
50
|
+
from google.cloud.spanner_v1.services.spanner import pagers
|
|
51
|
+
from google.cloud.spanner_v1.types import commit_response
|
|
52
|
+
from google.cloud.spanner_v1.types import mutation
|
|
53
|
+
from google.cloud.spanner_v1.types import result_set
|
|
54
|
+
from google.cloud.spanner_v1.types import spanner
|
|
55
|
+
from google.cloud.spanner_v1.types import transaction
|
|
56
|
+
from google.protobuf import struct_pb2 # type: ignore
|
|
57
|
+
from google.protobuf import timestamp_pb2 # type: ignore
|
|
58
|
+
from google.rpc import status_pb2 # type: ignore
|
|
59
|
+
from .transports.base import SpannerTransport, DEFAULT_CLIENT_INFO
|
|
60
|
+
from .transports.grpc_asyncio import SpannerGrpcAsyncIOTransport
|
|
61
|
+
from .client import SpannerClient
|
|
62
|
+
|
|
63
|
+
try:
|
|
64
|
+
from google.api_core import client_logging # type: ignore
|
|
65
|
+
|
|
66
|
+
CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
|
|
67
|
+
except ImportError: # pragma: NO COVER
|
|
68
|
+
CLIENT_LOGGING_SUPPORTED = False
|
|
69
|
+
|
|
70
|
+
_LOGGER = std_logging.getLogger(__name__)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class SpannerAsyncClient:
|
|
74
|
+
"""Cloud Spanner API
|
|
75
|
+
|
|
76
|
+
The Cloud Spanner API can be used to manage sessions and execute
|
|
77
|
+
transactions on data stored in Cloud Spanner databases.
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
_client: SpannerClient
|
|
81
|
+
|
|
82
|
+
# Copy defaults from the synchronous client for use here.
|
|
83
|
+
# Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead.
|
|
84
|
+
DEFAULT_ENDPOINT = SpannerClient.DEFAULT_ENDPOINT
|
|
85
|
+
DEFAULT_MTLS_ENDPOINT = SpannerClient.DEFAULT_MTLS_ENDPOINT
|
|
86
|
+
_DEFAULT_ENDPOINT_TEMPLATE = SpannerClient._DEFAULT_ENDPOINT_TEMPLATE
|
|
87
|
+
_DEFAULT_UNIVERSE = SpannerClient._DEFAULT_UNIVERSE
|
|
88
|
+
|
|
89
|
+
database_path = staticmethod(SpannerClient.database_path)
|
|
90
|
+
parse_database_path = staticmethod(SpannerClient.parse_database_path)
|
|
91
|
+
session_path = staticmethod(SpannerClient.session_path)
|
|
92
|
+
parse_session_path = staticmethod(SpannerClient.parse_session_path)
|
|
93
|
+
common_billing_account_path = staticmethod(
|
|
94
|
+
SpannerClient.common_billing_account_path
|
|
95
|
+
)
|
|
96
|
+
parse_common_billing_account_path = staticmethod(
|
|
97
|
+
SpannerClient.parse_common_billing_account_path
|
|
98
|
+
)
|
|
99
|
+
common_folder_path = staticmethod(SpannerClient.common_folder_path)
|
|
100
|
+
parse_common_folder_path = staticmethod(SpannerClient.parse_common_folder_path)
|
|
101
|
+
common_organization_path = staticmethod(SpannerClient.common_organization_path)
|
|
102
|
+
parse_common_organization_path = staticmethod(
|
|
103
|
+
SpannerClient.parse_common_organization_path
|
|
104
|
+
)
|
|
105
|
+
common_project_path = staticmethod(SpannerClient.common_project_path)
|
|
106
|
+
parse_common_project_path = staticmethod(SpannerClient.parse_common_project_path)
|
|
107
|
+
common_location_path = staticmethod(SpannerClient.common_location_path)
|
|
108
|
+
parse_common_location_path = staticmethod(SpannerClient.parse_common_location_path)
|
|
109
|
+
|
|
110
|
+
@classmethod
|
|
111
|
+
def from_service_account_info(cls, info: dict, *args, **kwargs):
|
|
112
|
+
"""Creates an instance of this client using the provided credentials
|
|
113
|
+
info.
|
|
114
|
+
|
|
115
|
+
Args:
|
|
116
|
+
info (dict): The service account private key info.
|
|
117
|
+
args: Additional arguments to pass to the constructor.
|
|
118
|
+
kwargs: Additional arguments to pass to the constructor.
|
|
119
|
+
|
|
120
|
+
Returns:
|
|
121
|
+
SpannerAsyncClient: The constructed client.
|
|
122
|
+
"""
|
|
123
|
+
return SpannerClient.from_service_account_info.__func__(SpannerAsyncClient, info, *args, **kwargs) # type: ignore
|
|
124
|
+
|
|
125
|
+
@classmethod
|
|
126
|
+
def from_service_account_file(cls, filename: str, *args, **kwargs):
|
|
127
|
+
"""Creates an instance of this client using the provided credentials
|
|
128
|
+
file.
|
|
129
|
+
|
|
130
|
+
Args:
|
|
131
|
+
filename (str): The path to the service account private key json
|
|
132
|
+
file.
|
|
133
|
+
args: Additional arguments to pass to the constructor.
|
|
134
|
+
kwargs: Additional arguments to pass to the constructor.
|
|
135
|
+
|
|
136
|
+
Returns:
|
|
137
|
+
SpannerAsyncClient: The constructed client.
|
|
138
|
+
"""
|
|
139
|
+
return SpannerClient.from_service_account_file.__func__(SpannerAsyncClient, filename, *args, **kwargs) # type: ignore
|
|
140
|
+
|
|
141
|
+
from_service_account_json = from_service_account_file
|
|
142
|
+
|
|
143
|
+
@classmethod
|
|
144
|
+
def get_mtls_endpoint_and_cert_source(
|
|
145
|
+
cls, client_options: Optional[ClientOptions] = None
|
|
146
|
+
):
|
|
147
|
+
"""Return the API endpoint and client cert source for mutual TLS.
|
|
148
|
+
|
|
149
|
+
The client cert source is determined in the following order:
|
|
150
|
+
(1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the
|
|
151
|
+
client cert source is None.
|
|
152
|
+
(2) if `client_options.client_cert_source` is provided, use the provided one; if the
|
|
153
|
+
default client cert source exists, use the default one; otherwise the client cert
|
|
154
|
+
source is None.
|
|
155
|
+
|
|
156
|
+
The API endpoint is determined in the following order:
|
|
157
|
+
(1) if `client_options.api_endpoint` if provided, use the provided one.
|
|
158
|
+
(2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the
|
|
159
|
+
default mTLS endpoint; if the environment variable is "never", use the default API
|
|
160
|
+
endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise
|
|
161
|
+
use the default API endpoint.
|
|
162
|
+
|
|
163
|
+
More details can be found at https://google.aip.dev/auth/4114.
|
|
164
|
+
|
|
165
|
+
Args:
|
|
166
|
+
client_options (google.api_core.client_options.ClientOptions): Custom options for the
|
|
167
|
+
client. Only the `api_endpoint` and `client_cert_source` properties may be used
|
|
168
|
+
in this method.
|
|
169
|
+
|
|
170
|
+
Returns:
|
|
171
|
+
Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the
|
|
172
|
+
client cert source to use.
|
|
173
|
+
|
|
174
|
+
Raises:
|
|
175
|
+
google.auth.exceptions.MutualTLSChannelError: If any errors happen.
|
|
176
|
+
"""
|
|
177
|
+
return SpannerClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore
|
|
178
|
+
|
|
179
|
+
@property
|
|
180
|
+
def transport(self) -> SpannerTransport:
|
|
181
|
+
"""Returns the transport used by the client instance.
|
|
182
|
+
|
|
183
|
+
Returns:
|
|
184
|
+
SpannerTransport: The transport used by the client instance.
|
|
185
|
+
"""
|
|
186
|
+
return self._client.transport
|
|
187
|
+
|
|
188
|
+
@property
|
|
189
|
+
def api_endpoint(self):
|
|
190
|
+
"""Return the API endpoint used by the client instance.
|
|
191
|
+
|
|
192
|
+
Returns:
|
|
193
|
+
str: The API endpoint used by the client instance.
|
|
194
|
+
"""
|
|
195
|
+
return self._client._api_endpoint
|
|
196
|
+
|
|
197
|
+
@property
|
|
198
|
+
def universe_domain(self) -> str:
|
|
199
|
+
"""Return the universe domain used by the client instance.
|
|
200
|
+
|
|
201
|
+
Returns:
|
|
202
|
+
str: The universe domain used
|
|
203
|
+
by the client instance.
|
|
204
|
+
"""
|
|
205
|
+
return self._client._universe_domain
|
|
206
|
+
|
|
207
|
+
get_transport_class = SpannerClient.get_transport_class
|
|
208
|
+
|
|
209
|
+
def __init__(
|
|
210
|
+
self,
|
|
211
|
+
*,
|
|
212
|
+
credentials: Optional[ga_credentials.Credentials] = None,
|
|
213
|
+
transport: Optional[
|
|
214
|
+
Union[str, SpannerTransport, Callable[..., SpannerTransport]]
|
|
215
|
+
] = "grpc_asyncio",
|
|
216
|
+
client_options: Optional[ClientOptions] = None,
|
|
217
|
+
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
|
|
218
|
+
) -> None:
|
|
219
|
+
"""Instantiates the spanner async client.
|
|
220
|
+
|
|
221
|
+
Args:
|
|
222
|
+
credentials (Optional[google.auth.credentials.Credentials]): The
|
|
223
|
+
authorization credentials to attach to requests. These
|
|
224
|
+
credentials identify the application to the service; if none
|
|
225
|
+
are specified, the client will attempt to ascertain the
|
|
226
|
+
credentials from the environment.
|
|
227
|
+
transport (Optional[Union[str,SpannerTransport,Callable[..., SpannerTransport]]]):
|
|
228
|
+
The transport to use, or a Callable that constructs and returns a new transport to use.
|
|
229
|
+
If a Callable is given, it will be called with the same set of initialization
|
|
230
|
+
arguments as used in the SpannerTransport constructor.
|
|
231
|
+
If set to None, a transport is chosen automatically.
|
|
232
|
+
client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]):
|
|
233
|
+
Custom options for the client.
|
|
234
|
+
|
|
235
|
+
1. The ``api_endpoint`` property can be used to override the
|
|
236
|
+
default endpoint provided by the client when ``transport`` is
|
|
237
|
+
not explicitly provided. Only if this property is not set and
|
|
238
|
+
``transport`` was not explicitly provided, the endpoint is
|
|
239
|
+
determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment
|
|
240
|
+
variable, which have one of the following values:
|
|
241
|
+
"always" (always use the default mTLS endpoint), "never" (always
|
|
242
|
+
use the default regular endpoint) and "auto" (auto-switch to the
|
|
243
|
+
default mTLS endpoint if client certificate is present; this is
|
|
244
|
+
the default value).
|
|
245
|
+
|
|
246
|
+
2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
|
|
247
|
+
is "true", then the ``client_cert_source`` property can be used
|
|
248
|
+
to provide a client certificate for mTLS transport. If
|
|
249
|
+
not provided, the default SSL client certificate will be used if
|
|
250
|
+
present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
|
|
251
|
+
set, no client certificate will be used.
|
|
252
|
+
|
|
253
|
+
3. The ``universe_domain`` property can be used to override the
|
|
254
|
+
default "googleapis.com" universe. Note that ``api_endpoint``
|
|
255
|
+
property still takes precedence; and ``universe_domain`` is
|
|
256
|
+
currently not supported for mTLS.
|
|
257
|
+
|
|
258
|
+
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
|
|
259
|
+
The client info used to send a user-agent string along with
|
|
260
|
+
API requests. If ``None``, then default info will be used.
|
|
261
|
+
Generally, you only need to set this if you're developing
|
|
262
|
+
your own client library.
|
|
263
|
+
|
|
264
|
+
Raises:
|
|
265
|
+
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
|
|
266
|
+
creation failed for any reason.
|
|
267
|
+
"""
|
|
268
|
+
self._client = SpannerClient(
|
|
269
|
+
credentials=credentials,
|
|
270
|
+
transport=transport,
|
|
271
|
+
client_options=client_options,
|
|
272
|
+
client_info=client_info,
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
|
|
276
|
+
std_logging.DEBUG
|
|
277
|
+
): # pragma: NO COVER
|
|
278
|
+
_LOGGER.debug(
|
|
279
|
+
"Created client `google.spanner_v1.SpannerAsyncClient`.",
|
|
280
|
+
extra={
|
|
281
|
+
"serviceName": "google.spanner.v1.Spanner",
|
|
282
|
+
"universeDomain": getattr(
|
|
283
|
+
self._client._transport._credentials, "universe_domain", ""
|
|
284
|
+
),
|
|
285
|
+
"credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}",
|
|
286
|
+
"credentialsInfo": getattr(
|
|
287
|
+
self.transport._credentials, "get_cred_info", lambda: None
|
|
288
|
+
)(),
|
|
289
|
+
}
|
|
290
|
+
if hasattr(self._client._transport, "_credentials")
|
|
291
|
+
else {
|
|
292
|
+
"serviceName": "google.spanner.v1.Spanner",
|
|
293
|
+
"credentialsType": None,
|
|
294
|
+
},
|
|
295
|
+
)
|
|
296
|
+
|
|
297
|
+
async def create_session(
|
|
298
|
+
self,
|
|
299
|
+
request: Optional[Union[spanner.CreateSessionRequest, dict]] = None,
|
|
300
|
+
*,
|
|
301
|
+
database: Optional[str] = None,
|
|
302
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
303
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
304
|
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
|
305
|
+
) -> spanner.Session:
|
|
306
|
+
r"""Creates a new session. A session can be used to perform
|
|
307
|
+
transactions that read and/or modify data in a Cloud Spanner
|
|
308
|
+
database. Sessions are meant to be reused for many consecutive
|
|
309
|
+
transactions.
|
|
310
|
+
|
|
311
|
+
Sessions can only execute one transaction at a time. To execute
|
|
312
|
+
multiple concurrent read-write/write-only transactions, create
|
|
313
|
+
multiple sessions. Note that standalone reads and queries use a
|
|
314
|
+
transaction internally, and count toward the one transaction
|
|
315
|
+
limit.
|
|
316
|
+
|
|
317
|
+
Active sessions use additional server resources, so it is a good
|
|
318
|
+
idea to delete idle and unneeded sessions. Aside from explicit
|
|
319
|
+
deletes, Cloud Spanner may delete sessions for which no
|
|
320
|
+
operations are sent for more than an hour. If a session is
|
|
321
|
+
deleted, requests to it return ``NOT_FOUND``.
|
|
322
|
+
|
|
323
|
+
Idle sessions can be kept alive by sending a trivial SQL query
|
|
324
|
+
periodically, e.g., ``"SELECT 1"``.
|
|
325
|
+
|
|
326
|
+
.. code-block:: python
|
|
327
|
+
|
|
328
|
+
# This snippet has been automatically generated and should be regarded as a
|
|
329
|
+
# code template only.
|
|
330
|
+
# It will require modifications to work:
|
|
331
|
+
# - It may require correct/in-range values for request initialization.
|
|
332
|
+
# - It may require specifying regional endpoints when creating the service
|
|
333
|
+
# client as shown in:
|
|
334
|
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
|
335
|
+
from google.cloud import spanner_v1
|
|
336
|
+
|
|
337
|
+
async def sample_create_session():
|
|
338
|
+
# Create a client
|
|
339
|
+
client = spanner_v1.SpannerAsyncClient()
|
|
340
|
+
|
|
341
|
+
# Initialize request argument(s)
|
|
342
|
+
request = spanner_v1.CreateSessionRequest(
|
|
343
|
+
database="database_value",
|
|
344
|
+
)
|
|
345
|
+
|
|
346
|
+
# Make the request
|
|
347
|
+
response = await client.create_session(request=request)
|
|
348
|
+
|
|
349
|
+
# Handle the response
|
|
350
|
+
print(response)
|
|
351
|
+
|
|
352
|
+
Args:
|
|
353
|
+
request (Optional[Union[google.cloud.spanner_v1.types.CreateSessionRequest, dict]]):
|
|
354
|
+
The request object. The request for
|
|
355
|
+
[CreateSession][google.spanner.v1.Spanner.CreateSession].
|
|
356
|
+
database (:class:`str`):
|
|
357
|
+
Required. The database in which the
|
|
358
|
+
new session is created.
|
|
359
|
+
|
|
360
|
+
This corresponds to the ``database`` field
|
|
361
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
362
|
+
should not be set.
|
|
363
|
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
|
|
364
|
+
should be retried.
|
|
365
|
+
timeout (float): The timeout for this request.
|
|
366
|
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
|
367
|
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
|
368
|
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
|
369
|
+
be of type `bytes`.
|
|
370
|
+
|
|
371
|
+
Returns:
|
|
372
|
+
google.cloud.spanner_v1.types.Session:
|
|
373
|
+
A session in the Cloud Spanner API.
|
|
374
|
+
"""
|
|
375
|
+
# Create or coerce a protobuf request object.
|
|
376
|
+
# - Quick check: If we got a request object, we should *not* have
|
|
377
|
+
# gotten any keyword arguments that map to the request.
|
|
378
|
+
flattened_params = [database]
|
|
379
|
+
has_flattened_params = (
|
|
380
|
+
len([param for param in flattened_params if param is not None]) > 0
|
|
381
|
+
)
|
|
382
|
+
if request is not None and has_flattened_params:
|
|
383
|
+
raise ValueError(
|
|
384
|
+
"If the `request` argument is set, then none of "
|
|
385
|
+
"the individual field arguments should be set."
|
|
386
|
+
)
|
|
387
|
+
|
|
388
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
389
|
+
# there are no flattened fields), or create one.
|
|
390
|
+
if not isinstance(request, spanner.CreateSessionRequest):
|
|
391
|
+
request = spanner.CreateSessionRequest(request)
|
|
392
|
+
|
|
393
|
+
# If we have keyword arguments corresponding to fields on the
|
|
394
|
+
# request, apply these.
|
|
395
|
+
if database is not None:
|
|
396
|
+
request.database = database
|
|
397
|
+
|
|
398
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
399
|
+
# and friendly error handling.
|
|
400
|
+
rpc = self._client._transport._wrapped_methods[
|
|
401
|
+
self._client._transport.create_session
|
|
402
|
+
]
|
|
403
|
+
|
|
404
|
+
# Certain fields should be provided within the metadata header;
|
|
405
|
+
# add these here.
|
|
406
|
+
metadata = tuple(metadata) + (
|
|
407
|
+
gapic_v1.routing_header.to_grpc_metadata((("database", request.database),)),
|
|
408
|
+
)
|
|
409
|
+
|
|
410
|
+
# Validate the universe domain.
|
|
411
|
+
self._client._validate_universe_domain()
|
|
412
|
+
|
|
413
|
+
# Send the request.
|
|
414
|
+
response = await rpc(
|
|
415
|
+
request,
|
|
416
|
+
retry=retry,
|
|
417
|
+
timeout=timeout,
|
|
418
|
+
metadata=metadata,
|
|
419
|
+
)
|
|
420
|
+
|
|
421
|
+
# Done; return the response.
|
|
422
|
+
return response
|
|
423
|
+
|
|
424
|
+
async def batch_create_sessions(
|
|
425
|
+
self,
|
|
426
|
+
request: Optional[Union[spanner.BatchCreateSessionsRequest, dict]] = None,
|
|
427
|
+
*,
|
|
428
|
+
database: Optional[str] = None,
|
|
429
|
+
session_count: Optional[int] = None,
|
|
430
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
431
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
432
|
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
|
433
|
+
) -> spanner.BatchCreateSessionsResponse:
|
|
434
|
+
r"""Creates multiple new sessions.
|
|
435
|
+
|
|
436
|
+
This API can be used to initialize a session cache on
|
|
437
|
+
the clients. See https://goo.gl/TgSFN2 for best
|
|
438
|
+
practices on session cache management.
|
|
439
|
+
|
|
440
|
+
.. code-block:: python
|
|
441
|
+
|
|
442
|
+
# This snippet has been automatically generated and should be regarded as a
|
|
443
|
+
# code template only.
|
|
444
|
+
# It will require modifications to work:
|
|
445
|
+
# - It may require correct/in-range values for request initialization.
|
|
446
|
+
# - It may require specifying regional endpoints when creating the service
|
|
447
|
+
# client as shown in:
|
|
448
|
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
|
449
|
+
from google.cloud import spanner_v1
|
|
450
|
+
|
|
451
|
+
async def sample_batch_create_sessions():
|
|
452
|
+
# Create a client
|
|
453
|
+
client = spanner_v1.SpannerAsyncClient()
|
|
454
|
+
|
|
455
|
+
# Initialize request argument(s)
|
|
456
|
+
request = spanner_v1.BatchCreateSessionsRequest(
|
|
457
|
+
database="database_value",
|
|
458
|
+
session_count=1420,
|
|
459
|
+
)
|
|
460
|
+
|
|
461
|
+
# Make the request
|
|
462
|
+
response = await client.batch_create_sessions(request=request)
|
|
463
|
+
|
|
464
|
+
# Handle the response
|
|
465
|
+
print(response)
|
|
466
|
+
|
|
467
|
+
Args:
|
|
468
|
+
request (Optional[Union[google.cloud.spanner_v1.types.BatchCreateSessionsRequest, dict]]):
|
|
469
|
+
The request object. The request for
|
|
470
|
+
[BatchCreateSessions][google.spanner.v1.Spanner.BatchCreateSessions].
|
|
471
|
+
database (:class:`str`):
|
|
472
|
+
Required. The database in which the
|
|
473
|
+
new sessions are created.
|
|
474
|
+
|
|
475
|
+
This corresponds to the ``database`` field
|
|
476
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
477
|
+
should not be set.
|
|
478
|
+
session_count (:class:`int`):
|
|
479
|
+
Required. The number of sessions to be created in this
|
|
480
|
+
batch call. The API may return fewer than the requested
|
|
481
|
+
number of sessions. If a specific number of sessions are
|
|
482
|
+
desired, the client can make additional calls to
|
|
483
|
+
BatchCreateSessions (adjusting
|
|
484
|
+
[session_count][google.spanner.v1.BatchCreateSessionsRequest.session_count]
|
|
485
|
+
as necessary).
|
|
486
|
+
|
|
487
|
+
This corresponds to the ``session_count`` field
|
|
488
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
489
|
+
should not be set.
|
|
490
|
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
|
|
491
|
+
should be retried.
|
|
492
|
+
timeout (float): The timeout for this request.
|
|
493
|
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
|
494
|
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
|
495
|
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
|
496
|
+
be of type `bytes`.
|
|
497
|
+
|
|
498
|
+
Returns:
|
|
499
|
+
google.cloud.spanner_v1.types.BatchCreateSessionsResponse:
|
|
500
|
+
The response for
|
|
501
|
+
[BatchCreateSessions][google.spanner.v1.Spanner.BatchCreateSessions].
|
|
502
|
+
|
|
503
|
+
"""
|
|
504
|
+
# Create or coerce a protobuf request object.
|
|
505
|
+
# - Quick check: If we got a request object, we should *not* have
|
|
506
|
+
# gotten any keyword arguments that map to the request.
|
|
507
|
+
flattened_params = [database, session_count]
|
|
508
|
+
has_flattened_params = (
|
|
509
|
+
len([param for param in flattened_params if param is not None]) > 0
|
|
510
|
+
)
|
|
511
|
+
if request is not None and has_flattened_params:
|
|
512
|
+
raise ValueError(
|
|
513
|
+
"If the `request` argument is set, then none of "
|
|
514
|
+
"the individual field arguments should be set."
|
|
515
|
+
)
|
|
516
|
+
|
|
517
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
518
|
+
# there are no flattened fields), or create one.
|
|
519
|
+
if not isinstance(request, spanner.BatchCreateSessionsRequest):
|
|
520
|
+
request = spanner.BatchCreateSessionsRequest(request)
|
|
521
|
+
|
|
522
|
+
# If we have keyword arguments corresponding to fields on the
|
|
523
|
+
# request, apply these.
|
|
524
|
+
if database is not None:
|
|
525
|
+
request.database = database
|
|
526
|
+
if session_count is not None:
|
|
527
|
+
request.session_count = session_count
|
|
528
|
+
|
|
529
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
530
|
+
# and friendly error handling.
|
|
531
|
+
rpc = self._client._transport._wrapped_methods[
|
|
532
|
+
self._client._transport.batch_create_sessions
|
|
533
|
+
]
|
|
534
|
+
|
|
535
|
+
# Certain fields should be provided within the metadata header;
|
|
536
|
+
# add these here.
|
|
537
|
+
metadata = tuple(metadata) + (
|
|
538
|
+
gapic_v1.routing_header.to_grpc_metadata((("database", request.database),)),
|
|
539
|
+
)
|
|
540
|
+
|
|
541
|
+
# Validate the universe domain.
|
|
542
|
+
self._client._validate_universe_domain()
|
|
543
|
+
|
|
544
|
+
# Send the request.
|
|
545
|
+
response = await rpc(
|
|
546
|
+
request,
|
|
547
|
+
retry=retry,
|
|
548
|
+
timeout=timeout,
|
|
549
|
+
metadata=metadata,
|
|
550
|
+
)
|
|
551
|
+
|
|
552
|
+
# Done; return the response.
|
|
553
|
+
return response
|
|
554
|
+
|
|
555
|
+
async def get_session(
|
|
556
|
+
self,
|
|
557
|
+
request: Optional[Union[spanner.GetSessionRequest, dict]] = None,
|
|
558
|
+
*,
|
|
559
|
+
name: Optional[str] = None,
|
|
560
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
561
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
562
|
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
|
563
|
+
) -> spanner.Session:
|
|
564
|
+
r"""Gets a session. Returns ``NOT_FOUND`` if the session does not
|
|
565
|
+
exist. This is mainly useful for determining whether a session
|
|
566
|
+
is still alive.
|
|
567
|
+
|
|
568
|
+
.. code-block:: python
|
|
569
|
+
|
|
570
|
+
# This snippet has been automatically generated and should be regarded as a
|
|
571
|
+
# code template only.
|
|
572
|
+
# It will require modifications to work:
|
|
573
|
+
# - It may require correct/in-range values for request initialization.
|
|
574
|
+
# - It may require specifying regional endpoints when creating the service
|
|
575
|
+
# client as shown in:
|
|
576
|
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
|
577
|
+
from google.cloud import spanner_v1
|
|
578
|
+
|
|
579
|
+
async def sample_get_session():
|
|
580
|
+
# Create a client
|
|
581
|
+
client = spanner_v1.SpannerAsyncClient()
|
|
582
|
+
|
|
583
|
+
# Initialize request argument(s)
|
|
584
|
+
request = spanner_v1.GetSessionRequest(
|
|
585
|
+
name="name_value",
|
|
586
|
+
)
|
|
587
|
+
|
|
588
|
+
# Make the request
|
|
589
|
+
response = await client.get_session(request=request)
|
|
590
|
+
|
|
591
|
+
# Handle the response
|
|
592
|
+
print(response)
|
|
593
|
+
|
|
594
|
+
Args:
|
|
595
|
+
request (Optional[Union[google.cloud.spanner_v1.types.GetSessionRequest, dict]]):
|
|
596
|
+
The request object. The request for
|
|
597
|
+
[GetSession][google.spanner.v1.Spanner.GetSession].
|
|
598
|
+
name (:class:`str`):
|
|
599
|
+
Required. The name of the session to
|
|
600
|
+
retrieve.
|
|
601
|
+
|
|
602
|
+
This corresponds to the ``name`` field
|
|
603
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
604
|
+
should not be set.
|
|
605
|
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
|
|
606
|
+
should be retried.
|
|
607
|
+
timeout (float): The timeout for this request.
|
|
608
|
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
|
609
|
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
|
610
|
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
|
611
|
+
be of type `bytes`.
|
|
612
|
+
|
|
613
|
+
Returns:
|
|
614
|
+
google.cloud.spanner_v1.types.Session:
|
|
615
|
+
A session in the Cloud Spanner API.
|
|
616
|
+
"""
|
|
617
|
+
# Create or coerce a protobuf request object.
|
|
618
|
+
# - Quick check: If we got a request object, we should *not* have
|
|
619
|
+
# gotten any keyword arguments that map to the request.
|
|
620
|
+
flattened_params = [name]
|
|
621
|
+
has_flattened_params = (
|
|
622
|
+
len([param for param in flattened_params if param is not None]) > 0
|
|
623
|
+
)
|
|
624
|
+
if request is not None and has_flattened_params:
|
|
625
|
+
raise ValueError(
|
|
626
|
+
"If the `request` argument is set, then none of "
|
|
627
|
+
"the individual field arguments should be set."
|
|
628
|
+
)
|
|
629
|
+
|
|
630
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
631
|
+
# there are no flattened fields), or create one.
|
|
632
|
+
if not isinstance(request, spanner.GetSessionRequest):
|
|
633
|
+
request = spanner.GetSessionRequest(request)
|
|
634
|
+
|
|
635
|
+
# If we have keyword arguments corresponding to fields on the
|
|
636
|
+
# request, apply these.
|
|
637
|
+
if name is not None:
|
|
638
|
+
request.name = name
|
|
639
|
+
|
|
640
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
641
|
+
# and friendly error handling.
|
|
642
|
+
rpc = self._client._transport._wrapped_methods[
|
|
643
|
+
self._client._transport.get_session
|
|
644
|
+
]
|
|
645
|
+
|
|
646
|
+
# Certain fields should be provided within the metadata header;
|
|
647
|
+
# add these here.
|
|
648
|
+
metadata = tuple(metadata) + (
|
|
649
|
+
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
|
|
650
|
+
)
|
|
651
|
+
|
|
652
|
+
# Validate the universe domain.
|
|
653
|
+
self._client._validate_universe_domain()
|
|
654
|
+
|
|
655
|
+
# Send the request.
|
|
656
|
+
response = await rpc(
|
|
657
|
+
request,
|
|
658
|
+
retry=retry,
|
|
659
|
+
timeout=timeout,
|
|
660
|
+
metadata=metadata,
|
|
661
|
+
)
|
|
662
|
+
|
|
663
|
+
# Done; return the response.
|
|
664
|
+
return response
|
|
665
|
+
|
|
666
|
+
async def list_sessions(
|
|
667
|
+
self,
|
|
668
|
+
request: Optional[Union[spanner.ListSessionsRequest, dict]] = None,
|
|
669
|
+
*,
|
|
670
|
+
database: Optional[str] = None,
|
|
671
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
672
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
673
|
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
|
674
|
+
) -> pagers.ListSessionsAsyncPager:
|
|
675
|
+
r"""Lists all sessions in a given database.
|
|
676
|
+
|
|
677
|
+
.. code-block:: python
|
|
678
|
+
|
|
679
|
+
# This snippet has been automatically generated and should be regarded as a
|
|
680
|
+
# code template only.
|
|
681
|
+
# It will require modifications to work:
|
|
682
|
+
# - It may require correct/in-range values for request initialization.
|
|
683
|
+
# - It may require specifying regional endpoints when creating the service
|
|
684
|
+
# client as shown in:
|
|
685
|
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
|
686
|
+
from google.cloud import spanner_v1
|
|
687
|
+
|
|
688
|
+
async def sample_list_sessions():
|
|
689
|
+
# Create a client
|
|
690
|
+
client = spanner_v1.SpannerAsyncClient()
|
|
691
|
+
|
|
692
|
+
# Initialize request argument(s)
|
|
693
|
+
request = spanner_v1.ListSessionsRequest(
|
|
694
|
+
database="database_value",
|
|
695
|
+
)
|
|
696
|
+
|
|
697
|
+
# Make the request
|
|
698
|
+
page_result = client.list_sessions(request=request)
|
|
699
|
+
|
|
700
|
+
# Handle the response
|
|
701
|
+
async for response in page_result:
|
|
702
|
+
print(response)
|
|
703
|
+
|
|
704
|
+
Args:
|
|
705
|
+
request (Optional[Union[google.cloud.spanner_v1.types.ListSessionsRequest, dict]]):
|
|
706
|
+
The request object. The request for
|
|
707
|
+
[ListSessions][google.spanner.v1.Spanner.ListSessions].
|
|
708
|
+
database (:class:`str`):
|
|
709
|
+
Required. The database in which to
|
|
710
|
+
list sessions.
|
|
711
|
+
|
|
712
|
+
This corresponds to the ``database`` field
|
|
713
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
714
|
+
should not be set.
|
|
715
|
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
|
|
716
|
+
should be retried.
|
|
717
|
+
timeout (float): The timeout for this request.
|
|
718
|
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
|
719
|
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
|
720
|
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
|
721
|
+
be of type `bytes`.
|
|
722
|
+
|
|
723
|
+
Returns:
|
|
724
|
+
google.cloud.spanner_v1.services.spanner.pagers.ListSessionsAsyncPager:
|
|
725
|
+
The response for
|
|
726
|
+
[ListSessions][google.spanner.v1.Spanner.ListSessions].
|
|
727
|
+
|
|
728
|
+
Iterating over this object will yield results and
|
|
729
|
+
resolve additional pages automatically.
|
|
730
|
+
|
|
731
|
+
"""
|
|
732
|
+
# Create or coerce a protobuf request object.
|
|
733
|
+
# - Quick check: If we got a request object, we should *not* have
|
|
734
|
+
# gotten any keyword arguments that map to the request.
|
|
735
|
+
flattened_params = [database]
|
|
736
|
+
has_flattened_params = (
|
|
737
|
+
len([param for param in flattened_params if param is not None]) > 0
|
|
738
|
+
)
|
|
739
|
+
if request is not None and has_flattened_params:
|
|
740
|
+
raise ValueError(
|
|
741
|
+
"If the `request` argument is set, then none of "
|
|
742
|
+
"the individual field arguments should be set."
|
|
743
|
+
)
|
|
744
|
+
|
|
745
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
746
|
+
# there are no flattened fields), or create one.
|
|
747
|
+
if not isinstance(request, spanner.ListSessionsRequest):
|
|
748
|
+
request = spanner.ListSessionsRequest(request)
|
|
749
|
+
|
|
750
|
+
# If we have keyword arguments corresponding to fields on the
|
|
751
|
+
# request, apply these.
|
|
752
|
+
if database is not None:
|
|
753
|
+
request.database = database
|
|
754
|
+
|
|
755
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
756
|
+
# and friendly error handling.
|
|
757
|
+
rpc = self._client._transport._wrapped_methods[
|
|
758
|
+
self._client._transport.list_sessions
|
|
759
|
+
]
|
|
760
|
+
|
|
761
|
+
# Certain fields should be provided within the metadata header;
|
|
762
|
+
# add these here.
|
|
763
|
+
metadata = tuple(metadata) + (
|
|
764
|
+
gapic_v1.routing_header.to_grpc_metadata((("database", request.database),)),
|
|
765
|
+
)
|
|
766
|
+
|
|
767
|
+
# Validate the universe domain.
|
|
768
|
+
self._client._validate_universe_domain()
|
|
769
|
+
|
|
770
|
+
# Send the request.
|
|
771
|
+
response = await rpc(
|
|
772
|
+
request,
|
|
773
|
+
retry=retry,
|
|
774
|
+
timeout=timeout,
|
|
775
|
+
metadata=metadata,
|
|
776
|
+
)
|
|
777
|
+
|
|
778
|
+
# This method is paged; wrap the response in a pager, which provides
|
|
779
|
+
# an `__aiter__` convenience method.
|
|
780
|
+
response = pagers.ListSessionsAsyncPager(
|
|
781
|
+
method=rpc,
|
|
782
|
+
request=request,
|
|
783
|
+
response=response,
|
|
784
|
+
retry=retry,
|
|
785
|
+
timeout=timeout,
|
|
786
|
+
metadata=metadata,
|
|
787
|
+
)
|
|
788
|
+
|
|
789
|
+
# Done; return the response.
|
|
790
|
+
return response
|
|
791
|
+
|
|
792
|
+
async def delete_session(
|
|
793
|
+
self,
|
|
794
|
+
request: Optional[Union[spanner.DeleteSessionRequest, dict]] = None,
|
|
795
|
+
*,
|
|
796
|
+
name: Optional[str] = None,
|
|
797
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
798
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
799
|
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
|
800
|
+
) -> None:
|
|
801
|
+
r"""Ends a session, releasing server resources associated
|
|
802
|
+
with it. This will asynchronously trigger cancellation
|
|
803
|
+
of any operations that are running with this session.
|
|
804
|
+
|
|
805
|
+
.. code-block:: python
|
|
806
|
+
|
|
807
|
+
# This snippet has been automatically generated and should be regarded as a
|
|
808
|
+
# code template only.
|
|
809
|
+
# It will require modifications to work:
|
|
810
|
+
# - It may require correct/in-range values for request initialization.
|
|
811
|
+
# - It may require specifying regional endpoints when creating the service
|
|
812
|
+
# client as shown in:
|
|
813
|
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
|
814
|
+
from google.cloud import spanner_v1
|
|
815
|
+
|
|
816
|
+
async def sample_delete_session():
|
|
817
|
+
# Create a client
|
|
818
|
+
client = spanner_v1.SpannerAsyncClient()
|
|
819
|
+
|
|
820
|
+
# Initialize request argument(s)
|
|
821
|
+
request = spanner_v1.DeleteSessionRequest(
|
|
822
|
+
name="name_value",
|
|
823
|
+
)
|
|
824
|
+
|
|
825
|
+
# Make the request
|
|
826
|
+
await client.delete_session(request=request)
|
|
827
|
+
|
|
828
|
+
Args:
|
|
829
|
+
request (Optional[Union[google.cloud.spanner_v1.types.DeleteSessionRequest, dict]]):
|
|
830
|
+
The request object. The request for
|
|
831
|
+
[DeleteSession][google.spanner.v1.Spanner.DeleteSession].
|
|
832
|
+
name (:class:`str`):
|
|
833
|
+
Required. The name of the session to
|
|
834
|
+
delete.
|
|
835
|
+
|
|
836
|
+
This corresponds to the ``name`` field
|
|
837
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
838
|
+
should not be set.
|
|
839
|
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
|
|
840
|
+
should be retried.
|
|
841
|
+
timeout (float): The timeout for this request.
|
|
842
|
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
|
843
|
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
|
844
|
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
|
845
|
+
be of type `bytes`.
|
|
846
|
+
"""
|
|
847
|
+
# Create or coerce a protobuf request object.
|
|
848
|
+
# - Quick check: If we got a request object, we should *not* have
|
|
849
|
+
# gotten any keyword arguments that map to the request.
|
|
850
|
+
flattened_params = [name]
|
|
851
|
+
has_flattened_params = (
|
|
852
|
+
len([param for param in flattened_params if param is not None]) > 0
|
|
853
|
+
)
|
|
854
|
+
if request is not None and has_flattened_params:
|
|
855
|
+
raise ValueError(
|
|
856
|
+
"If the `request` argument is set, then none of "
|
|
857
|
+
"the individual field arguments should be set."
|
|
858
|
+
)
|
|
859
|
+
|
|
860
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
861
|
+
# there are no flattened fields), or create one.
|
|
862
|
+
if not isinstance(request, spanner.DeleteSessionRequest):
|
|
863
|
+
request = spanner.DeleteSessionRequest(request)
|
|
864
|
+
|
|
865
|
+
# If we have keyword arguments corresponding to fields on the
|
|
866
|
+
# request, apply these.
|
|
867
|
+
if name is not None:
|
|
868
|
+
request.name = name
|
|
869
|
+
|
|
870
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
871
|
+
# and friendly error handling.
|
|
872
|
+
rpc = self._client._transport._wrapped_methods[
|
|
873
|
+
self._client._transport.delete_session
|
|
874
|
+
]
|
|
875
|
+
|
|
876
|
+
# Certain fields should be provided within the metadata header;
|
|
877
|
+
# add these here.
|
|
878
|
+
metadata = tuple(metadata) + (
|
|
879
|
+
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
|
|
880
|
+
)
|
|
881
|
+
|
|
882
|
+
# Validate the universe domain.
|
|
883
|
+
self._client._validate_universe_domain()
|
|
884
|
+
|
|
885
|
+
# Send the request.
|
|
886
|
+
await rpc(
|
|
887
|
+
request,
|
|
888
|
+
retry=retry,
|
|
889
|
+
timeout=timeout,
|
|
890
|
+
metadata=metadata,
|
|
891
|
+
)
|
|
892
|
+
|
|
893
|
+
async def execute_sql(
|
|
894
|
+
self,
|
|
895
|
+
request: Optional[Union[spanner.ExecuteSqlRequest, dict]] = None,
|
|
896
|
+
*,
|
|
897
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
898
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
899
|
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
|
900
|
+
) -> result_set.ResultSet:
|
|
901
|
+
r"""Executes an SQL statement, returning all results in a single
|
|
902
|
+
reply. This method cannot be used to return a result set larger
|
|
903
|
+
than 10 MiB; if the query yields more data than that, the query
|
|
904
|
+
fails with a ``FAILED_PRECONDITION`` error.
|
|
905
|
+
|
|
906
|
+
Operations inside read-write transactions might return
|
|
907
|
+
``ABORTED``. If this occurs, the application should restart the
|
|
908
|
+
transaction from the beginning. See
|
|
909
|
+
[Transaction][google.spanner.v1.Transaction] for more details.
|
|
910
|
+
|
|
911
|
+
Larger result sets can be fetched in streaming fashion by
|
|
912
|
+
calling
|
|
913
|
+
[ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql]
|
|
914
|
+
instead.
|
|
915
|
+
|
|
916
|
+
.. code-block:: python
|
|
917
|
+
|
|
918
|
+
# This snippet has been automatically generated and should be regarded as a
|
|
919
|
+
# code template only.
|
|
920
|
+
# It will require modifications to work:
|
|
921
|
+
# - It may require correct/in-range values for request initialization.
|
|
922
|
+
# - It may require specifying regional endpoints when creating the service
|
|
923
|
+
# client as shown in:
|
|
924
|
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
|
925
|
+
from google.cloud import spanner_v1
|
|
926
|
+
|
|
927
|
+
async def sample_execute_sql():
|
|
928
|
+
# Create a client
|
|
929
|
+
client = spanner_v1.SpannerAsyncClient()
|
|
930
|
+
|
|
931
|
+
# Initialize request argument(s)
|
|
932
|
+
request = spanner_v1.ExecuteSqlRequest(
|
|
933
|
+
session="session_value",
|
|
934
|
+
sql="sql_value",
|
|
935
|
+
)
|
|
936
|
+
|
|
937
|
+
# Make the request
|
|
938
|
+
response = await client.execute_sql(request=request)
|
|
939
|
+
|
|
940
|
+
# Handle the response
|
|
941
|
+
print(response)
|
|
942
|
+
|
|
943
|
+
Args:
|
|
944
|
+
request (Optional[Union[google.cloud.spanner_v1.types.ExecuteSqlRequest, dict]]):
|
|
945
|
+
The request object. The request for
|
|
946
|
+
[ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and
|
|
947
|
+
[ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql].
|
|
948
|
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
|
|
949
|
+
should be retried.
|
|
950
|
+
timeout (float): The timeout for this request.
|
|
951
|
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
|
952
|
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
|
953
|
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
|
954
|
+
be of type `bytes`.
|
|
955
|
+
|
|
956
|
+
Returns:
|
|
957
|
+
google.cloud.spanner_v1.types.ResultSet:
|
|
958
|
+
Results from [Read][google.spanner.v1.Spanner.Read] or
|
|
959
|
+
[ExecuteSql][google.spanner.v1.Spanner.ExecuteSql].
|
|
960
|
+
|
|
961
|
+
"""
|
|
962
|
+
# Create or coerce a protobuf request object.
|
|
963
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
964
|
+
# there are no flattened fields), or create one.
|
|
965
|
+
if not isinstance(request, spanner.ExecuteSqlRequest):
|
|
966
|
+
request = spanner.ExecuteSqlRequest(request)
|
|
967
|
+
|
|
968
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
969
|
+
# and friendly error handling.
|
|
970
|
+
rpc = self._client._transport._wrapped_methods[
|
|
971
|
+
self._client._transport.execute_sql
|
|
972
|
+
]
|
|
973
|
+
|
|
974
|
+
# Certain fields should be provided within the metadata header;
|
|
975
|
+
# add these here.
|
|
976
|
+
metadata = tuple(metadata) + (
|
|
977
|
+
gapic_v1.routing_header.to_grpc_metadata((("session", request.session),)),
|
|
978
|
+
)
|
|
979
|
+
|
|
980
|
+
# Validate the universe domain.
|
|
981
|
+
self._client._validate_universe_domain()
|
|
982
|
+
|
|
983
|
+
# Send the request.
|
|
984
|
+
response = await rpc(
|
|
985
|
+
request,
|
|
986
|
+
retry=retry,
|
|
987
|
+
timeout=timeout,
|
|
988
|
+
metadata=metadata,
|
|
989
|
+
)
|
|
990
|
+
|
|
991
|
+
# Done; return the response.
|
|
992
|
+
return response
|
|
993
|
+
|
|
994
|
+
def execute_streaming_sql(
|
|
995
|
+
self,
|
|
996
|
+
request: Optional[Union[spanner.ExecuteSqlRequest, dict]] = None,
|
|
997
|
+
*,
|
|
998
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
999
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
1000
|
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
|
1001
|
+
) -> Awaitable[AsyncIterable[result_set.PartialResultSet]]:
|
|
1002
|
+
r"""Like [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], except
|
|
1003
|
+
returns the result set as a stream. Unlike
|
|
1004
|
+
[ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], there is no
|
|
1005
|
+
limit on the size of the returned result set. However, no
|
|
1006
|
+
individual row in the result set can exceed 100 MiB, and no
|
|
1007
|
+
column value can exceed 10 MiB.
|
|
1008
|
+
|
|
1009
|
+
.. code-block:: python
|
|
1010
|
+
|
|
1011
|
+
# This snippet has been automatically generated and should be regarded as a
|
|
1012
|
+
# code template only.
|
|
1013
|
+
# It will require modifications to work:
|
|
1014
|
+
# - It may require correct/in-range values for request initialization.
|
|
1015
|
+
# - It may require specifying regional endpoints when creating the service
|
|
1016
|
+
# client as shown in:
|
|
1017
|
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
|
1018
|
+
from google.cloud import spanner_v1
|
|
1019
|
+
|
|
1020
|
+
async def sample_execute_streaming_sql():
|
|
1021
|
+
# Create a client
|
|
1022
|
+
client = spanner_v1.SpannerAsyncClient()
|
|
1023
|
+
|
|
1024
|
+
# Initialize request argument(s)
|
|
1025
|
+
request = spanner_v1.ExecuteSqlRequest(
|
|
1026
|
+
session="session_value",
|
|
1027
|
+
sql="sql_value",
|
|
1028
|
+
)
|
|
1029
|
+
|
|
1030
|
+
# Make the request
|
|
1031
|
+
stream = await client.execute_streaming_sql(request=request)
|
|
1032
|
+
|
|
1033
|
+
# Handle the response
|
|
1034
|
+
async for response in stream:
|
|
1035
|
+
print(response)
|
|
1036
|
+
|
|
1037
|
+
Args:
|
|
1038
|
+
request (Optional[Union[google.cloud.spanner_v1.types.ExecuteSqlRequest, dict]]):
|
|
1039
|
+
The request object. The request for
|
|
1040
|
+
[ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and
|
|
1041
|
+
[ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql].
|
|
1042
|
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
|
|
1043
|
+
should be retried.
|
|
1044
|
+
timeout (float): The timeout for this request.
|
|
1045
|
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
|
1046
|
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
|
1047
|
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
|
1048
|
+
be of type `bytes`.
|
|
1049
|
+
|
|
1050
|
+
Returns:
|
|
1051
|
+
AsyncIterable[google.cloud.spanner_v1.types.PartialResultSet]:
|
|
1052
|
+
Partial results from a streaming read
|
|
1053
|
+
or SQL query. Streaming reads and SQL
|
|
1054
|
+
queries better tolerate large result
|
|
1055
|
+
sets, large rows, and large values, but
|
|
1056
|
+
are a little trickier to consume.
|
|
1057
|
+
|
|
1058
|
+
"""
|
|
1059
|
+
# Create or coerce a protobuf request object.
|
|
1060
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
1061
|
+
# there are no flattened fields), or create one.
|
|
1062
|
+
if not isinstance(request, spanner.ExecuteSqlRequest):
|
|
1063
|
+
request = spanner.ExecuteSqlRequest(request)
|
|
1064
|
+
|
|
1065
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
1066
|
+
# and friendly error handling.
|
|
1067
|
+
rpc = self._client._transport._wrapped_methods[
|
|
1068
|
+
self._client._transport.execute_streaming_sql
|
|
1069
|
+
]
|
|
1070
|
+
|
|
1071
|
+
# Certain fields should be provided within the metadata header;
|
|
1072
|
+
# add these here.
|
|
1073
|
+
metadata = tuple(metadata) + (
|
|
1074
|
+
gapic_v1.routing_header.to_grpc_metadata((("session", request.session),)),
|
|
1075
|
+
)
|
|
1076
|
+
|
|
1077
|
+
# Validate the universe domain.
|
|
1078
|
+
self._client._validate_universe_domain()
|
|
1079
|
+
|
|
1080
|
+
# Send the request.
|
|
1081
|
+
response = rpc(
|
|
1082
|
+
request,
|
|
1083
|
+
retry=retry,
|
|
1084
|
+
timeout=timeout,
|
|
1085
|
+
metadata=metadata,
|
|
1086
|
+
)
|
|
1087
|
+
|
|
1088
|
+
# Done; return the response.
|
|
1089
|
+
return response
|
|
1090
|
+
|
|
1091
|
+
async def execute_batch_dml(
|
|
1092
|
+
self,
|
|
1093
|
+
request: Optional[Union[spanner.ExecuteBatchDmlRequest, dict]] = None,
|
|
1094
|
+
*,
|
|
1095
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
1096
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
1097
|
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
|
1098
|
+
) -> spanner.ExecuteBatchDmlResponse:
|
|
1099
|
+
r"""Executes a batch of SQL DML statements. This method allows many
|
|
1100
|
+
statements to be run with lower latency than submitting them
|
|
1101
|
+
sequentially with
|
|
1102
|
+
[ExecuteSql][google.spanner.v1.Spanner.ExecuteSql].
|
|
1103
|
+
|
|
1104
|
+
Statements are executed in sequential order. A request can
|
|
1105
|
+
succeed even if a statement fails. The
|
|
1106
|
+
[ExecuteBatchDmlResponse.status][google.spanner.v1.ExecuteBatchDmlResponse.status]
|
|
1107
|
+
field in the response provides information about the statement
|
|
1108
|
+
that failed. Clients must inspect this field to determine
|
|
1109
|
+
whether an error occurred.
|
|
1110
|
+
|
|
1111
|
+
Execution stops after the first failed statement; the remaining
|
|
1112
|
+
statements are not executed.
|
|
1113
|
+
|
|
1114
|
+
.. code-block:: python
|
|
1115
|
+
|
|
1116
|
+
# This snippet has been automatically generated and should be regarded as a
|
|
1117
|
+
# code template only.
|
|
1118
|
+
# It will require modifications to work:
|
|
1119
|
+
# - It may require correct/in-range values for request initialization.
|
|
1120
|
+
# - It may require specifying regional endpoints when creating the service
|
|
1121
|
+
# client as shown in:
|
|
1122
|
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
|
1123
|
+
from google.cloud import spanner_v1
|
|
1124
|
+
|
|
1125
|
+
async def sample_execute_batch_dml():
|
|
1126
|
+
# Create a client
|
|
1127
|
+
client = spanner_v1.SpannerAsyncClient()
|
|
1128
|
+
|
|
1129
|
+
# Initialize request argument(s)
|
|
1130
|
+
statements = spanner_v1.Statement()
|
|
1131
|
+
statements.sql = "sql_value"
|
|
1132
|
+
|
|
1133
|
+
request = spanner_v1.ExecuteBatchDmlRequest(
|
|
1134
|
+
session="session_value",
|
|
1135
|
+
statements=statements,
|
|
1136
|
+
seqno=550,
|
|
1137
|
+
)
|
|
1138
|
+
|
|
1139
|
+
# Make the request
|
|
1140
|
+
response = await client.execute_batch_dml(request=request)
|
|
1141
|
+
|
|
1142
|
+
# Handle the response
|
|
1143
|
+
print(response)
|
|
1144
|
+
|
|
1145
|
+
Args:
|
|
1146
|
+
request (Optional[Union[google.cloud.spanner_v1.types.ExecuteBatchDmlRequest, dict]]):
|
|
1147
|
+
The request object. The request for
|
|
1148
|
+
[ExecuteBatchDml][google.spanner.v1.Spanner.ExecuteBatchDml].
|
|
1149
|
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
|
|
1150
|
+
should be retried.
|
|
1151
|
+
timeout (float): The timeout for this request.
|
|
1152
|
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
|
1153
|
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
|
1154
|
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
|
1155
|
+
be of type `bytes`.
|
|
1156
|
+
|
|
1157
|
+
Returns:
|
|
1158
|
+
google.cloud.spanner_v1.types.ExecuteBatchDmlResponse:
|
|
1159
|
+
The response for
|
|
1160
|
+
[ExecuteBatchDml][google.spanner.v1.Spanner.ExecuteBatchDml].
|
|
1161
|
+
Contains a list of
|
|
1162
|
+
[ResultSet][google.spanner.v1.ResultSet] messages,
|
|
1163
|
+
one for each DML statement that has successfully
|
|
1164
|
+
executed, in the same order as the statements in the
|
|
1165
|
+
request. If a statement fails, the status in the
|
|
1166
|
+
response body identifies the cause of the failure.
|
|
1167
|
+
|
|
1168
|
+
To check for DML statements that failed, use the
|
|
1169
|
+
following approach:
|
|
1170
|
+
|
|
1171
|
+
1. Check the status in the response message. The
|
|
1172
|
+
[google.rpc.Code][google.rpc.Code] enum value OK
|
|
1173
|
+
indicates that all statements were executed
|
|
1174
|
+
successfully. 2. If the status was not OK, check the
|
|
1175
|
+
number of result sets in the response. If the
|
|
1176
|
+
response contains N
|
|
1177
|
+
[ResultSet][google.spanner.v1.ResultSet] messages,
|
|
1178
|
+
then statement N+1 in the request failed.
|
|
1179
|
+
|
|
1180
|
+
Example 1:
|
|
1181
|
+
|
|
1182
|
+
- Request: 5 DML statements, all executed
|
|
1183
|
+
successfully.
|
|
1184
|
+
|
|
1185
|
+
\* Response: 5
|
|
1186
|
+
[ResultSet][google.spanner.v1.ResultSet] messages,
|
|
1187
|
+
with the status OK.
|
|
1188
|
+
|
|
1189
|
+
Example 2:
|
|
1190
|
+
|
|
1191
|
+
- Request: 5 DML statements. The third statement has
|
|
1192
|
+
a syntax error.
|
|
1193
|
+
|
|
1194
|
+
\* Response: 2
|
|
1195
|
+
[ResultSet][google.spanner.v1.ResultSet] messages,
|
|
1196
|
+
and a syntax error (INVALID_ARGUMENT) status. The
|
|
1197
|
+
number of [ResultSet][google.spanner.v1.ResultSet]
|
|
1198
|
+
messages indicates that the third statement failed,
|
|
1199
|
+
and the fourth and fifth statements were not
|
|
1200
|
+
executed.
|
|
1201
|
+
|
|
1202
|
+
"""
|
|
1203
|
+
# Create or coerce a protobuf request object.
|
|
1204
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
1205
|
+
# there are no flattened fields), or create one.
|
|
1206
|
+
if not isinstance(request, spanner.ExecuteBatchDmlRequest):
|
|
1207
|
+
request = spanner.ExecuteBatchDmlRequest(request)
|
|
1208
|
+
|
|
1209
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
1210
|
+
# and friendly error handling.
|
|
1211
|
+
rpc = self._client._transport._wrapped_methods[
|
|
1212
|
+
self._client._transport.execute_batch_dml
|
|
1213
|
+
]
|
|
1214
|
+
|
|
1215
|
+
# Certain fields should be provided within the metadata header;
|
|
1216
|
+
# add these here.
|
|
1217
|
+
metadata = tuple(metadata) + (
|
|
1218
|
+
gapic_v1.routing_header.to_grpc_metadata((("session", request.session),)),
|
|
1219
|
+
)
|
|
1220
|
+
|
|
1221
|
+
# Validate the universe domain.
|
|
1222
|
+
self._client._validate_universe_domain()
|
|
1223
|
+
|
|
1224
|
+
# Send the request.
|
|
1225
|
+
response = await rpc(
|
|
1226
|
+
request,
|
|
1227
|
+
retry=retry,
|
|
1228
|
+
timeout=timeout,
|
|
1229
|
+
metadata=metadata,
|
|
1230
|
+
)
|
|
1231
|
+
|
|
1232
|
+
# Done; return the response.
|
|
1233
|
+
return response
|
|
1234
|
+
|
|
1235
|
+
async def read(
|
|
1236
|
+
self,
|
|
1237
|
+
request: Optional[Union[spanner.ReadRequest, dict]] = None,
|
|
1238
|
+
*,
|
|
1239
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
1240
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
1241
|
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
|
1242
|
+
) -> result_set.ResultSet:
|
|
1243
|
+
r"""Reads rows from the database using key lookups and scans, as a
|
|
1244
|
+
simple key/value style alternative to
|
|
1245
|
+
[ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. This method
|
|
1246
|
+
cannot be used to return a result set larger than 10 MiB; if the
|
|
1247
|
+
read matches more data than that, the read fails with a
|
|
1248
|
+
``FAILED_PRECONDITION`` error.
|
|
1249
|
+
|
|
1250
|
+
Reads inside read-write transactions might return ``ABORTED``.
|
|
1251
|
+
If this occurs, the application should restart the transaction
|
|
1252
|
+
from the beginning. See
|
|
1253
|
+
[Transaction][google.spanner.v1.Transaction] for more details.
|
|
1254
|
+
|
|
1255
|
+
Larger result sets can be yielded in streaming fashion by
|
|
1256
|
+
calling [StreamingRead][google.spanner.v1.Spanner.StreamingRead]
|
|
1257
|
+
instead.
|
|
1258
|
+
|
|
1259
|
+
.. code-block:: python
|
|
1260
|
+
|
|
1261
|
+
# This snippet has been automatically generated and should be regarded as a
|
|
1262
|
+
# code template only.
|
|
1263
|
+
# It will require modifications to work:
|
|
1264
|
+
# - It may require correct/in-range values for request initialization.
|
|
1265
|
+
# - It may require specifying regional endpoints when creating the service
|
|
1266
|
+
# client as shown in:
|
|
1267
|
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
|
1268
|
+
from google.cloud import spanner_v1
|
|
1269
|
+
|
|
1270
|
+
async def sample_read():
|
|
1271
|
+
# Create a client
|
|
1272
|
+
client = spanner_v1.SpannerAsyncClient()
|
|
1273
|
+
|
|
1274
|
+
# Initialize request argument(s)
|
|
1275
|
+
request = spanner_v1.ReadRequest(
|
|
1276
|
+
session="session_value",
|
|
1277
|
+
table="table_value",
|
|
1278
|
+
columns=['columns_value1', 'columns_value2'],
|
|
1279
|
+
)
|
|
1280
|
+
|
|
1281
|
+
# Make the request
|
|
1282
|
+
response = await client.read(request=request)
|
|
1283
|
+
|
|
1284
|
+
# Handle the response
|
|
1285
|
+
print(response)
|
|
1286
|
+
|
|
1287
|
+
Args:
|
|
1288
|
+
request (Optional[Union[google.cloud.spanner_v1.types.ReadRequest, dict]]):
|
|
1289
|
+
The request object. The request for [Read][google.spanner.v1.Spanner.Read]
|
|
1290
|
+
and
|
|
1291
|
+
[StreamingRead][google.spanner.v1.Spanner.StreamingRead].
|
|
1292
|
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
|
|
1293
|
+
should be retried.
|
|
1294
|
+
timeout (float): The timeout for this request.
|
|
1295
|
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
|
1296
|
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
|
1297
|
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
|
1298
|
+
be of type `bytes`.
|
|
1299
|
+
|
|
1300
|
+
Returns:
|
|
1301
|
+
google.cloud.spanner_v1.types.ResultSet:
|
|
1302
|
+
Results from [Read][google.spanner.v1.Spanner.Read] or
|
|
1303
|
+
[ExecuteSql][google.spanner.v1.Spanner.ExecuteSql].
|
|
1304
|
+
|
|
1305
|
+
"""
|
|
1306
|
+
# Create or coerce a protobuf request object.
|
|
1307
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
1308
|
+
# there are no flattened fields), or create one.
|
|
1309
|
+
if not isinstance(request, spanner.ReadRequest):
|
|
1310
|
+
request = spanner.ReadRequest(request)
|
|
1311
|
+
|
|
1312
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
1313
|
+
# and friendly error handling.
|
|
1314
|
+
rpc = self._client._transport._wrapped_methods[self._client._transport.read]
|
|
1315
|
+
|
|
1316
|
+
# Certain fields should be provided within the metadata header;
|
|
1317
|
+
# add these here.
|
|
1318
|
+
metadata = tuple(metadata) + (
|
|
1319
|
+
gapic_v1.routing_header.to_grpc_metadata((("session", request.session),)),
|
|
1320
|
+
)
|
|
1321
|
+
|
|
1322
|
+
# Validate the universe domain.
|
|
1323
|
+
self._client._validate_universe_domain()
|
|
1324
|
+
|
|
1325
|
+
# Send the request.
|
|
1326
|
+
response = await rpc(
|
|
1327
|
+
request,
|
|
1328
|
+
retry=retry,
|
|
1329
|
+
timeout=timeout,
|
|
1330
|
+
metadata=metadata,
|
|
1331
|
+
)
|
|
1332
|
+
|
|
1333
|
+
# Done; return the response.
|
|
1334
|
+
return response
|
|
1335
|
+
|
|
1336
|
+
def streaming_read(
|
|
1337
|
+
self,
|
|
1338
|
+
request: Optional[Union[spanner.ReadRequest, dict]] = None,
|
|
1339
|
+
*,
|
|
1340
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
1341
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
1342
|
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
|
1343
|
+
) -> Awaitable[AsyncIterable[result_set.PartialResultSet]]:
|
|
1344
|
+
r"""Like [Read][google.spanner.v1.Spanner.Read], except returns the
|
|
1345
|
+
result set as a stream. Unlike
|
|
1346
|
+
[Read][google.spanner.v1.Spanner.Read], there is no limit on the
|
|
1347
|
+
size of the returned result set. However, no individual row in
|
|
1348
|
+
the result set can exceed 100 MiB, and no column value can
|
|
1349
|
+
exceed 10 MiB.
|
|
1350
|
+
|
|
1351
|
+
.. code-block:: python
|
|
1352
|
+
|
|
1353
|
+
# This snippet has been automatically generated and should be regarded as a
|
|
1354
|
+
# code template only.
|
|
1355
|
+
# It will require modifications to work:
|
|
1356
|
+
# - It may require correct/in-range values for request initialization.
|
|
1357
|
+
# - It may require specifying regional endpoints when creating the service
|
|
1358
|
+
# client as shown in:
|
|
1359
|
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
|
1360
|
+
from google.cloud import spanner_v1
|
|
1361
|
+
|
|
1362
|
+
async def sample_streaming_read():
|
|
1363
|
+
# Create a client
|
|
1364
|
+
client = spanner_v1.SpannerAsyncClient()
|
|
1365
|
+
|
|
1366
|
+
# Initialize request argument(s)
|
|
1367
|
+
request = spanner_v1.ReadRequest(
|
|
1368
|
+
session="session_value",
|
|
1369
|
+
table="table_value",
|
|
1370
|
+
columns=['columns_value1', 'columns_value2'],
|
|
1371
|
+
)
|
|
1372
|
+
|
|
1373
|
+
# Make the request
|
|
1374
|
+
stream = await client.streaming_read(request=request)
|
|
1375
|
+
|
|
1376
|
+
# Handle the response
|
|
1377
|
+
async for response in stream:
|
|
1378
|
+
print(response)
|
|
1379
|
+
|
|
1380
|
+
Args:
|
|
1381
|
+
request (Optional[Union[google.cloud.spanner_v1.types.ReadRequest, dict]]):
|
|
1382
|
+
The request object. The request for [Read][google.spanner.v1.Spanner.Read]
|
|
1383
|
+
and
|
|
1384
|
+
[StreamingRead][google.spanner.v1.Spanner.StreamingRead].
|
|
1385
|
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
|
|
1386
|
+
should be retried.
|
|
1387
|
+
timeout (float): The timeout for this request.
|
|
1388
|
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
|
1389
|
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
|
1390
|
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
|
1391
|
+
be of type `bytes`.
|
|
1392
|
+
|
|
1393
|
+
Returns:
|
|
1394
|
+
AsyncIterable[google.cloud.spanner_v1.types.PartialResultSet]:
|
|
1395
|
+
Partial results from a streaming read
|
|
1396
|
+
or SQL query. Streaming reads and SQL
|
|
1397
|
+
queries better tolerate large result
|
|
1398
|
+
sets, large rows, and large values, but
|
|
1399
|
+
are a little trickier to consume.
|
|
1400
|
+
|
|
1401
|
+
"""
|
|
1402
|
+
# Create or coerce a protobuf request object.
|
|
1403
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
1404
|
+
# there are no flattened fields), or create one.
|
|
1405
|
+
if not isinstance(request, spanner.ReadRequest):
|
|
1406
|
+
request = spanner.ReadRequest(request)
|
|
1407
|
+
|
|
1408
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
1409
|
+
# and friendly error handling.
|
|
1410
|
+
rpc = self._client._transport._wrapped_methods[
|
|
1411
|
+
self._client._transport.streaming_read
|
|
1412
|
+
]
|
|
1413
|
+
|
|
1414
|
+
# Certain fields should be provided within the metadata header;
|
|
1415
|
+
# add these here.
|
|
1416
|
+
metadata = tuple(metadata) + (
|
|
1417
|
+
gapic_v1.routing_header.to_grpc_metadata((("session", request.session),)),
|
|
1418
|
+
)
|
|
1419
|
+
|
|
1420
|
+
# Validate the universe domain.
|
|
1421
|
+
self._client._validate_universe_domain()
|
|
1422
|
+
|
|
1423
|
+
# Send the request.
|
|
1424
|
+
response = rpc(
|
|
1425
|
+
request,
|
|
1426
|
+
retry=retry,
|
|
1427
|
+
timeout=timeout,
|
|
1428
|
+
metadata=metadata,
|
|
1429
|
+
)
|
|
1430
|
+
|
|
1431
|
+
# Done; return the response.
|
|
1432
|
+
return response
|
|
1433
|
+
|
|
1434
|
+
async def begin_transaction(
|
|
1435
|
+
self,
|
|
1436
|
+
request: Optional[Union[spanner.BeginTransactionRequest, dict]] = None,
|
|
1437
|
+
*,
|
|
1438
|
+
session: Optional[str] = None,
|
|
1439
|
+
options: Optional[transaction.TransactionOptions] = None,
|
|
1440
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
1441
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
1442
|
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
|
1443
|
+
) -> transaction.Transaction:
|
|
1444
|
+
r"""Begins a new transaction. This step can often be skipped:
|
|
1445
|
+
[Read][google.spanner.v1.Spanner.Read],
|
|
1446
|
+
[ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and
|
|
1447
|
+
[Commit][google.spanner.v1.Spanner.Commit] can begin a new
|
|
1448
|
+
transaction as a side-effect.
|
|
1449
|
+
|
|
1450
|
+
.. code-block:: python
|
|
1451
|
+
|
|
1452
|
+
# This snippet has been automatically generated and should be regarded as a
|
|
1453
|
+
# code template only.
|
|
1454
|
+
# It will require modifications to work:
|
|
1455
|
+
# - It may require correct/in-range values for request initialization.
|
|
1456
|
+
# - It may require specifying regional endpoints when creating the service
|
|
1457
|
+
# client as shown in:
|
|
1458
|
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
|
1459
|
+
from google.cloud import spanner_v1
|
|
1460
|
+
|
|
1461
|
+
async def sample_begin_transaction():
|
|
1462
|
+
# Create a client
|
|
1463
|
+
client = spanner_v1.SpannerAsyncClient()
|
|
1464
|
+
|
|
1465
|
+
# Initialize request argument(s)
|
|
1466
|
+
request = spanner_v1.BeginTransactionRequest(
|
|
1467
|
+
session="session_value",
|
|
1468
|
+
)
|
|
1469
|
+
|
|
1470
|
+
# Make the request
|
|
1471
|
+
response = await client.begin_transaction(request=request)
|
|
1472
|
+
|
|
1473
|
+
# Handle the response
|
|
1474
|
+
print(response)
|
|
1475
|
+
|
|
1476
|
+
Args:
|
|
1477
|
+
request (Optional[Union[google.cloud.spanner_v1.types.BeginTransactionRequest, dict]]):
|
|
1478
|
+
The request object. The request for
|
|
1479
|
+
[BeginTransaction][google.spanner.v1.Spanner.BeginTransaction].
|
|
1480
|
+
session (:class:`str`):
|
|
1481
|
+
Required. The session in which the
|
|
1482
|
+
transaction runs.
|
|
1483
|
+
|
|
1484
|
+
This corresponds to the ``session`` field
|
|
1485
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1486
|
+
should not be set.
|
|
1487
|
+
options (:class:`google.cloud.spanner_v1.types.TransactionOptions`):
|
|
1488
|
+
Required. Options for the new
|
|
1489
|
+
transaction.
|
|
1490
|
+
|
|
1491
|
+
This corresponds to the ``options`` field
|
|
1492
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1493
|
+
should not be set.
|
|
1494
|
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
|
|
1495
|
+
should be retried.
|
|
1496
|
+
timeout (float): The timeout for this request.
|
|
1497
|
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
|
1498
|
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
|
1499
|
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
|
1500
|
+
be of type `bytes`.
|
|
1501
|
+
|
|
1502
|
+
Returns:
|
|
1503
|
+
google.cloud.spanner_v1.types.Transaction:
|
|
1504
|
+
A transaction.
|
|
1505
|
+
"""
|
|
1506
|
+
# Create or coerce a protobuf request object.
|
|
1507
|
+
# - Quick check: If we got a request object, we should *not* have
|
|
1508
|
+
# gotten any keyword arguments that map to the request.
|
|
1509
|
+
flattened_params = [session, options]
|
|
1510
|
+
has_flattened_params = (
|
|
1511
|
+
len([param for param in flattened_params if param is not None]) > 0
|
|
1512
|
+
)
|
|
1513
|
+
if request is not None and has_flattened_params:
|
|
1514
|
+
raise ValueError(
|
|
1515
|
+
"If the `request` argument is set, then none of "
|
|
1516
|
+
"the individual field arguments should be set."
|
|
1517
|
+
)
|
|
1518
|
+
|
|
1519
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
1520
|
+
# there are no flattened fields), or create one.
|
|
1521
|
+
if not isinstance(request, spanner.BeginTransactionRequest):
|
|
1522
|
+
request = spanner.BeginTransactionRequest(request)
|
|
1523
|
+
|
|
1524
|
+
# If we have keyword arguments corresponding to fields on the
|
|
1525
|
+
# request, apply these.
|
|
1526
|
+
if session is not None:
|
|
1527
|
+
request.session = session
|
|
1528
|
+
if options is not None:
|
|
1529
|
+
request.options = options
|
|
1530
|
+
|
|
1531
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
1532
|
+
# and friendly error handling.
|
|
1533
|
+
rpc = self._client._transport._wrapped_methods[
|
|
1534
|
+
self._client._transport.begin_transaction
|
|
1535
|
+
]
|
|
1536
|
+
|
|
1537
|
+
# Certain fields should be provided within the metadata header;
|
|
1538
|
+
# add these here.
|
|
1539
|
+
metadata = tuple(metadata) + (
|
|
1540
|
+
gapic_v1.routing_header.to_grpc_metadata((("session", request.session),)),
|
|
1541
|
+
)
|
|
1542
|
+
|
|
1543
|
+
# Validate the universe domain.
|
|
1544
|
+
self._client._validate_universe_domain()
|
|
1545
|
+
|
|
1546
|
+
# Send the request.
|
|
1547
|
+
response = await rpc(
|
|
1548
|
+
request,
|
|
1549
|
+
retry=retry,
|
|
1550
|
+
timeout=timeout,
|
|
1551
|
+
metadata=metadata,
|
|
1552
|
+
)
|
|
1553
|
+
|
|
1554
|
+
# Done; return the response.
|
|
1555
|
+
return response
|
|
1556
|
+
|
|
1557
|
+
async def commit(
|
|
1558
|
+
self,
|
|
1559
|
+
request: Optional[Union[spanner.CommitRequest, dict]] = None,
|
|
1560
|
+
*,
|
|
1561
|
+
session: Optional[str] = None,
|
|
1562
|
+
transaction_id: Optional[bytes] = None,
|
|
1563
|
+
mutations: Optional[MutableSequence[mutation.Mutation]] = None,
|
|
1564
|
+
single_use_transaction: Optional[transaction.TransactionOptions] = None,
|
|
1565
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
1566
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
1567
|
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
|
1568
|
+
) -> commit_response.CommitResponse:
|
|
1569
|
+
r"""Commits a transaction. The request includes the mutations to be
|
|
1570
|
+
applied to rows in the database.
|
|
1571
|
+
|
|
1572
|
+
``Commit`` might return an ``ABORTED`` error. This can occur at
|
|
1573
|
+
any time; commonly, the cause is conflicts with concurrent
|
|
1574
|
+
transactions. However, it can also happen for a variety of other
|
|
1575
|
+
reasons. If ``Commit`` returns ``ABORTED``, the caller should
|
|
1576
|
+
re-attempt the transaction from the beginning, re-using the same
|
|
1577
|
+
session.
|
|
1578
|
+
|
|
1579
|
+
On very rare occasions, ``Commit`` might return ``UNKNOWN``.
|
|
1580
|
+
This can happen, for example, if the client job experiences a 1+
|
|
1581
|
+
hour networking failure. At that point, Cloud Spanner has lost
|
|
1582
|
+
track of the transaction outcome and we recommend that you
|
|
1583
|
+
perform another read from the database to see the state of
|
|
1584
|
+
things as they are now.
|
|
1585
|
+
|
|
1586
|
+
.. code-block:: python
|
|
1587
|
+
|
|
1588
|
+
# This snippet has been automatically generated and should be regarded as a
|
|
1589
|
+
# code template only.
|
|
1590
|
+
# It will require modifications to work:
|
|
1591
|
+
# - It may require correct/in-range values for request initialization.
|
|
1592
|
+
# - It may require specifying regional endpoints when creating the service
|
|
1593
|
+
# client as shown in:
|
|
1594
|
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
|
1595
|
+
from google.cloud import spanner_v1
|
|
1596
|
+
|
|
1597
|
+
async def sample_commit():
|
|
1598
|
+
# Create a client
|
|
1599
|
+
client = spanner_v1.SpannerAsyncClient()
|
|
1600
|
+
|
|
1601
|
+
# Initialize request argument(s)
|
|
1602
|
+
request = spanner_v1.CommitRequest(
|
|
1603
|
+
transaction_id=b'transaction_id_blob',
|
|
1604
|
+
session="session_value",
|
|
1605
|
+
)
|
|
1606
|
+
|
|
1607
|
+
# Make the request
|
|
1608
|
+
response = await client.commit(request=request)
|
|
1609
|
+
|
|
1610
|
+
# Handle the response
|
|
1611
|
+
print(response)
|
|
1612
|
+
|
|
1613
|
+
Args:
|
|
1614
|
+
request (Optional[Union[google.cloud.spanner_v1.types.CommitRequest, dict]]):
|
|
1615
|
+
The request object. The request for
|
|
1616
|
+
[Commit][google.spanner.v1.Spanner.Commit].
|
|
1617
|
+
session (:class:`str`):
|
|
1618
|
+
Required. The session in which the
|
|
1619
|
+
transaction to be committed is running.
|
|
1620
|
+
|
|
1621
|
+
This corresponds to the ``session`` field
|
|
1622
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1623
|
+
should not be set.
|
|
1624
|
+
transaction_id (:class:`bytes`):
|
|
1625
|
+
Commit a previously-started
|
|
1626
|
+
transaction.
|
|
1627
|
+
|
|
1628
|
+
This corresponds to the ``transaction_id`` field
|
|
1629
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1630
|
+
should not be set.
|
|
1631
|
+
mutations (:class:`MutableSequence[google.cloud.spanner_v1.types.Mutation]`):
|
|
1632
|
+
The mutations to be executed when
|
|
1633
|
+
this transaction commits. All mutations
|
|
1634
|
+
are applied atomically, in the order
|
|
1635
|
+
they appear in this list.
|
|
1636
|
+
|
|
1637
|
+
This corresponds to the ``mutations`` field
|
|
1638
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1639
|
+
should not be set.
|
|
1640
|
+
single_use_transaction (:class:`google.cloud.spanner_v1.types.TransactionOptions`):
|
|
1641
|
+
Execute mutations in a temporary transaction. Note that
|
|
1642
|
+
unlike commit of a previously-started transaction,
|
|
1643
|
+
commit with a temporary transaction is non-idempotent.
|
|
1644
|
+
That is, if the ``CommitRequest`` is sent to Cloud
|
|
1645
|
+
Spanner more than once (for instance, due to retries in
|
|
1646
|
+
the application, or in the transport library), it is
|
|
1647
|
+
possible that the mutations are executed more than once.
|
|
1648
|
+
If this is undesirable, use
|
|
1649
|
+
[BeginTransaction][google.spanner.v1.Spanner.BeginTransaction]
|
|
1650
|
+
and [Commit][google.spanner.v1.Spanner.Commit] instead.
|
|
1651
|
+
|
|
1652
|
+
This corresponds to the ``single_use_transaction`` field
|
|
1653
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1654
|
+
should not be set.
|
|
1655
|
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
|
|
1656
|
+
should be retried.
|
|
1657
|
+
timeout (float): The timeout for this request.
|
|
1658
|
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
|
1659
|
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
|
1660
|
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
|
1661
|
+
be of type `bytes`.
|
|
1662
|
+
|
|
1663
|
+
Returns:
|
|
1664
|
+
google.cloud.spanner_v1.types.CommitResponse:
|
|
1665
|
+
The response for
|
|
1666
|
+
[Commit][google.spanner.v1.Spanner.Commit].
|
|
1667
|
+
|
|
1668
|
+
"""
|
|
1669
|
+
# Create or coerce a protobuf request object.
|
|
1670
|
+
# - Quick check: If we got a request object, we should *not* have
|
|
1671
|
+
# gotten any keyword arguments that map to the request.
|
|
1672
|
+
flattened_params = [session, transaction_id, mutations, single_use_transaction]
|
|
1673
|
+
has_flattened_params = (
|
|
1674
|
+
len([param for param in flattened_params if param is not None]) > 0
|
|
1675
|
+
)
|
|
1676
|
+
if request is not None and has_flattened_params:
|
|
1677
|
+
raise ValueError(
|
|
1678
|
+
"If the `request` argument is set, then none of "
|
|
1679
|
+
"the individual field arguments should be set."
|
|
1680
|
+
)
|
|
1681
|
+
|
|
1682
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
1683
|
+
# there are no flattened fields), or create one.
|
|
1684
|
+
if not isinstance(request, spanner.CommitRequest):
|
|
1685
|
+
request = spanner.CommitRequest(request)
|
|
1686
|
+
|
|
1687
|
+
# If we have keyword arguments corresponding to fields on the
|
|
1688
|
+
# request, apply these.
|
|
1689
|
+
if session is not None:
|
|
1690
|
+
request.session = session
|
|
1691
|
+
if transaction_id is not None:
|
|
1692
|
+
request.transaction_id = transaction_id
|
|
1693
|
+
if single_use_transaction is not None:
|
|
1694
|
+
request.single_use_transaction = single_use_transaction
|
|
1695
|
+
if mutations:
|
|
1696
|
+
request.mutations.extend(mutations)
|
|
1697
|
+
|
|
1698
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
1699
|
+
# and friendly error handling.
|
|
1700
|
+
rpc = self._client._transport._wrapped_methods[self._client._transport.commit]
|
|
1701
|
+
|
|
1702
|
+
# Certain fields should be provided within the metadata header;
|
|
1703
|
+
# add these here.
|
|
1704
|
+
metadata = tuple(metadata) + (
|
|
1705
|
+
gapic_v1.routing_header.to_grpc_metadata((("session", request.session),)),
|
|
1706
|
+
)
|
|
1707
|
+
|
|
1708
|
+
# Validate the universe domain.
|
|
1709
|
+
self._client._validate_universe_domain()
|
|
1710
|
+
|
|
1711
|
+
# Send the request.
|
|
1712
|
+
response = await rpc(
|
|
1713
|
+
request,
|
|
1714
|
+
retry=retry,
|
|
1715
|
+
timeout=timeout,
|
|
1716
|
+
metadata=metadata,
|
|
1717
|
+
)
|
|
1718
|
+
|
|
1719
|
+
# Done; return the response.
|
|
1720
|
+
return response
|
|
1721
|
+
|
|
1722
|
+
async def rollback(
|
|
1723
|
+
self,
|
|
1724
|
+
request: Optional[Union[spanner.RollbackRequest, dict]] = None,
|
|
1725
|
+
*,
|
|
1726
|
+
session: Optional[str] = None,
|
|
1727
|
+
transaction_id: Optional[bytes] = None,
|
|
1728
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
1729
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
1730
|
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
|
1731
|
+
) -> None:
|
|
1732
|
+
r"""Rolls back a transaction, releasing any locks it holds. It is a
|
|
1733
|
+
good idea to call this for any transaction that includes one or
|
|
1734
|
+
more [Read][google.spanner.v1.Spanner.Read] or
|
|
1735
|
+
[ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] requests and
|
|
1736
|
+
ultimately decides not to commit.
|
|
1737
|
+
|
|
1738
|
+
``Rollback`` returns ``OK`` if it successfully aborts the
|
|
1739
|
+
transaction, the transaction was already aborted, or the
|
|
1740
|
+
transaction is not found. ``Rollback`` never returns
|
|
1741
|
+
``ABORTED``.
|
|
1742
|
+
|
|
1743
|
+
.. code-block:: python
|
|
1744
|
+
|
|
1745
|
+
# This snippet has been automatically generated and should be regarded as a
|
|
1746
|
+
# code template only.
|
|
1747
|
+
# It will require modifications to work:
|
|
1748
|
+
# - It may require correct/in-range values for request initialization.
|
|
1749
|
+
# - It may require specifying regional endpoints when creating the service
|
|
1750
|
+
# client as shown in:
|
|
1751
|
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
|
1752
|
+
from google.cloud import spanner_v1
|
|
1753
|
+
|
|
1754
|
+
async def sample_rollback():
|
|
1755
|
+
# Create a client
|
|
1756
|
+
client = spanner_v1.SpannerAsyncClient()
|
|
1757
|
+
|
|
1758
|
+
# Initialize request argument(s)
|
|
1759
|
+
request = spanner_v1.RollbackRequest(
|
|
1760
|
+
session="session_value",
|
|
1761
|
+
transaction_id=b'transaction_id_blob',
|
|
1762
|
+
)
|
|
1763
|
+
|
|
1764
|
+
# Make the request
|
|
1765
|
+
await client.rollback(request=request)
|
|
1766
|
+
|
|
1767
|
+
Args:
|
|
1768
|
+
request (Optional[Union[google.cloud.spanner_v1.types.RollbackRequest, dict]]):
|
|
1769
|
+
The request object. The request for
|
|
1770
|
+
[Rollback][google.spanner.v1.Spanner.Rollback].
|
|
1771
|
+
session (:class:`str`):
|
|
1772
|
+
Required. The session in which the
|
|
1773
|
+
transaction to roll back is running.
|
|
1774
|
+
|
|
1775
|
+
This corresponds to the ``session`` field
|
|
1776
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1777
|
+
should not be set.
|
|
1778
|
+
transaction_id (:class:`bytes`):
|
|
1779
|
+
Required. The transaction to roll
|
|
1780
|
+
back.
|
|
1781
|
+
|
|
1782
|
+
This corresponds to the ``transaction_id`` field
|
|
1783
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1784
|
+
should not be set.
|
|
1785
|
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
|
|
1786
|
+
should be retried.
|
|
1787
|
+
timeout (float): The timeout for this request.
|
|
1788
|
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
|
1789
|
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
|
1790
|
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
|
1791
|
+
be of type `bytes`.
|
|
1792
|
+
"""
|
|
1793
|
+
# Create or coerce a protobuf request object.
|
|
1794
|
+
# - Quick check: If we got a request object, we should *not* have
|
|
1795
|
+
# gotten any keyword arguments that map to the request.
|
|
1796
|
+
flattened_params = [session, transaction_id]
|
|
1797
|
+
has_flattened_params = (
|
|
1798
|
+
len([param for param in flattened_params if param is not None]) > 0
|
|
1799
|
+
)
|
|
1800
|
+
if request is not None and has_flattened_params:
|
|
1801
|
+
raise ValueError(
|
|
1802
|
+
"If the `request` argument is set, then none of "
|
|
1803
|
+
"the individual field arguments should be set."
|
|
1804
|
+
)
|
|
1805
|
+
|
|
1806
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
1807
|
+
# there are no flattened fields), or create one.
|
|
1808
|
+
if not isinstance(request, spanner.RollbackRequest):
|
|
1809
|
+
request = spanner.RollbackRequest(request)
|
|
1810
|
+
|
|
1811
|
+
# If we have keyword arguments corresponding to fields on the
|
|
1812
|
+
# request, apply these.
|
|
1813
|
+
if session is not None:
|
|
1814
|
+
request.session = session
|
|
1815
|
+
if transaction_id is not None:
|
|
1816
|
+
request.transaction_id = transaction_id
|
|
1817
|
+
|
|
1818
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
1819
|
+
# and friendly error handling.
|
|
1820
|
+
rpc = self._client._transport._wrapped_methods[self._client._transport.rollback]
|
|
1821
|
+
|
|
1822
|
+
# Certain fields should be provided within the metadata header;
|
|
1823
|
+
# add these here.
|
|
1824
|
+
metadata = tuple(metadata) + (
|
|
1825
|
+
gapic_v1.routing_header.to_grpc_metadata((("session", request.session),)),
|
|
1826
|
+
)
|
|
1827
|
+
|
|
1828
|
+
# Validate the universe domain.
|
|
1829
|
+
self._client._validate_universe_domain()
|
|
1830
|
+
|
|
1831
|
+
# Send the request.
|
|
1832
|
+
await rpc(
|
|
1833
|
+
request,
|
|
1834
|
+
retry=retry,
|
|
1835
|
+
timeout=timeout,
|
|
1836
|
+
metadata=metadata,
|
|
1837
|
+
)
|
|
1838
|
+
|
|
1839
|
+
async def partition_query(
|
|
1840
|
+
self,
|
|
1841
|
+
request: Optional[Union[spanner.PartitionQueryRequest, dict]] = None,
|
|
1842
|
+
*,
|
|
1843
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
1844
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
1845
|
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
|
1846
|
+
) -> spanner.PartitionResponse:
|
|
1847
|
+
r"""Creates a set of partition tokens that can be used to execute a
|
|
1848
|
+
query operation in parallel. Each of the returned partition
|
|
1849
|
+
tokens can be used by
|
|
1850
|
+
[ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql]
|
|
1851
|
+
to specify a subset of the query result to read. The same
|
|
1852
|
+
session and read-only transaction must be used by the
|
|
1853
|
+
PartitionQueryRequest used to create the partition tokens and
|
|
1854
|
+
the ExecuteSqlRequests that use the partition tokens.
|
|
1855
|
+
|
|
1856
|
+
Partition tokens become invalid when the session used to create
|
|
1857
|
+
them is deleted, is idle for too long, begins a new transaction,
|
|
1858
|
+
or becomes too old. When any of these happen, it is not possible
|
|
1859
|
+
to resume the query, and the whole operation must be restarted
|
|
1860
|
+
from the beginning.
|
|
1861
|
+
|
|
1862
|
+
.. code-block:: python
|
|
1863
|
+
|
|
1864
|
+
# This snippet has been automatically generated and should be regarded as a
|
|
1865
|
+
# code template only.
|
|
1866
|
+
# It will require modifications to work:
|
|
1867
|
+
# - It may require correct/in-range values for request initialization.
|
|
1868
|
+
# - It may require specifying regional endpoints when creating the service
|
|
1869
|
+
# client as shown in:
|
|
1870
|
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
|
1871
|
+
from google.cloud import spanner_v1
|
|
1872
|
+
|
|
1873
|
+
async def sample_partition_query():
|
|
1874
|
+
# Create a client
|
|
1875
|
+
client = spanner_v1.SpannerAsyncClient()
|
|
1876
|
+
|
|
1877
|
+
# Initialize request argument(s)
|
|
1878
|
+
request = spanner_v1.PartitionQueryRequest(
|
|
1879
|
+
session="session_value",
|
|
1880
|
+
sql="sql_value",
|
|
1881
|
+
)
|
|
1882
|
+
|
|
1883
|
+
# Make the request
|
|
1884
|
+
response = await client.partition_query(request=request)
|
|
1885
|
+
|
|
1886
|
+
# Handle the response
|
|
1887
|
+
print(response)
|
|
1888
|
+
|
|
1889
|
+
Args:
|
|
1890
|
+
request (Optional[Union[google.cloud.spanner_v1.types.PartitionQueryRequest, dict]]):
|
|
1891
|
+
The request object. The request for
|
|
1892
|
+
[PartitionQuery][google.spanner.v1.Spanner.PartitionQuery]
|
|
1893
|
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
|
|
1894
|
+
should be retried.
|
|
1895
|
+
timeout (float): The timeout for this request.
|
|
1896
|
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
|
1897
|
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
|
1898
|
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
|
1899
|
+
be of type `bytes`.
|
|
1900
|
+
|
|
1901
|
+
Returns:
|
|
1902
|
+
google.cloud.spanner_v1.types.PartitionResponse:
|
|
1903
|
+
The response for [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery]
|
|
1904
|
+
or
|
|
1905
|
+
[PartitionRead][google.spanner.v1.Spanner.PartitionRead]
|
|
1906
|
+
|
|
1907
|
+
"""
|
|
1908
|
+
# Create or coerce a protobuf request object.
|
|
1909
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
1910
|
+
# there are no flattened fields), or create one.
|
|
1911
|
+
if not isinstance(request, spanner.PartitionQueryRequest):
|
|
1912
|
+
request = spanner.PartitionQueryRequest(request)
|
|
1913
|
+
|
|
1914
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
1915
|
+
# and friendly error handling.
|
|
1916
|
+
rpc = self._client._transport._wrapped_methods[
|
|
1917
|
+
self._client._transport.partition_query
|
|
1918
|
+
]
|
|
1919
|
+
|
|
1920
|
+
# Certain fields should be provided within the metadata header;
|
|
1921
|
+
# add these here.
|
|
1922
|
+
metadata = tuple(metadata) + (
|
|
1923
|
+
gapic_v1.routing_header.to_grpc_metadata((("session", request.session),)),
|
|
1924
|
+
)
|
|
1925
|
+
|
|
1926
|
+
# Validate the universe domain.
|
|
1927
|
+
self._client._validate_universe_domain()
|
|
1928
|
+
|
|
1929
|
+
# Send the request.
|
|
1930
|
+
response = await rpc(
|
|
1931
|
+
request,
|
|
1932
|
+
retry=retry,
|
|
1933
|
+
timeout=timeout,
|
|
1934
|
+
metadata=metadata,
|
|
1935
|
+
)
|
|
1936
|
+
|
|
1937
|
+
# Done; return the response.
|
|
1938
|
+
return response
|
|
1939
|
+
|
|
1940
|
+
async def partition_read(
|
|
1941
|
+
self,
|
|
1942
|
+
request: Optional[Union[spanner.PartitionReadRequest, dict]] = None,
|
|
1943
|
+
*,
|
|
1944
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
1945
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
1946
|
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
|
1947
|
+
) -> spanner.PartitionResponse:
|
|
1948
|
+
r"""Creates a set of partition tokens that can be used to execute a
|
|
1949
|
+
read operation in parallel. Each of the returned partition
|
|
1950
|
+
tokens can be used by
|
|
1951
|
+
[StreamingRead][google.spanner.v1.Spanner.StreamingRead] to
|
|
1952
|
+
specify a subset of the read result to read. The same session
|
|
1953
|
+
and read-only transaction must be used by the
|
|
1954
|
+
PartitionReadRequest used to create the partition tokens and the
|
|
1955
|
+
ReadRequests that use the partition tokens. There are no
|
|
1956
|
+
ordering guarantees on rows returned among the returned
|
|
1957
|
+
partition tokens, or even within each individual StreamingRead
|
|
1958
|
+
call issued with a partition_token.
|
|
1959
|
+
|
|
1960
|
+
Partition tokens become invalid when the session used to create
|
|
1961
|
+
them is deleted, is idle for too long, begins a new transaction,
|
|
1962
|
+
or becomes too old. When any of these happen, it is not possible
|
|
1963
|
+
to resume the read, and the whole operation must be restarted
|
|
1964
|
+
from the beginning.
|
|
1965
|
+
|
|
1966
|
+
.. code-block:: python
|
|
1967
|
+
|
|
1968
|
+
# This snippet has been automatically generated and should be regarded as a
|
|
1969
|
+
# code template only.
|
|
1970
|
+
# It will require modifications to work:
|
|
1971
|
+
# - It may require correct/in-range values for request initialization.
|
|
1972
|
+
# - It may require specifying regional endpoints when creating the service
|
|
1973
|
+
# client as shown in:
|
|
1974
|
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
|
1975
|
+
from google.cloud import spanner_v1
|
|
1976
|
+
|
|
1977
|
+
async def sample_partition_read():
|
|
1978
|
+
# Create a client
|
|
1979
|
+
client = spanner_v1.SpannerAsyncClient()
|
|
1980
|
+
|
|
1981
|
+
# Initialize request argument(s)
|
|
1982
|
+
request = spanner_v1.PartitionReadRequest(
|
|
1983
|
+
session="session_value",
|
|
1984
|
+
table="table_value",
|
|
1985
|
+
)
|
|
1986
|
+
|
|
1987
|
+
# Make the request
|
|
1988
|
+
response = await client.partition_read(request=request)
|
|
1989
|
+
|
|
1990
|
+
# Handle the response
|
|
1991
|
+
print(response)
|
|
1992
|
+
|
|
1993
|
+
Args:
|
|
1994
|
+
request (Optional[Union[google.cloud.spanner_v1.types.PartitionReadRequest, dict]]):
|
|
1995
|
+
The request object. The request for
|
|
1996
|
+
[PartitionRead][google.spanner.v1.Spanner.PartitionRead]
|
|
1997
|
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
|
|
1998
|
+
should be retried.
|
|
1999
|
+
timeout (float): The timeout for this request.
|
|
2000
|
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
|
2001
|
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
|
2002
|
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
|
2003
|
+
be of type `bytes`.
|
|
2004
|
+
|
|
2005
|
+
Returns:
|
|
2006
|
+
google.cloud.spanner_v1.types.PartitionResponse:
|
|
2007
|
+
The response for [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery]
|
|
2008
|
+
or
|
|
2009
|
+
[PartitionRead][google.spanner.v1.Spanner.PartitionRead]
|
|
2010
|
+
|
|
2011
|
+
"""
|
|
2012
|
+
# Create or coerce a protobuf request object.
|
|
2013
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
2014
|
+
# there are no flattened fields), or create one.
|
|
2015
|
+
if not isinstance(request, spanner.PartitionReadRequest):
|
|
2016
|
+
request = spanner.PartitionReadRequest(request)
|
|
2017
|
+
|
|
2018
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
2019
|
+
# and friendly error handling.
|
|
2020
|
+
rpc = self._client._transport._wrapped_methods[
|
|
2021
|
+
self._client._transport.partition_read
|
|
2022
|
+
]
|
|
2023
|
+
|
|
2024
|
+
# Certain fields should be provided within the metadata header;
|
|
2025
|
+
# add these here.
|
|
2026
|
+
metadata = tuple(metadata) + (
|
|
2027
|
+
gapic_v1.routing_header.to_grpc_metadata((("session", request.session),)),
|
|
2028
|
+
)
|
|
2029
|
+
|
|
2030
|
+
# Validate the universe domain.
|
|
2031
|
+
self._client._validate_universe_domain()
|
|
2032
|
+
|
|
2033
|
+
# Send the request.
|
|
2034
|
+
response = await rpc(
|
|
2035
|
+
request,
|
|
2036
|
+
retry=retry,
|
|
2037
|
+
timeout=timeout,
|
|
2038
|
+
metadata=metadata,
|
|
2039
|
+
)
|
|
2040
|
+
|
|
2041
|
+
# Done; return the response.
|
|
2042
|
+
return response
|
|
2043
|
+
|
|
2044
|
+
def batch_write(
|
|
2045
|
+
self,
|
|
2046
|
+
request: Optional[Union[spanner.BatchWriteRequest, dict]] = None,
|
|
2047
|
+
*,
|
|
2048
|
+
session: Optional[str] = None,
|
|
2049
|
+
mutation_groups: Optional[
|
|
2050
|
+
MutableSequence[spanner.BatchWriteRequest.MutationGroup]
|
|
2051
|
+
] = None,
|
|
2052
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
2053
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
2054
|
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
|
2055
|
+
) -> Awaitable[AsyncIterable[spanner.BatchWriteResponse]]:
|
|
2056
|
+
r"""Batches the supplied mutation groups in a collection
|
|
2057
|
+
of efficient transactions. All mutations in a group are
|
|
2058
|
+
committed atomically. However, mutations across groups
|
|
2059
|
+
can be committed non-atomically in an unspecified order
|
|
2060
|
+
and thus, they must be independent of each other.
|
|
2061
|
+
Partial failure is possible, i.e., some groups may have
|
|
2062
|
+
been committed successfully, while some may have failed.
|
|
2063
|
+
The results of individual batches are streamed into the
|
|
2064
|
+
response as the batches are applied.
|
|
2065
|
+
|
|
2066
|
+
BatchWrite requests are not replay protected, meaning
|
|
2067
|
+
that each mutation group may be applied more than once.
|
|
2068
|
+
Replays of non-idempotent mutations may have undesirable
|
|
2069
|
+
effects. For example, replays of an insert mutation may
|
|
2070
|
+
produce an already exists error or if you use generated
|
|
2071
|
+
or commit timestamp-based keys, it may result in
|
|
2072
|
+
additional rows being added to the mutation's table. We
|
|
2073
|
+
recommend structuring your mutation groups to be
|
|
2074
|
+
idempotent to avoid this issue.
|
|
2075
|
+
|
|
2076
|
+
.. code-block:: python
|
|
2077
|
+
|
|
2078
|
+
# This snippet has been automatically generated and should be regarded as a
|
|
2079
|
+
# code template only.
|
|
2080
|
+
# It will require modifications to work:
|
|
2081
|
+
# - It may require correct/in-range values for request initialization.
|
|
2082
|
+
# - It may require specifying regional endpoints when creating the service
|
|
2083
|
+
# client as shown in:
|
|
2084
|
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
|
2085
|
+
from google.cloud import spanner_v1
|
|
2086
|
+
|
|
2087
|
+
async def sample_batch_write():
|
|
2088
|
+
# Create a client
|
|
2089
|
+
client = spanner_v1.SpannerAsyncClient()
|
|
2090
|
+
|
|
2091
|
+
# Initialize request argument(s)
|
|
2092
|
+
mutation_groups = spanner_v1.MutationGroup()
|
|
2093
|
+
mutation_groups.mutations.insert.table = "table_value"
|
|
2094
|
+
|
|
2095
|
+
request = spanner_v1.BatchWriteRequest(
|
|
2096
|
+
session="session_value",
|
|
2097
|
+
mutation_groups=mutation_groups,
|
|
2098
|
+
)
|
|
2099
|
+
|
|
2100
|
+
# Make the request
|
|
2101
|
+
stream = await client.batch_write(request=request)
|
|
2102
|
+
|
|
2103
|
+
# Handle the response
|
|
2104
|
+
async for response in stream:
|
|
2105
|
+
print(response)
|
|
2106
|
+
|
|
2107
|
+
Args:
|
|
2108
|
+
request (Optional[Union[google.cloud.spanner_v1.types.BatchWriteRequest, dict]]):
|
|
2109
|
+
The request object. The request for
|
|
2110
|
+
[BatchWrite][google.spanner.v1.Spanner.BatchWrite].
|
|
2111
|
+
session (:class:`str`):
|
|
2112
|
+
Required. The session in which the
|
|
2113
|
+
batch request is to be run.
|
|
2114
|
+
|
|
2115
|
+
This corresponds to the ``session`` field
|
|
2116
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
2117
|
+
should not be set.
|
|
2118
|
+
mutation_groups (:class:`MutableSequence[google.cloud.spanner_v1.types.BatchWriteRequest.MutationGroup]`):
|
|
2119
|
+
Required. The groups of mutations to
|
|
2120
|
+
be applied.
|
|
2121
|
+
|
|
2122
|
+
This corresponds to the ``mutation_groups`` field
|
|
2123
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
2124
|
+
should not be set.
|
|
2125
|
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
|
|
2126
|
+
should be retried.
|
|
2127
|
+
timeout (float): The timeout for this request.
|
|
2128
|
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
|
2129
|
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
|
2130
|
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
|
2131
|
+
be of type `bytes`.
|
|
2132
|
+
|
|
2133
|
+
Returns:
|
|
2134
|
+
AsyncIterable[google.cloud.spanner_v1.types.BatchWriteResponse]:
|
|
2135
|
+
The result of applying a batch of
|
|
2136
|
+
mutations.
|
|
2137
|
+
|
|
2138
|
+
"""
|
|
2139
|
+
# Create or coerce a protobuf request object.
|
|
2140
|
+
# - Quick check: If we got a request object, we should *not* have
|
|
2141
|
+
# gotten any keyword arguments that map to the request.
|
|
2142
|
+
flattened_params = [session, mutation_groups]
|
|
2143
|
+
has_flattened_params = (
|
|
2144
|
+
len([param for param in flattened_params if param is not None]) > 0
|
|
2145
|
+
)
|
|
2146
|
+
if request is not None and has_flattened_params:
|
|
2147
|
+
raise ValueError(
|
|
2148
|
+
"If the `request` argument is set, then none of "
|
|
2149
|
+
"the individual field arguments should be set."
|
|
2150
|
+
)
|
|
2151
|
+
|
|
2152
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
2153
|
+
# there are no flattened fields), or create one.
|
|
2154
|
+
if not isinstance(request, spanner.BatchWriteRequest):
|
|
2155
|
+
request = spanner.BatchWriteRequest(request)
|
|
2156
|
+
|
|
2157
|
+
# If we have keyword arguments corresponding to fields on the
|
|
2158
|
+
# request, apply these.
|
|
2159
|
+
if session is not None:
|
|
2160
|
+
request.session = session
|
|
2161
|
+
if mutation_groups:
|
|
2162
|
+
request.mutation_groups.extend(mutation_groups)
|
|
2163
|
+
|
|
2164
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
2165
|
+
# and friendly error handling.
|
|
2166
|
+
rpc = self._client._transport._wrapped_methods[
|
|
2167
|
+
self._client._transport.batch_write
|
|
2168
|
+
]
|
|
2169
|
+
|
|
2170
|
+
# Certain fields should be provided within the metadata header;
|
|
2171
|
+
# add these here.
|
|
2172
|
+
metadata = tuple(metadata) + (
|
|
2173
|
+
gapic_v1.routing_header.to_grpc_metadata((("session", request.session),)),
|
|
2174
|
+
)
|
|
2175
|
+
|
|
2176
|
+
# Validate the universe domain.
|
|
2177
|
+
self._client._validate_universe_domain()
|
|
2178
|
+
|
|
2179
|
+
# Send the request.
|
|
2180
|
+
response = rpc(
|
|
2181
|
+
request,
|
|
2182
|
+
retry=retry,
|
|
2183
|
+
timeout=timeout,
|
|
2184
|
+
metadata=metadata,
|
|
2185
|
+
)
|
|
2186
|
+
|
|
2187
|
+
# Done; return the response.
|
|
2188
|
+
return response
|
|
2189
|
+
|
|
2190
|
+
async def __aenter__(self) -> "SpannerAsyncClient":
|
|
2191
|
+
return self
|
|
2192
|
+
|
|
2193
|
+
async def __aexit__(self, exc_type, exc, tb):
|
|
2194
|
+
await self.transport.close()
|
|
2195
|
+
|
|
2196
|
+
|
|
2197
|
+
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
|
|
2198
|
+
gapic_version=package_version.__version__
|
|
2199
|
+
)
|
|
2200
|
+
|
|
2201
|
+
if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER
|
|
2202
|
+
DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__
|
|
2203
|
+
|
|
2204
|
+
|
|
2205
|
+
__all__ = ("SpannerAsyncClient",)
|