google-cloud-bigtable 2.30.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/bigtable/__init__.py +25 -0
- google/cloud/bigtable/app_profile.py +377 -0
- google/cloud/bigtable/backup.py +490 -0
- google/cloud/bigtable/batcher.py +414 -0
- google/cloud/bigtable/client.py +475 -0
- google/cloud/bigtable/cluster.py +541 -0
- google/cloud/bigtable/column_family.py +362 -0
- google/cloud/bigtable/data/__init__.py +103 -0
- google/cloud/bigtable/data/_async/__init__.py +25 -0
- google/cloud/bigtable/data/_async/_mutate_rows.py +226 -0
- google/cloud/bigtable/data/_async/_read_rows.py +363 -0
- google/cloud/bigtable/data/_async/client.py +1522 -0
- google/cloud/bigtable/data/_async/mutations_batcher.py +534 -0
- google/cloud/bigtable/data/_cross_sync/__init__.py +20 -0
- google/cloud/bigtable/data/_cross_sync/_decorators.py +441 -0
- google/cloud/bigtable/data/_cross_sync/_mapping_meta.py +64 -0
- google/cloud/bigtable/data/_cross_sync/cross_sync.py +334 -0
- google/cloud/bigtable/data/_helpers.py +249 -0
- google/cloud/bigtable/data/_sync_autogen/_mutate_rows.py +182 -0
- google/cloud/bigtable/data/_sync_autogen/_read_rows.py +304 -0
- google/cloud/bigtable/data/_sync_autogen/client.py +1293 -0
- google/cloud/bigtable/data/_sync_autogen/mutations_batcher.py +449 -0
- google/cloud/bigtable/data/exceptions.py +340 -0
- google/cloud/bigtable/data/execute_query/__init__.py +43 -0
- google/cloud/bigtable/data/execute_query/_async/__init__.py +13 -0
- google/cloud/bigtable/data/execute_query/_async/execute_query_iterator.py +291 -0
- google/cloud/bigtable/data/execute_query/_byte_cursor.py +123 -0
- google/cloud/bigtable/data/execute_query/_checksum.py +43 -0
- google/cloud/bigtable/data/execute_query/_parameters_formatting.py +155 -0
- google/cloud/bigtable/data/execute_query/_query_result_parsing_utils.py +134 -0
- google/cloud/bigtable/data/execute_query/_reader.py +122 -0
- google/cloud/bigtable/data/execute_query/_sync_autogen/execute_query_iterator.py +239 -0
- google/cloud/bigtable/data/execute_query/metadata.py +399 -0
- google/cloud/bigtable/data/execute_query/values.py +123 -0
- google/cloud/bigtable/data/mutations.py +380 -0
- google/cloud/bigtable/data/read_modify_write_rules.py +112 -0
- google/cloud/bigtable/data/read_rows_query.py +536 -0
- google/cloud/bigtable/data/row.py +535 -0
- google/cloud/bigtable/data/row_filters.py +968 -0
- google/cloud/bigtable/encryption_info.py +64 -0
- google/cloud/bigtable/enums.py +223 -0
- google/cloud/bigtable/error.py +64 -0
- google/cloud/bigtable/gapic_version.py +16 -0
- google/cloud/bigtable/helpers.py +31 -0
- google/cloud/bigtable/instance.py +789 -0
- google/cloud/bigtable/policy.py +255 -0
- google/cloud/bigtable/row.py +1267 -0
- google/cloud/bigtable/row_data.py +380 -0
- google/cloud/bigtable/row_filters.py +838 -0
- google/cloud/bigtable/row_merger.py +250 -0
- google/cloud/bigtable/row_set.py +213 -0
- google/cloud/bigtable/table.py +1409 -0
- google/cloud/bigtable_admin/__init__.py +410 -0
- google/cloud/bigtable_admin/gapic_version.py +16 -0
- google/cloud/bigtable_admin/py.typed +2 -0
- google/cloud/bigtable_admin_v2/__init__.py +250 -0
- google/cloud/bigtable_admin_v2/gapic_metadata.json +962 -0
- google/cloud/bigtable_admin_v2/gapic_version.py +16 -0
- google/cloud/bigtable_admin_v2/py.typed +2 -0
- google/cloud/bigtable_admin_v2/services/__init__.py +15 -0
- google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/__init__.py +22 -0
- google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/async_client.py +3465 -0
- google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/client.py +3944 -0
- google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/pagers.py +681 -0
- google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/__init__.py +40 -0
- google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/base.py +751 -0
- google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/grpc.py +1249 -0
- google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/grpc_asyncio.py +1579 -0
- google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/rest.py +6820 -0
- google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/rest_base.py +1746 -0
- google/cloud/bigtable_admin_v2/services/bigtable_table_admin/__init__.py +22 -0
- google/cloud/bigtable_admin_v2/services/bigtable_table_admin/async_client.py +3472 -0
- google/cloud/bigtable_admin_v2/services/bigtable_table_admin/client.py +3949 -0
- google/cloud/bigtable_admin_v2/services/bigtable_table_admin/pagers.py +669 -0
- google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/__init__.py +40 -0
- google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/base.py +708 -0
- google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/grpc.py +1257 -0
- google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/grpc_asyncio.py +1549 -0
- google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/rest.py +6609 -0
- google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/rest_base.py +1714 -0
- google/cloud/bigtable_admin_v2/types/__init__.py +248 -0
- google/cloud/bigtable_admin_v2/types/bigtable_instance_admin.py +1364 -0
- google/cloud/bigtable_admin_v2/types/bigtable_table_admin.py +1715 -0
- google/cloud/bigtable_admin_v2/types/common.py +81 -0
- google/cloud/bigtable_admin_v2/types/instance.py +819 -0
- google/cloud/bigtable_admin_v2/types/table.py +1028 -0
- google/cloud/bigtable_admin_v2/types/types.py +776 -0
- google/cloud/bigtable_v2/__init__.py +136 -0
- google/cloud/bigtable_v2/gapic_metadata.json +193 -0
- google/cloud/bigtable_v2/gapic_version.py +16 -0
- google/cloud/bigtable_v2/py.typed +2 -0
- google/cloud/bigtable_v2/services/__init__.py +15 -0
- google/cloud/bigtable_v2/services/bigtable/__init__.py +22 -0
- google/cloud/bigtable_v2/services/bigtable/async_client.py +1741 -0
- google/cloud/bigtable_v2/services/bigtable/client.py +2194 -0
- google/cloud/bigtable_v2/services/bigtable/transports/__init__.py +38 -0
- google/cloud/bigtable_v2/services/bigtable/transports/base.py +343 -0
- google/cloud/bigtable_v2/services/bigtable/transports/grpc.py +660 -0
- google/cloud/bigtable_v2/services/bigtable/transports/grpc_asyncio.py +762 -0
- google/cloud/bigtable_v2/services/bigtable/transports/rest.py +2489 -0
- google/cloud/bigtable_v2/services/bigtable/transports/rest_base.py +711 -0
- google/cloud/bigtable_v2/types/__init__.py +138 -0
- google/cloud/bigtable_v2/types/bigtable.py +1531 -0
- google/cloud/bigtable_v2/types/data.py +1612 -0
- google/cloud/bigtable_v2/types/feature_flags.py +119 -0
- google/cloud/bigtable_v2/types/request_stats.py +171 -0
- google/cloud/bigtable_v2/types/response_params.py +64 -0
- google/cloud/bigtable_v2/types/types.py +579 -0
- google_cloud_bigtable-2.30.0.data/scripts/fixup_bigtable_admin_v2_keywords.py +233 -0
- google_cloud_bigtable-2.30.0.data/scripts/fixup_bigtable_v2_keywords.py +186 -0
- google_cloud_bigtable-2.30.0.dist-info/LICENSE +202 -0
- google_cloud_bigtable-2.30.0.dist-info/METADATA +154 -0
- google_cloud_bigtable-2.30.0.dist-info/RECORD +115 -0
- google_cloud_bigtable-2.30.0.dist-info/WHEEL +5 -0
- google_cloud_bigtable-2.30.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,2194 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Copyright 2024 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
|
+
from collections import OrderedDict
|
|
17
|
+
from http import HTTPStatus
|
|
18
|
+
import json
|
|
19
|
+
import logging as std_logging
|
|
20
|
+
import os
|
|
21
|
+
import re
|
|
22
|
+
from typing import (
|
|
23
|
+
Dict,
|
|
24
|
+
Callable,
|
|
25
|
+
Mapping,
|
|
26
|
+
MutableMapping,
|
|
27
|
+
MutableSequence,
|
|
28
|
+
Optional,
|
|
29
|
+
Iterable,
|
|
30
|
+
Sequence,
|
|
31
|
+
Tuple,
|
|
32
|
+
Type,
|
|
33
|
+
Union,
|
|
34
|
+
cast,
|
|
35
|
+
)
|
|
36
|
+
import warnings
|
|
37
|
+
|
|
38
|
+
from google.cloud.bigtable_v2 import gapic_version as package_version
|
|
39
|
+
|
|
40
|
+
from google.api_core import client_options as client_options_lib
|
|
41
|
+
from google.api_core import exceptions as core_exceptions
|
|
42
|
+
from google.api_core import gapic_v1
|
|
43
|
+
from google.api_core import retry as retries
|
|
44
|
+
from google.auth import credentials as ga_credentials # type: ignore
|
|
45
|
+
from google.auth.transport import mtls # type: ignore
|
|
46
|
+
from google.auth.transport.grpc import SslCredentials # type: ignore
|
|
47
|
+
from google.auth.exceptions import MutualTLSChannelError # type: ignore
|
|
48
|
+
from google.oauth2 import service_account # type: ignore
|
|
49
|
+
|
|
50
|
+
try:
|
|
51
|
+
OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]
|
|
52
|
+
except AttributeError: # pragma: NO COVER
|
|
53
|
+
OptionalRetry = Union[retries.Retry, object, None] # type: ignore
|
|
54
|
+
|
|
55
|
+
try:
|
|
56
|
+
from google.api_core import client_logging # type: ignore
|
|
57
|
+
|
|
58
|
+
CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
|
|
59
|
+
except ImportError: # pragma: NO COVER
|
|
60
|
+
CLIENT_LOGGING_SUPPORTED = False
|
|
61
|
+
|
|
62
|
+
_LOGGER = std_logging.getLogger(__name__)
|
|
63
|
+
|
|
64
|
+
from google.cloud.bigtable_v2.types import bigtable
|
|
65
|
+
from google.cloud.bigtable_v2.types import data
|
|
66
|
+
from google.cloud.bigtable_v2.types import request_stats
|
|
67
|
+
from google.protobuf import timestamp_pb2 # type: ignore
|
|
68
|
+
from .transports.base import BigtableTransport, DEFAULT_CLIENT_INFO
|
|
69
|
+
from .transports.grpc import BigtableGrpcTransport
|
|
70
|
+
from .transports.grpc_asyncio import BigtableGrpcAsyncIOTransport
|
|
71
|
+
from .transports.rest import BigtableRestTransport
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class BigtableClientMeta(type):
|
|
75
|
+
"""Metaclass for the Bigtable client.
|
|
76
|
+
|
|
77
|
+
This provides class-level methods for building and retrieving
|
|
78
|
+
support objects (e.g. transport) without polluting the client instance
|
|
79
|
+
objects.
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
_transport_registry = OrderedDict() # type: Dict[str, Type[BigtableTransport]]
|
|
83
|
+
_transport_registry["grpc"] = BigtableGrpcTransport
|
|
84
|
+
_transport_registry["grpc_asyncio"] = BigtableGrpcAsyncIOTransport
|
|
85
|
+
_transport_registry["rest"] = BigtableRestTransport
|
|
86
|
+
|
|
87
|
+
def get_transport_class(
|
|
88
|
+
cls,
|
|
89
|
+
label: Optional[str] = None,
|
|
90
|
+
) -> Type[BigtableTransport]:
|
|
91
|
+
"""Returns an appropriate transport class.
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
label: The name of the desired transport. If none is
|
|
95
|
+
provided, then the first transport in the registry is used.
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
The transport class to use.
|
|
99
|
+
"""
|
|
100
|
+
# If a specific transport is requested, return that one.
|
|
101
|
+
if label:
|
|
102
|
+
return cls._transport_registry[label]
|
|
103
|
+
|
|
104
|
+
# No transport is requested; return the default (that is, the first one
|
|
105
|
+
# in the dictionary).
|
|
106
|
+
return next(iter(cls._transport_registry.values()))
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class BigtableClient(metaclass=BigtableClientMeta):
|
|
110
|
+
"""Service for reading from and writing to existing Bigtable
|
|
111
|
+
tables.
|
|
112
|
+
"""
|
|
113
|
+
|
|
114
|
+
@staticmethod
|
|
115
|
+
def _get_default_mtls_endpoint(api_endpoint):
|
|
116
|
+
"""Converts api endpoint to mTLS endpoint.
|
|
117
|
+
|
|
118
|
+
Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to
|
|
119
|
+
"*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively.
|
|
120
|
+
Args:
|
|
121
|
+
api_endpoint (Optional[str]): the api endpoint to convert.
|
|
122
|
+
Returns:
|
|
123
|
+
str: converted mTLS api endpoint.
|
|
124
|
+
"""
|
|
125
|
+
if not api_endpoint:
|
|
126
|
+
return api_endpoint
|
|
127
|
+
|
|
128
|
+
mtls_endpoint_re = re.compile(
|
|
129
|
+
r"(?P<name>[^.]+)(?P<mtls>\.mtls)?(?P<sandbox>\.sandbox)?(?P<googledomain>\.googleapis\.com)?"
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
m = mtls_endpoint_re.match(api_endpoint)
|
|
133
|
+
name, mtls, sandbox, googledomain = m.groups()
|
|
134
|
+
if mtls or not googledomain:
|
|
135
|
+
return api_endpoint
|
|
136
|
+
|
|
137
|
+
if sandbox:
|
|
138
|
+
return api_endpoint.replace(
|
|
139
|
+
"sandbox.googleapis.com", "mtls.sandbox.googleapis.com"
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com")
|
|
143
|
+
|
|
144
|
+
# Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead.
|
|
145
|
+
DEFAULT_ENDPOINT = "bigtable.googleapis.com"
|
|
146
|
+
DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore
|
|
147
|
+
DEFAULT_ENDPOINT
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
_DEFAULT_ENDPOINT_TEMPLATE = "bigtable.{UNIVERSE_DOMAIN}"
|
|
151
|
+
_DEFAULT_UNIVERSE = "googleapis.com"
|
|
152
|
+
|
|
153
|
+
@classmethod
|
|
154
|
+
def from_service_account_info(cls, info: dict, *args, **kwargs):
|
|
155
|
+
"""Creates an instance of this client using the provided credentials
|
|
156
|
+
info.
|
|
157
|
+
|
|
158
|
+
Args:
|
|
159
|
+
info (dict): The service account private key info.
|
|
160
|
+
args: Additional arguments to pass to the constructor.
|
|
161
|
+
kwargs: Additional arguments to pass to the constructor.
|
|
162
|
+
|
|
163
|
+
Returns:
|
|
164
|
+
BigtableClient: The constructed client.
|
|
165
|
+
"""
|
|
166
|
+
credentials = service_account.Credentials.from_service_account_info(info)
|
|
167
|
+
kwargs["credentials"] = credentials
|
|
168
|
+
return cls(*args, **kwargs)
|
|
169
|
+
|
|
170
|
+
@classmethod
|
|
171
|
+
def from_service_account_file(cls, filename: str, *args, **kwargs):
|
|
172
|
+
"""Creates an instance of this client using the provided credentials
|
|
173
|
+
file.
|
|
174
|
+
|
|
175
|
+
Args:
|
|
176
|
+
filename (str): The path to the service account private key json
|
|
177
|
+
file.
|
|
178
|
+
args: Additional arguments to pass to the constructor.
|
|
179
|
+
kwargs: Additional arguments to pass to the constructor.
|
|
180
|
+
|
|
181
|
+
Returns:
|
|
182
|
+
BigtableClient: The constructed client.
|
|
183
|
+
"""
|
|
184
|
+
credentials = service_account.Credentials.from_service_account_file(filename)
|
|
185
|
+
kwargs["credentials"] = credentials
|
|
186
|
+
return cls(*args, **kwargs)
|
|
187
|
+
|
|
188
|
+
from_service_account_json = from_service_account_file
|
|
189
|
+
|
|
190
|
+
@property
|
|
191
|
+
def transport(self) -> BigtableTransport:
|
|
192
|
+
"""Returns the transport used by the client instance.
|
|
193
|
+
|
|
194
|
+
Returns:
|
|
195
|
+
BigtableTransport: The transport used by the client
|
|
196
|
+
instance.
|
|
197
|
+
"""
|
|
198
|
+
return self._transport
|
|
199
|
+
|
|
200
|
+
@staticmethod
|
|
201
|
+
def authorized_view_path(
|
|
202
|
+
project: str,
|
|
203
|
+
instance: str,
|
|
204
|
+
table: str,
|
|
205
|
+
authorized_view: str,
|
|
206
|
+
) -> str:
|
|
207
|
+
"""Returns a fully-qualified authorized_view string."""
|
|
208
|
+
return "projects/{project}/instances/{instance}/tables/{table}/authorizedViews/{authorized_view}".format(
|
|
209
|
+
project=project,
|
|
210
|
+
instance=instance,
|
|
211
|
+
table=table,
|
|
212
|
+
authorized_view=authorized_view,
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
@staticmethod
|
|
216
|
+
def parse_authorized_view_path(path: str) -> Dict[str, str]:
|
|
217
|
+
"""Parses a authorized_view path into its component segments."""
|
|
218
|
+
m = re.match(
|
|
219
|
+
r"^projects/(?P<project>.+?)/instances/(?P<instance>.+?)/tables/(?P<table>.+?)/authorizedViews/(?P<authorized_view>.+?)$",
|
|
220
|
+
path,
|
|
221
|
+
)
|
|
222
|
+
return m.groupdict() if m else {}
|
|
223
|
+
|
|
224
|
+
@staticmethod
|
|
225
|
+
def instance_path(
|
|
226
|
+
project: str,
|
|
227
|
+
instance: str,
|
|
228
|
+
) -> str:
|
|
229
|
+
"""Returns a fully-qualified instance string."""
|
|
230
|
+
return "projects/{project}/instances/{instance}".format(
|
|
231
|
+
project=project,
|
|
232
|
+
instance=instance,
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
@staticmethod
|
|
236
|
+
def parse_instance_path(path: str) -> Dict[str, str]:
|
|
237
|
+
"""Parses a instance path into its component segments."""
|
|
238
|
+
m = re.match(r"^projects/(?P<project>.+?)/instances/(?P<instance>.+?)$", path)
|
|
239
|
+
return m.groupdict() if m else {}
|
|
240
|
+
|
|
241
|
+
@staticmethod
|
|
242
|
+
def materialized_view_path(
|
|
243
|
+
project: str,
|
|
244
|
+
instance: str,
|
|
245
|
+
materialized_view: str,
|
|
246
|
+
) -> str:
|
|
247
|
+
"""Returns a fully-qualified materialized_view string."""
|
|
248
|
+
return "projects/{project}/instances/{instance}/materializedViews/{materialized_view}".format(
|
|
249
|
+
project=project,
|
|
250
|
+
instance=instance,
|
|
251
|
+
materialized_view=materialized_view,
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
@staticmethod
|
|
255
|
+
def parse_materialized_view_path(path: str) -> Dict[str, str]:
|
|
256
|
+
"""Parses a materialized_view path into its component segments."""
|
|
257
|
+
m = re.match(
|
|
258
|
+
r"^projects/(?P<project>.+?)/instances/(?P<instance>.+?)/materializedViews/(?P<materialized_view>.+?)$",
|
|
259
|
+
path,
|
|
260
|
+
)
|
|
261
|
+
return m.groupdict() if m else {}
|
|
262
|
+
|
|
263
|
+
@staticmethod
|
|
264
|
+
def table_path(
|
|
265
|
+
project: str,
|
|
266
|
+
instance: str,
|
|
267
|
+
table: str,
|
|
268
|
+
) -> str:
|
|
269
|
+
"""Returns a fully-qualified table string."""
|
|
270
|
+
return "projects/{project}/instances/{instance}/tables/{table}".format(
|
|
271
|
+
project=project,
|
|
272
|
+
instance=instance,
|
|
273
|
+
table=table,
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
@staticmethod
|
|
277
|
+
def parse_table_path(path: str) -> Dict[str, str]:
|
|
278
|
+
"""Parses a table path into its component segments."""
|
|
279
|
+
m = re.match(
|
|
280
|
+
r"^projects/(?P<project>.+?)/instances/(?P<instance>.+?)/tables/(?P<table>.+?)$",
|
|
281
|
+
path,
|
|
282
|
+
)
|
|
283
|
+
return m.groupdict() if m else {}
|
|
284
|
+
|
|
285
|
+
@staticmethod
|
|
286
|
+
def common_billing_account_path(
|
|
287
|
+
billing_account: str,
|
|
288
|
+
) -> str:
|
|
289
|
+
"""Returns a fully-qualified billing_account string."""
|
|
290
|
+
return "billingAccounts/{billing_account}".format(
|
|
291
|
+
billing_account=billing_account,
|
|
292
|
+
)
|
|
293
|
+
|
|
294
|
+
@staticmethod
|
|
295
|
+
def parse_common_billing_account_path(path: str) -> Dict[str, str]:
|
|
296
|
+
"""Parse a billing_account path into its component segments."""
|
|
297
|
+
m = re.match(r"^billingAccounts/(?P<billing_account>.+?)$", path)
|
|
298
|
+
return m.groupdict() if m else {}
|
|
299
|
+
|
|
300
|
+
@staticmethod
|
|
301
|
+
def common_folder_path(
|
|
302
|
+
folder: str,
|
|
303
|
+
) -> str:
|
|
304
|
+
"""Returns a fully-qualified folder string."""
|
|
305
|
+
return "folders/{folder}".format(
|
|
306
|
+
folder=folder,
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
@staticmethod
|
|
310
|
+
def parse_common_folder_path(path: str) -> Dict[str, str]:
|
|
311
|
+
"""Parse a folder path into its component segments."""
|
|
312
|
+
m = re.match(r"^folders/(?P<folder>.+?)$", path)
|
|
313
|
+
return m.groupdict() if m else {}
|
|
314
|
+
|
|
315
|
+
@staticmethod
|
|
316
|
+
def common_organization_path(
|
|
317
|
+
organization: str,
|
|
318
|
+
) -> str:
|
|
319
|
+
"""Returns a fully-qualified organization string."""
|
|
320
|
+
return "organizations/{organization}".format(
|
|
321
|
+
organization=organization,
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
@staticmethod
|
|
325
|
+
def parse_common_organization_path(path: str) -> Dict[str, str]:
|
|
326
|
+
"""Parse a organization path into its component segments."""
|
|
327
|
+
m = re.match(r"^organizations/(?P<organization>.+?)$", path)
|
|
328
|
+
return m.groupdict() if m else {}
|
|
329
|
+
|
|
330
|
+
@staticmethod
|
|
331
|
+
def common_project_path(
|
|
332
|
+
project: str,
|
|
333
|
+
) -> str:
|
|
334
|
+
"""Returns a fully-qualified project string."""
|
|
335
|
+
return "projects/{project}".format(
|
|
336
|
+
project=project,
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
@staticmethod
|
|
340
|
+
def parse_common_project_path(path: str) -> Dict[str, str]:
|
|
341
|
+
"""Parse a project path into its component segments."""
|
|
342
|
+
m = re.match(r"^projects/(?P<project>.+?)$", path)
|
|
343
|
+
return m.groupdict() if m else {}
|
|
344
|
+
|
|
345
|
+
@staticmethod
|
|
346
|
+
def common_location_path(
|
|
347
|
+
project: str,
|
|
348
|
+
location: str,
|
|
349
|
+
) -> str:
|
|
350
|
+
"""Returns a fully-qualified location string."""
|
|
351
|
+
return "projects/{project}/locations/{location}".format(
|
|
352
|
+
project=project,
|
|
353
|
+
location=location,
|
|
354
|
+
)
|
|
355
|
+
|
|
356
|
+
@staticmethod
|
|
357
|
+
def parse_common_location_path(path: str) -> Dict[str, str]:
|
|
358
|
+
"""Parse a location path into its component segments."""
|
|
359
|
+
m = re.match(r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)$", path)
|
|
360
|
+
return m.groupdict() if m else {}
|
|
361
|
+
|
|
362
|
+
@classmethod
|
|
363
|
+
def get_mtls_endpoint_and_cert_source(
|
|
364
|
+
cls, client_options: Optional[client_options_lib.ClientOptions] = None
|
|
365
|
+
):
|
|
366
|
+
"""Deprecated. Return the API endpoint and client cert source for mutual TLS.
|
|
367
|
+
|
|
368
|
+
The client cert source is determined in the following order:
|
|
369
|
+
(1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the
|
|
370
|
+
client cert source is None.
|
|
371
|
+
(2) if `client_options.client_cert_source` is provided, use the provided one; if the
|
|
372
|
+
default client cert source exists, use the default one; otherwise the client cert
|
|
373
|
+
source is None.
|
|
374
|
+
|
|
375
|
+
The API endpoint is determined in the following order:
|
|
376
|
+
(1) if `client_options.api_endpoint` if provided, use the provided one.
|
|
377
|
+
(2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the
|
|
378
|
+
default mTLS endpoint; if the environment variable is "never", use the default API
|
|
379
|
+
endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise
|
|
380
|
+
use the default API endpoint.
|
|
381
|
+
|
|
382
|
+
More details can be found at https://google.aip.dev/auth/4114.
|
|
383
|
+
|
|
384
|
+
Args:
|
|
385
|
+
client_options (google.api_core.client_options.ClientOptions): Custom options for the
|
|
386
|
+
client. Only the `api_endpoint` and `client_cert_source` properties may be used
|
|
387
|
+
in this method.
|
|
388
|
+
|
|
389
|
+
Returns:
|
|
390
|
+
Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the
|
|
391
|
+
client cert source to use.
|
|
392
|
+
|
|
393
|
+
Raises:
|
|
394
|
+
google.auth.exceptions.MutualTLSChannelError: If any errors happen.
|
|
395
|
+
"""
|
|
396
|
+
|
|
397
|
+
warnings.warn(
|
|
398
|
+
"get_mtls_endpoint_and_cert_source is deprecated. Use the api_endpoint property instead.",
|
|
399
|
+
DeprecationWarning,
|
|
400
|
+
)
|
|
401
|
+
if client_options is None:
|
|
402
|
+
client_options = client_options_lib.ClientOptions()
|
|
403
|
+
use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")
|
|
404
|
+
use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto")
|
|
405
|
+
if use_client_cert not in ("true", "false"):
|
|
406
|
+
raise ValueError(
|
|
407
|
+
"Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
|
|
408
|
+
)
|
|
409
|
+
if use_mtls_endpoint not in ("auto", "never", "always"):
|
|
410
|
+
raise MutualTLSChannelError(
|
|
411
|
+
"Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
|
|
412
|
+
)
|
|
413
|
+
|
|
414
|
+
# Figure out the client cert source to use.
|
|
415
|
+
client_cert_source = None
|
|
416
|
+
if use_client_cert == "true":
|
|
417
|
+
if client_options.client_cert_source:
|
|
418
|
+
client_cert_source = client_options.client_cert_source
|
|
419
|
+
elif mtls.has_default_client_cert_source():
|
|
420
|
+
client_cert_source = mtls.default_client_cert_source()
|
|
421
|
+
|
|
422
|
+
# Figure out which api endpoint to use.
|
|
423
|
+
if client_options.api_endpoint is not None:
|
|
424
|
+
api_endpoint = client_options.api_endpoint
|
|
425
|
+
elif use_mtls_endpoint == "always" or (
|
|
426
|
+
use_mtls_endpoint == "auto" and client_cert_source
|
|
427
|
+
):
|
|
428
|
+
api_endpoint = cls.DEFAULT_MTLS_ENDPOINT
|
|
429
|
+
else:
|
|
430
|
+
api_endpoint = cls.DEFAULT_ENDPOINT
|
|
431
|
+
|
|
432
|
+
return api_endpoint, client_cert_source
|
|
433
|
+
|
|
434
|
+
@staticmethod
|
|
435
|
+
def _read_environment_variables():
|
|
436
|
+
"""Returns the environment variables used by the client.
|
|
437
|
+
|
|
438
|
+
Returns:
|
|
439
|
+
Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE,
|
|
440
|
+
GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables.
|
|
441
|
+
|
|
442
|
+
Raises:
|
|
443
|
+
ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not
|
|
444
|
+
any of ["true", "false"].
|
|
445
|
+
google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT
|
|
446
|
+
is not any of ["auto", "never", "always"].
|
|
447
|
+
"""
|
|
448
|
+
use_client_cert = os.getenv(
|
|
449
|
+
"GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
|
|
450
|
+
).lower()
|
|
451
|
+
use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower()
|
|
452
|
+
universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN")
|
|
453
|
+
if use_client_cert not in ("true", "false"):
|
|
454
|
+
raise ValueError(
|
|
455
|
+
"Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
|
|
456
|
+
)
|
|
457
|
+
if use_mtls_endpoint not in ("auto", "never", "always"):
|
|
458
|
+
raise MutualTLSChannelError(
|
|
459
|
+
"Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
|
|
460
|
+
)
|
|
461
|
+
return use_client_cert == "true", use_mtls_endpoint, universe_domain_env
|
|
462
|
+
|
|
463
|
+
@staticmethod
|
|
464
|
+
def _get_client_cert_source(provided_cert_source, use_cert_flag):
|
|
465
|
+
"""Return the client cert source to be used by the client.
|
|
466
|
+
|
|
467
|
+
Args:
|
|
468
|
+
provided_cert_source (bytes): The client certificate source provided.
|
|
469
|
+
use_cert_flag (bool): A flag indicating whether to use the client certificate.
|
|
470
|
+
|
|
471
|
+
Returns:
|
|
472
|
+
bytes or None: The client cert source to be used by the client.
|
|
473
|
+
"""
|
|
474
|
+
client_cert_source = None
|
|
475
|
+
if use_cert_flag:
|
|
476
|
+
if provided_cert_source:
|
|
477
|
+
client_cert_source = provided_cert_source
|
|
478
|
+
elif mtls.has_default_client_cert_source():
|
|
479
|
+
client_cert_source = mtls.default_client_cert_source()
|
|
480
|
+
return client_cert_source
|
|
481
|
+
|
|
482
|
+
@staticmethod
|
|
483
|
+
def _get_api_endpoint(
|
|
484
|
+
api_override, client_cert_source, universe_domain, use_mtls_endpoint
|
|
485
|
+
):
|
|
486
|
+
"""Return the API endpoint used by the client.
|
|
487
|
+
|
|
488
|
+
Args:
|
|
489
|
+
api_override (str): The API endpoint override. If specified, this is always
|
|
490
|
+
the return value of this function and the other arguments are not used.
|
|
491
|
+
client_cert_source (bytes): The client certificate source used by the client.
|
|
492
|
+
universe_domain (str): The universe domain used by the client.
|
|
493
|
+
use_mtls_endpoint (str): How to use the mTLS endpoint, which depends also on the other parameters.
|
|
494
|
+
Possible values are "always", "auto", or "never".
|
|
495
|
+
|
|
496
|
+
Returns:
|
|
497
|
+
str: The API endpoint to be used by the client.
|
|
498
|
+
"""
|
|
499
|
+
if api_override is not None:
|
|
500
|
+
api_endpoint = api_override
|
|
501
|
+
elif use_mtls_endpoint == "always" or (
|
|
502
|
+
use_mtls_endpoint == "auto" and client_cert_source
|
|
503
|
+
):
|
|
504
|
+
_default_universe = BigtableClient._DEFAULT_UNIVERSE
|
|
505
|
+
if universe_domain != _default_universe:
|
|
506
|
+
raise MutualTLSChannelError(
|
|
507
|
+
f"mTLS is not supported in any universe other than {_default_universe}."
|
|
508
|
+
)
|
|
509
|
+
api_endpoint = BigtableClient.DEFAULT_MTLS_ENDPOINT
|
|
510
|
+
else:
|
|
511
|
+
api_endpoint = BigtableClient._DEFAULT_ENDPOINT_TEMPLATE.format(
|
|
512
|
+
UNIVERSE_DOMAIN=universe_domain
|
|
513
|
+
)
|
|
514
|
+
return api_endpoint
|
|
515
|
+
|
|
516
|
+
@staticmethod
|
|
517
|
+
def _get_universe_domain(
|
|
518
|
+
client_universe_domain: Optional[str], universe_domain_env: Optional[str]
|
|
519
|
+
) -> str:
|
|
520
|
+
"""Return the universe domain used by the client.
|
|
521
|
+
|
|
522
|
+
Args:
|
|
523
|
+
client_universe_domain (Optional[str]): The universe domain configured via the client options.
|
|
524
|
+
universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable.
|
|
525
|
+
|
|
526
|
+
Returns:
|
|
527
|
+
str: The universe domain to be used by the client.
|
|
528
|
+
|
|
529
|
+
Raises:
|
|
530
|
+
ValueError: If the universe domain is an empty string.
|
|
531
|
+
"""
|
|
532
|
+
universe_domain = BigtableClient._DEFAULT_UNIVERSE
|
|
533
|
+
if client_universe_domain is not None:
|
|
534
|
+
universe_domain = client_universe_domain
|
|
535
|
+
elif universe_domain_env is not None:
|
|
536
|
+
universe_domain = universe_domain_env
|
|
537
|
+
if len(universe_domain.strip()) == 0:
|
|
538
|
+
raise ValueError("Universe Domain cannot be an empty string.")
|
|
539
|
+
return universe_domain
|
|
540
|
+
|
|
541
|
+
def _validate_universe_domain(self):
|
|
542
|
+
"""Validates client's and credentials' universe domains are consistent.
|
|
543
|
+
|
|
544
|
+
Returns:
|
|
545
|
+
bool: True iff the configured universe domain is valid.
|
|
546
|
+
|
|
547
|
+
Raises:
|
|
548
|
+
ValueError: If the configured universe domain is not valid.
|
|
549
|
+
"""
|
|
550
|
+
|
|
551
|
+
# NOTE (b/349488459): universe validation is disabled until further notice.
|
|
552
|
+
return True
|
|
553
|
+
|
|
554
|
+
def _add_cred_info_for_auth_errors(
|
|
555
|
+
self, error: core_exceptions.GoogleAPICallError
|
|
556
|
+
) -> None:
|
|
557
|
+
"""Adds credential info string to error details for 401/403/404 errors.
|
|
558
|
+
|
|
559
|
+
Args:
|
|
560
|
+
error (google.api_core.exceptions.GoogleAPICallError): The error to add the cred info.
|
|
561
|
+
"""
|
|
562
|
+
if error.code not in [
|
|
563
|
+
HTTPStatus.UNAUTHORIZED,
|
|
564
|
+
HTTPStatus.FORBIDDEN,
|
|
565
|
+
HTTPStatus.NOT_FOUND,
|
|
566
|
+
]:
|
|
567
|
+
return
|
|
568
|
+
|
|
569
|
+
cred = self._transport._credentials
|
|
570
|
+
|
|
571
|
+
# get_cred_info is only available in google-auth>=2.35.0
|
|
572
|
+
if not hasattr(cred, "get_cred_info"):
|
|
573
|
+
return
|
|
574
|
+
|
|
575
|
+
# ignore the type check since pypy test fails when get_cred_info
|
|
576
|
+
# is not available
|
|
577
|
+
cred_info = cred.get_cred_info() # type: ignore
|
|
578
|
+
if cred_info and hasattr(error._details, "append"):
|
|
579
|
+
error._details.append(json.dumps(cred_info))
|
|
580
|
+
|
|
581
|
+
@property
|
|
582
|
+
def api_endpoint(self):
|
|
583
|
+
"""Return the API endpoint used by the client instance.
|
|
584
|
+
|
|
585
|
+
Returns:
|
|
586
|
+
str: The API endpoint used by the client instance.
|
|
587
|
+
"""
|
|
588
|
+
return self._api_endpoint
|
|
589
|
+
|
|
590
|
+
@property
|
|
591
|
+
def universe_domain(self) -> str:
|
|
592
|
+
"""Return the universe domain used by the client instance.
|
|
593
|
+
|
|
594
|
+
Returns:
|
|
595
|
+
str: The universe domain used by the client instance.
|
|
596
|
+
"""
|
|
597
|
+
return self._universe_domain
|
|
598
|
+
|
|
599
|
+
def __init__(
|
|
600
|
+
self,
|
|
601
|
+
*,
|
|
602
|
+
credentials: Optional[ga_credentials.Credentials] = None,
|
|
603
|
+
transport: Optional[
|
|
604
|
+
Union[str, BigtableTransport, Callable[..., BigtableTransport]]
|
|
605
|
+
] = None,
|
|
606
|
+
client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None,
|
|
607
|
+
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
|
|
608
|
+
) -> None:
|
|
609
|
+
"""Instantiates the bigtable client.
|
|
610
|
+
|
|
611
|
+
Args:
|
|
612
|
+
credentials (Optional[google.auth.credentials.Credentials]): The
|
|
613
|
+
authorization credentials to attach to requests. These
|
|
614
|
+
credentials identify the application to the service; if none
|
|
615
|
+
are specified, the client will attempt to ascertain the
|
|
616
|
+
credentials from the environment.
|
|
617
|
+
transport (Optional[Union[str,BigtableTransport,Callable[..., BigtableTransport]]]):
|
|
618
|
+
The transport to use, or a Callable that constructs and returns a new transport.
|
|
619
|
+
If a Callable is given, it will be called with the same set of initialization
|
|
620
|
+
arguments as used in the BigtableTransport constructor.
|
|
621
|
+
If set to None, a transport is chosen automatically.
|
|
622
|
+
client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]):
|
|
623
|
+
Custom options for the client.
|
|
624
|
+
|
|
625
|
+
1. The ``api_endpoint`` property can be used to override the
|
|
626
|
+
default endpoint provided by the client when ``transport`` is
|
|
627
|
+
not explicitly provided. Only if this property is not set and
|
|
628
|
+
``transport`` was not explicitly provided, the endpoint is
|
|
629
|
+
determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment
|
|
630
|
+
variable, which have one of the following values:
|
|
631
|
+
"always" (always use the default mTLS endpoint), "never" (always
|
|
632
|
+
use the default regular endpoint) and "auto" (auto-switch to the
|
|
633
|
+
default mTLS endpoint if client certificate is present; this is
|
|
634
|
+
the default value).
|
|
635
|
+
|
|
636
|
+
2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
|
|
637
|
+
is "true", then the ``client_cert_source`` property can be used
|
|
638
|
+
to provide a client certificate for mTLS transport. If
|
|
639
|
+
not provided, the default SSL client certificate will be used if
|
|
640
|
+
present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
|
|
641
|
+
set, no client certificate will be used.
|
|
642
|
+
|
|
643
|
+
3. The ``universe_domain`` property can be used to override the
|
|
644
|
+
default "googleapis.com" universe. Note that the ``api_endpoint``
|
|
645
|
+
property still takes precedence; and ``universe_domain`` is
|
|
646
|
+
currently not supported for mTLS.
|
|
647
|
+
|
|
648
|
+
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
|
|
649
|
+
The client info used to send a user-agent string along with
|
|
650
|
+
API requests. If ``None``, then default info will be used.
|
|
651
|
+
Generally, you only need to set this if you're developing
|
|
652
|
+
your own client library.
|
|
653
|
+
|
|
654
|
+
Raises:
|
|
655
|
+
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
|
|
656
|
+
creation failed for any reason.
|
|
657
|
+
"""
|
|
658
|
+
self._client_options = client_options
|
|
659
|
+
if isinstance(self._client_options, dict):
|
|
660
|
+
self._client_options = client_options_lib.from_dict(self._client_options)
|
|
661
|
+
if self._client_options is None:
|
|
662
|
+
self._client_options = client_options_lib.ClientOptions()
|
|
663
|
+
self._client_options = cast(
|
|
664
|
+
client_options_lib.ClientOptions, self._client_options
|
|
665
|
+
)
|
|
666
|
+
|
|
667
|
+
universe_domain_opt = getattr(self._client_options, "universe_domain", None)
|
|
668
|
+
|
|
669
|
+
(
|
|
670
|
+
self._use_client_cert,
|
|
671
|
+
self._use_mtls_endpoint,
|
|
672
|
+
self._universe_domain_env,
|
|
673
|
+
) = BigtableClient._read_environment_variables()
|
|
674
|
+
self._client_cert_source = BigtableClient._get_client_cert_source(
|
|
675
|
+
self._client_options.client_cert_source, self._use_client_cert
|
|
676
|
+
)
|
|
677
|
+
self._universe_domain = BigtableClient._get_universe_domain(
|
|
678
|
+
universe_domain_opt, self._universe_domain_env
|
|
679
|
+
)
|
|
680
|
+
self._api_endpoint = None # updated below, depending on `transport`
|
|
681
|
+
|
|
682
|
+
# Initialize the universe domain validation.
|
|
683
|
+
self._is_universe_domain_valid = False
|
|
684
|
+
|
|
685
|
+
if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER
|
|
686
|
+
# Setup logging.
|
|
687
|
+
client_logging.initialize_logging()
|
|
688
|
+
|
|
689
|
+
api_key_value = getattr(self._client_options, "api_key", None)
|
|
690
|
+
if api_key_value and credentials:
|
|
691
|
+
raise ValueError(
|
|
692
|
+
"client_options.api_key and credentials are mutually exclusive"
|
|
693
|
+
)
|
|
694
|
+
|
|
695
|
+
# Save or instantiate the transport.
|
|
696
|
+
# Ordinarily, we provide the transport, but allowing a custom transport
|
|
697
|
+
# instance provides an extensibility point for unusual situations.
|
|
698
|
+
transport_provided = isinstance(transport, BigtableTransport)
|
|
699
|
+
if transport_provided:
|
|
700
|
+
# transport is a BigtableTransport instance.
|
|
701
|
+
if credentials or self._client_options.credentials_file or api_key_value:
|
|
702
|
+
raise ValueError(
|
|
703
|
+
"When providing a transport instance, "
|
|
704
|
+
"provide its credentials directly."
|
|
705
|
+
)
|
|
706
|
+
if self._client_options.scopes:
|
|
707
|
+
raise ValueError(
|
|
708
|
+
"When providing a transport instance, provide its scopes "
|
|
709
|
+
"directly."
|
|
710
|
+
)
|
|
711
|
+
self._transport = cast(BigtableTransport, transport)
|
|
712
|
+
self._api_endpoint = self._transport.host
|
|
713
|
+
|
|
714
|
+
self._api_endpoint = self._api_endpoint or BigtableClient._get_api_endpoint(
|
|
715
|
+
self._client_options.api_endpoint,
|
|
716
|
+
self._client_cert_source,
|
|
717
|
+
self._universe_domain,
|
|
718
|
+
self._use_mtls_endpoint,
|
|
719
|
+
)
|
|
720
|
+
|
|
721
|
+
if not transport_provided:
|
|
722
|
+
import google.auth._default # type: ignore
|
|
723
|
+
|
|
724
|
+
if api_key_value and hasattr(
|
|
725
|
+
google.auth._default, "get_api_key_credentials"
|
|
726
|
+
):
|
|
727
|
+
credentials = google.auth._default.get_api_key_credentials(
|
|
728
|
+
api_key_value
|
|
729
|
+
)
|
|
730
|
+
|
|
731
|
+
transport_init: Union[
|
|
732
|
+
Type[BigtableTransport], Callable[..., BigtableTransport]
|
|
733
|
+
] = (
|
|
734
|
+
BigtableClient.get_transport_class(transport)
|
|
735
|
+
if isinstance(transport, str) or transport is None
|
|
736
|
+
else cast(Callable[..., BigtableTransport], transport)
|
|
737
|
+
)
|
|
738
|
+
# initialize with the provided callable or the passed in class
|
|
739
|
+
self._transport = transport_init(
|
|
740
|
+
credentials=credentials,
|
|
741
|
+
credentials_file=self._client_options.credentials_file,
|
|
742
|
+
host=self._api_endpoint,
|
|
743
|
+
scopes=self._client_options.scopes,
|
|
744
|
+
client_cert_source_for_mtls=self._client_cert_source,
|
|
745
|
+
quota_project_id=self._client_options.quota_project_id,
|
|
746
|
+
client_info=client_info,
|
|
747
|
+
always_use_jwt_access=True,
|
|
748
|
+
api_audience=self._client_options.api_audience,
|
|
749
|
+
)
|
|
750
|
+
|
|
751
|
+
if "async" not in str(self._transport):
|
|
752
|
+
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
|
|
753
|
+
std_logging.DEBUG
|
|
754
|
+
): # pragma: NO COVER
|
|
755
|
+
_LOGGER.debug(
|
|
756
|
+
"Created client `google.bigtable_v2.BigtableClient`.",
|
|
757
|
+
extra={
|
|
758
|
+
"serviceName": "google.bigtable.v2.Bigtable",
|
|
759
|
+
"universeDomain": getattr(
|
|
760
|
+
self._transport._credentials, "universe_domain", ""
|
|
761
|
+
),
|
|
762
|
+
"credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}",
|
|
763
|
+
"credentialsInfo": getattr(
|
|
764
|
+
self.transport._credentials, "get_cred_info", lambda: None
|
|
765
|
+
)(),
|
|
766
|
+
}
|
|
767
|
+
if hasattr(self._transport, "_credentials")
|
|
768
|
+
else {
|
|
769
|
+
"serviceName": "google.bigtable.v2.Bigtable",
|
|
770
|
+
"credentialsType": None,
|
|
771
|
+
},
|
|
772
|
+
)
|
|
773
|
+
|
|
774
|
+
def read_rows(
|
|
775
|
+
self,
|
|
776
|
+
request: Optional[Union[bigtable.ReadRowsRequest, dict]] = None,
|
|
777
|
+
*,
|
|
778
|
+
table_name: Optional[str] = None,
|
|
779
|
+
app_profile_id: Optional[str] = None,
|
|
780
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
781
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
782
|
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
|
783
|
+
) -> Iterable[bigtable.ReadRowsResponse]:
|
|
784
|
+
r"""Streams back the contents of all requested rows in
|
|
785
|
+
key order, optionally applying the same Reader filter to
|
|
786
|
+
each. Depending on their size, rows and cells may be
|
|
787
|
+
broken up across multiple responses, but atomicity of
|
|
788
|
+
each row will still be preserved. See the
|
|
789
|
+
ReadRowsResponse documentation for details.
|
|
790
|
+
|
|
791
|
+
Args:
|
|
792
|
+
request (Union[google.cloud.bigtable_v2.types.ReadRowsRequest, dict]):
|
|
793
|
+
The request object. Request message for
|
|
794
|
+
Bigtable.ReadRows.
|
|
795
|
+
table_name (str):
|
|
796
|
+
Optional. The unique name of the table from which to
|
|
797
|
+
read.
|
|
798
|
+
|
|
799
|
+
Values are of the form
|
|
800
|
+
``projects/<project>/instances/<instance>/tables/<table>``.
|
|
801
|
+
|
|
802
|
+
This corresponds to the ``table_name`` field
|
|
803
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
804
|
+
should not be set.
|
|
805
|
+
app_profile_id (str):
|
|
806
|
+
This value specifies routing for
|
|
807
|
+
replication. If not specified, the
|
|
808
|
+
"default" application profile will be
|
|
809
|
+
used.
|
|
810
|
+
|
|
811
|
+
This corresponds to the ``app_profile_id`` field
|
|
812
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
813
|
+
should not be set.
|
|
814
|
+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
|
|
815
|
+
should be retried.
|
|
816
|
+
timeout (float): The timeout for this request.
|
|
817
|
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
|
818
|
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
|
819
|
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
|
820
|
+
be of type `bytes`.
|
|
821
|
+
|
|
822
|
+
Returns:
|
|
823
|
+
Iterable[google.cloud.bigtable_v2.types.ReadRowsResponse]:
|
|
824
|
+
Response message for
|
|
825
|
+
Bigtable.ReadRows.
|
|
826
|
+
|
|
827
|
+
"""
|
|
828
|
+
# Create or coerce a protobuf request object.
|
|
829
|
+
# - Quick check: If we got a request object, we should *not* have
|
|
830
|
+
# gotten any keyword arguments that map to the request.
|
|
831
|
+
flattened_params = [table_name, app_profile_id]
|
|
832
|
+
has_flattened_params = (
|
|
833
|
+
len([param for param in flattened_params if param is not None]) > 0
|
|
834
|
+
)
|
|
835
|
+
if request is not None and has_flattened_params:
|
|
836
|
+
raise ValueError(
|
|
837
|
+
"If the `request` argument is set, then none of "
|
|
838
|
+
"the individual field arguments should be set."
|
|
839
|
+
)
|
|
840
|
+
|
|
841
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
842
|
+
# there are no flattened fields), or create one.
|
|
843
|
+
if not isinstance(request, bigtable.ReadRowsRequest):
|
|
844
|
+
request = bigtable.ReadRowsRequest(request)
|
|
845
|
+
# If we have keyword arguments corresponding to fields on the
|
|
846
|
+
# request, apply these.
|
|
847
|
+
if table_name is not None:
|
|
848
|
+
request.table_name = table_name
|
|
849
|
+
if app_profile_id is not None:
|
|
850
|
+
request.app_profile_id = app_profile_id
|
|
851
|
+
|
|
852
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
853
|
+
# and friendly error handling.
|
|
854
|
+
rpc = self._transport._wrapped_methods[self._transport.read_rows]
|
|
855
|
+
|
|
856
|
+
header_params = {}
|
|
857
|
+
|
|
858
|
+
routing_param_regex = re.compile(
|
|
859
|
+
"^(?P<table_name>projects/[^/]+/instances/[^/]+/tables/[^/]+)$"
|
|
860
|
+
)
|
|
861
|
+
regex_match = routing_param_regex.match(request.table_name)
|
|
862
|
+
if regex_match and regex_match.group("table_name"):
|
|
863
|
+
header_params["table_name"] = regex_match.group("table_name")
|
|
864
|
+
|
|
865
|
+
if request.app_profile_id:
|
|
866
|
+
header_params["app_profile_id"] = request.app_profile_id
|
|
867
|
+
|
|
868
|
+
routing_param_regex = re.compile(
|
|
869
|
+
"^(?P<authorized_view_name>projects/[^/]+/instances/[^/]+/tables/[^/]+/authorizedViews/[^/]+)$"
|
|
870
|
+
)
|
|
871
|
+
regex_match = routing_param_regex.match(request.authorized_view_name)
|
|
872
|
+
if regex_match and regex_match.group("authorized_view_name"):
|
|
873
|
+
header_params["authorized_view_name"] = regex_match.group(
|
|
874
|
+
"authorized_view_name"
|
|
875
|
+
)
|
|
876
|
+
|
|
877
|
+
if header_params:
|
|
878
|
+
metadata = tuple(metadata) + (
|
|
879
|
+
gapic_v1.routing_header.to_grpc_metadata(header_params),
|
|
880
|
+
)
|
|
881
|
+
|
|
882
|
+
# Validate the universe domain.
|
|
883
|
+
self._validate_universe_domain()
|
|
884
|
+
|
|
885
|
+
# Send the request.
|
|
886
|
+
response = rpc(
|
|
887
|
+
request,
|
|
888
|
+
retry=retry,
|
|
889
|
+
timeout=timeout,
|
|
890
|
+
metadata=metadata,
|
|
891
|
+
)
|
|
892
|
+
|
|
893
|
+
# Done; return the response.
|
|
894
|
+
return response
|
|
895
|
+
|
|
896
|
+
def sample_row_keys(
|
|
897
|
+
self,
|
|
898
|
+
request: Optional[Union[bigtable.SampleRowKeysRequest, dict]] = None,
|
|
899
|
+
*,
|
|
900
|
+
table_name: Optional[str] = None,
|
|
901
|
+
app_profile_id: Optional[str] = None,
|
|
902
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
903
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
904
|
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
|
905
|
+
) -> Iterable[bigtable.SampleRowKeysResponse]:
|
|
906
|
+
r"""Returns a sample of row keys in the table. The
|
|
907
|
+
returned row keys will delimit contiguous sections of
|
|
908
|
+
the table of approximately equal size, which can be used
|
|
909
|
+
to break up the data for distributed tasks like
|
|
910
|
+
mapreduces.
|
|
911
|
+
|
|
912
|
+
Args:
|
|
913
|
+
request (Union[google.cloud.bigtable_v2.types.SampleRowKeysRequest, dict]):
|
|
914
|
+
The request object. Request message for
|
|
915
|
+
Bigtable.SampleRowKeys.
|
|
916
|
+
table_name (str):
|
|
917
|
+
Optional. The unique name of the table from which to
|
|
918
|
+
sample row keys.
|
|
919
|
+
|
|
920
|
+
Values are of the form
|
|
921
|
+
``projects/<project>/instances/<instance>/tables/<table>``.
|
|
922
|
+
|
|
923
|
+
This corresponds to the ``table_name`` field
|
|
924
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
925
|
+
should not be set.
|
|
926
|
+
app_profile_id (str):
|
|
927
|
+
This value specifies routing for
|
|
928
|
+
replication. If not specified, the
|
|
929
|
+
"default" application profile will be
|
|
930
|
+
used.
|
|
931
|
+
|
|
932
|
+
This corresponds to the ``app_profile_id`` field
|
|
933
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
934
|
+
should not be set.
|
|
935
|
+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
|
|
936
|
+
should be retried.
|
|
937
|
+
timeout (float): The timeout for this request.
|
|
938
|
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
|
939
|
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
|
940
|
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
|
941
|
+
be of type `bytes`.
|
|
942
|
+
|
|
943
|
+
Returns:
|
|
944
|
+
Iterable[google.cloud.bigtable_v2.types.SampleRowKeysResponse]:
|
|
945
|
+
Response message for
|
|
946
|
+
Bigtable.SampleRowKeys.
|
|
947
|
+
|
|
948
|
+
"""
|
|
949
|
+
# Create or coerce a protobuf request object.
|
|
950
|
+
# - Quick check: If we got a request object, we should *not* have
|
|
951
|
+
# gotten any keyword arguments that map to the request.
|
|
952
|
+
flattened_params = [table_name, app_profile_id]
|
|
953
|
+
has_flattened_params = (
|
|
954
|
+
len([param for param in flattened_params if param is not None]) > 0
|
|
955
|
+
)
|
|
956
|
+
if request is not None and has_flattened_params:
|
|
957
|
+
raise ValueError(
|
|
958
|
+
"If the `request` argument is set, then none of "
|
|
959
|
+
"the individual field arguments should be set."
|
|
960
|
+
)
|
|
961
|
+
|
|
962
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
963
|
+
# there are no flattened fields), or create one.
|
|
964
|
+
if not isinstance(request, bigtable.SampleRowKeysRequest):
|
|
965
|
+
request = bigtable.SampleRowKeysRequest(request)
|
|
966
|
+
# If we have keyword arguments corresponding to fields on the
|
|
967
|
+
# request, apply these.
|
|
968
|
+
if table_name is not None:
|
|
969
|
+
request.table_name = table_name
|
|
970
|
+
if app_profile_id is not None:
|
|
971
|
+
request.app_profile_id = app_profile_id
|
|
972
|
+
|
|
973
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
974
|
+
# and friendly error handling.
|
|
975
|
+
rpc = self._transport._wrapped_methods[self._transport.sample_row_keys]
|
|
976
|
+
|
|
977
|
+
header_params = {}
|
|
978
|
+
|
|
979
|
+
routing_param_regex = re.compile(
|
|
980
|
+
"^(?P<table_name>projects/[^/]+/instances/[^/]+/tables/[^/]+)$"
|
|
981
|
+
)
|
|
982
|
+
regex_match = routing_param_regex.match(request.table_name)
|
|
983
|
+
if regex_match and regex_match.group("table_name"):
|
|
984
|
+
header_params["table_name"] = regex_match.group("table_name")
|
|
985
|
+
|
|
986
|
+
if request.app_profile_id:
|
|
987
|
+
header_params["app_profile_id"] = request.app_profile_id
|
|
988
|
+
|
|
989
|
+
routing_param_regex = re.compile(
|
|
990
|
+
"^(?P<authorized_view_name>projects/[^/]+/instances/[^/]+/tables/[^/]+/authorizedViews/[^/]+)$"
|
|
991
|
+
)
|
|
992
|
+
regex_match = routing_param_regex.match(request.authorized_view_name)
|
|
993
|
+
if regex_match and regex_match.group("authorized_view_name"):
|
|
994
|
+
header_params["authorized_view_name"] = regex_match.group(
|
|
995
|
+
"authorized_view_name"
|
|
996
|
+
)
|
|
997
|
+
|
|
998
|
+
if header_params:
|
|
999
|
+
metadata = tuple(metadata) + (
|
|
1000
|
+
gapic_v1.routing_header.to_grpc_metadata(header_params),
|
|
1001
|
+
)
|
|
1002
|
+
|
|
1003
|
+
# Validate the universe domain.
|
|
1004
|
+
self._validate_universe_domain()
|
|
1005
|
+
|
|
1006
|
+
# Send the request.
|
|
1007
|
+
response = rpc(
|
|
1008
|
+
request,
|
|
1009
|
+
retry=retry,
|
|
1010
|
+
timeout=timeout,
|
|
1011
|
+
metadata=metadata,
|
|
1012
|
+
)
|
|
1013
|
+
|
|
1014
|
+
# Done; return the response.
|
|
1015
|
+
return response
|
|
1016
|
+
|
|
1017
|
+
def mutate_row(
|
|
1018
|
+
self,
|
|
1019
|
+
request: Optional[Union[bigtable.MutateRowRequest, dict]] = None,
|
|
1020
|
+
*,
|
|
1021
|
+
table_name: Optional[str] = None,
|
|
1022
|
+
row_key: Optional[bytes] = None,
|
|
1023
|
+
mutations: Optional[MutableSequence[data.Mutation]] = None,
|
|
1024
|
+
app_profile_id: Optional[str] = None,
|
|
1025
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
1026
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
1027
|
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
|
1028
|
+
) -> bigtable.MutateRowResponse:
|
|
1029
|
+
r"""Mutates a row atomically. Cells already present in the row are
|
|
1030
|
+
left unchanged unless explicitly changed by ``mutation``.
|
|
1031
|
+
|
|
1032
|
+
Args:
|
|
1033
|
+
request (Union[google.cloud.bigtable_v2.types.MutateRowRequest, dict]):
|
|
1034
|
+
The request object. Request message for
|
|
1035
|
+
Bigtable.MutateRow.
|
|
1036
|
+
table_name (str):
|
|
1037
|
+
Optional. The unique name of the table to which the
|
|
1038
|
+
mutation should be applied.
|
|
1039
|
+
|
|
1040
|
+
Values are of the form
|
|
1041
|
+
``projects/<project>/instances/<instance>/tables/<table>``.
|
|
1042
|
+
|
|
1043
|
+
This corresponds to the ``table_name`` field
|
|
1044
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1045
|
+
should not be set.
|
|
1046
|
+
row_key (bytes):
|
|
1047
|
+
Required. The key of the row to which
|
|
1048
|
+
the mutation should be applied.
|
|
1049
|
+
|
|
1050
|
+
This corresponds to the ``row_key`` field
|
|
1051
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1052
|
+
should not be set.
|
|
1053
|
+
mutations (MutableSequence[google.cloud.bigtable_v2.types.Mutation]):
|
|
1054
|
+
Required. Changes to be atomically
|
|
1055
|
+
applied to the specified row. Entries
|
|
1056
|
+
are applied in order, meaning that
|
|
1057
|
+
earlier mutations can be masked by later
|
|
1058
|
+
ones. Must contain at least one entry
|
|
1059
|
+
and at most 100000.
|
|
1060
|
+
|
|
1061
|
+
This corresponds to the ``mutations`` field
|
|
1062
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1063
|
+
should not be set.
|
|
1064
|
+
app_profile_id (str):
|
|
1065
|
+
This value specifies routing for
|
|
1066
|
+
replication. If not specified, the
|
|
1067
|
+
"default" application profile will be
|
|
1068
|
+
used.
|
|
1069
|
+
|
|
1070
|
+
This corresponds to the ``app_profile_id`` field
|
|
1071
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1072
|
+
should not be set.
|
|
1073
|
+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
|
|
1074
|
+
should be retried.
|
|
1075
|
+
timeout (float): The timeout for this request.
|
|
1076
|
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
|
1077
|
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
|
1078
|
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
|
1079
|
+
be of type `bytes`.
|
|
1080
|
+
|
|
1081
|
+
Returns:
|
|
1082
|
+
google.cloud.bigtable_v2.types.MutateRowResponse:
|
|
1083
|
+
Response message for
|
|
1084
|
+
Bigtable.MutateRow.
|
|
1085
|
+
|
|
1086
|
+
"""
|
|
1087
|
+
# Create or coerce a protobuf request object.
|
|
1088
|
+
# - Quick check: If we got a request object, we should *not* have
|
|
1089
|
+
# gotten any keyword arguments that map to the request.
|
|
1090
|
+
flattened_params = [table_name, row_key, mutations, app_profile_id]
|
|
1091
|
+
has_flattened_params = (
|
|
1092
|
+
len([param for param in flattened_params if param is not None]) > 0
|
|
1093
|
+
)
|
|
1094
|
+
if request is not None and has_flattened_params:
|
|
1095
|
+
raise ValueError(
|
|
1096
|
+
"If the `request` argument is set, then none of "
|
|
1097
|
+
"the individual field arguments should be set."
|
|
1098
|
+
)
|
|
1099
|
+
|
|
1100
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
1101
|
+
# there are no flattened fields), or create one.
|
|
1102
|
+
if not isinstance(request, bigtable.MutateRowRequest):
|
|
1103
|
+
request = bigtable.MutateRowRequest(request)
|
|
1104
|
+
# If we have keyword arguments corresponding to fields on the
|
|
1105
|
+
# request, apply these.
|
|
1106
|
+
if table_name is not None:
|
|
1107
|
+
request.table_name = table_name
|
|
1108
|
+
if row_key is not None:
|
|
1109
|
+
request.row_key = row_key
|
|
1110
|
+
if mutations is not None:
|
|
1111
|
+
request.mutations = mutations
|
|
1112
|
+
if app_profile_id is not None:
|
|
1113
|
+
request.app_profile_id = app_profile_id
|
|
1114
|
+
|
|
1115
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
1116
|
+
# and friendly error handling.
|
|
1117
|
+
rpc = self._transport._wrapped_methods[self._transport.mutate_row]
|
|
1118
|
+
|
|
1119
|
+
header_params = {}
|
|
1120
|
+
|
|
1121
|
+
routing_param_regex = re.compile(
|
|
1122
|
+
"^(?P<table_name>projects/[^/]+/instances/[^/]+/tables/[^/]+)$"
|
|
1123
|
+
)
|
|
1124
|
+
regex_match = routing_param_regex.match(request.table_name)
|
|
1125
|
+
if regex_match and regex_match.group("table_name"):
|
|
1126
|
+
header_params["table_name"] = regex_match.group("table_name")
|
|
1127
|
+
|
|
1128
|
+
if request.app_profile_id:
|
|
1129
|
+
header_params["app_profile_id"] = request.app_profile_id
|
|
1130
|
+
|
|
1131
|
+
routing_param_regex = re.compile(
|
|
1132
|
+
"^(?P<authorized_view_name>projects/[^/]+/instances/[^/]+/tables/[^/]+/authorizedViews/[^/]+)$"
|
|
1133
|
+
)
|
|
1134
|
+
regex_match = routing_param_regex.match(request.authorized_view_name)
|
|
1135
|
+
if regex_match and regex_match.group("authorized_view_name"):
|
|
1136
|
+
header_params["authorized_view_name"] = regex_match.group(
|
|
1137
|
+
"authorized_view_name"
|
|
1138
|
+
)
|
|
1139
|
+
|
|
1140
|
+
if header_params:
|
|
1141
|
+
metadata = tuple(metadata) + (
|
|
1142
|
+
gapic_v1.routing_header.to_grpc_metadata(header_params),
|
|
1143
|
+
)
|
|
1144
|
+
|
|
1145
|
+
# Validate the universe domain.
|
|
1146
|
+
self._validate_universe_domain()
|
|
1147
|
+
|
|
1148
|
+
# Send the request.
|
|
1149
|
+
response = rpc(
|
|
1150
|
+
request,
|
|
1151
|
+
retry=retry,
|
|
1152
|
+
timeout=timeout,
|
|
1153
|
+
metadata=metadata,
|
|
1154
|
+
)
|
|
1155
|
+
|
|
1156
|
+
# Done; return the response.
|
|
1157
|
+
return response
|
|
1158
|
+
|
|
1159
|
+
def mutate_rows(
|
|
1160
|
+
self,
|
|
1161
|
+
request: Optional[Union[bigtable.MutateRowsRequest, dict]] = None,
|
|
1162
|
+
*,
|
|
1163
|
+
table_name: Optional[str] = None,
|
|
1164
|
+
entries: Optional[MutableSequence[bigtable.MutateRowsRequest.Entry]] = None,
|
|
1165
|
+
app_profile_id: Optional[str] = None,
|
|
1166
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
1167
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
1168
|
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
|
1169
|
+
) -> Iterable[bigtable.MutateRowsResponse]:
|
|
1170
|
+
r"""Mutates multiple rows in a batch. Each individual row
|
|
1171
|
+
is mutated atomically as in MutateRow, but the entire
|
|
1172
|
+
batch is not executed atomically.
|
|
1173
|
+
|
|
1174
|
+
Args:
|
|
1175
|
+
request (Union[google.cloud.bigtable_v2.types.MutateRowsRequest, dict]):
|
|
1176
|
+
The request object. Request message for
|
|
1177
|
+
BigtableService.MutateRows.
|
|
1178
|
+
table_name (str):
|
|
1179
|
+
Optional. The unique name of the table to which the
|
|
1180
|
+
mutations should be applied.
|
|
1181
|
+
|
|
1182
|
+
Values are of the form
|
|
1183
|
+
``projects/<project>/instances/<instance>/tables/<table>``.
|
|
1184
|
+
|
|
1185
|
+
This corresponds to the ``table_name`` field
|
|
1186
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1187
|
+
should not be set.
|
|
1188
|
+
entries (MutableSequence[google.cloud.bigtable_v2.types.MutateRowsRequest.Entry]):
|
|
1189
|
+
Required. The row keys and
|
|
1190
|
+
corresponding mutations to be applied in
|
|
1191
|
+
bulk. Each entry is applied as an atomic
|
|
1192
|
+
mutation, but the entries may be applied
|
|
1193
|
+
in arbitrary order (even between entries
|
|
1194
|
+
for the same row). At least one entry
|
|
1195
|
+
must be specified, and in total the
|
|
1196
|
+
entries can contain at most 100000
|
|
1197
|
+
mutations.
|
|
1198
|
+
|
|
1199
|
+
This corresponds to the ``entries`` field
|
|
1200
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1201
|
+
should not be set.
|
|
1202
|
+
app_profile_id (str):
|
|
1203
|
+
This value specifies routing for
|
|
1204
|
+
replication. If not specified, the
|
|
1205
|
+
"default" application profile will be
|
|
1206
|
+
used.
|
|
1207
|
+
|
|
1208
|
+
This corresponds to the ``app_profile_id`` field
|
|
1209
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1210
|
+
should not be set.
|
|
1211
|
+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
|
|
1212
|
+
should be retried.
|
|
1213
|
+
timeout (float): The timeout for this request.
|
|
1214
|
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
|
1215
|
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
|
1216
|
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
|
1217
|
+
be of type `bytes`.
|
|
1218
|
+
|
|
1219
|
+
Returns:
|
|
1220
|
+
Iterable[google.cloud.bigtable_v2.types.MutateRowsResponse]:
|
|
1221
|
+
Response message for
|
|
1222
|
+
BigtableService.MutateRows.
|
|
1223
|
+
|
|
1224
|
+
"""
|
|
1225
|
+
# Create or coerce a protobuf request object.
|
|
1226
|
+
# - Quick check: If we got a request object, we should *not* have
|
|
1227
|
+
# gotten any keyword arguments that map to the request.
|
|
1228
|
+
flattened_params = [table_name, entries, app_profile_id]
|
|
1229
|
+
has_flattened_params = (
|
|
1230
|
+
len([param for param in flattened_params if param is not None]) > 0
|
|
1231
|
+
)
|
|
1232
|
+
if request is not None and has_flattened_params:
|
|
1233
|
+
raise ValueError(
|
|
1234
|
+
"If the `request` argument is set, then none of "
|
|
1235
|
+
"the individual field arguments should be set."
|
|
1236
|
+
)
|
|
1237
|
+
|
|
1238
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
1239
|
+
# there are no flattened fields), or create one.
|
|
1240
|
+
if not isinstance(request, bigtable.MutateRowsRequest):
|
|
1241
|
+
request = bigtable.MutateRowsRequest(request)
|
|
1242
|
+
# If we have keyword arguments corresponding to fields on the
|
|
1243
|
+
# request, apply these.
|
|
1244
|
+
if table_name is not None:
|
|
1245
|
+
request.table_name = table_name
|
|
1246
|
+
if entries is not None:
|
|
1247
|
+
request.entries = entries
|
|
1248
|
+
if app_profile_id is not None:
|
|
1249
|
+
request.app_profile_id = app_profile_id
|
|
1250
|
+
|
|
1251
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
1252
|
+
# and friendly error handling.
|
|
1253
|
+
rpc = self._transport._wrapped_methods[self._transport.mutate_rows]
|
|
1254
|
+
|
|
1255
|
+
header_params = {}
|
|
1256
|
+
|
|
1257
|
+
routing_param_regex = re.compile(
|
|
1258
|
+
"^(?P<table_name>projects/[^/]+/instances/[^/]+/tables/[^/]+)$"
|
|
1259
|
+
)
|
|
1260
|
+
regex_match = routing_param_regex.match(request.table_name)
|
|
1261
|
+
if regex_match and regex_match.group("table_name"):
|
|
1262
|
+
header_params["table_name"] = regex_match.group("table_name")
|
|
1263
|
+
|
|
1264
|
+
if request.app_profile_id:
|
|
1265
|
+
header_params["app_profile_id"] = request.app_profile_id
|
|
1266
|
+
|
|
1267
|
+
routing_param_regex = re.compile(
|
|
1268
|
+
"^(?P<authorized_view_name>projects/[^/]+/instances/[^/]+/tables/[^/]+/authorizedViews/[^/]+)$"
|
|
1269
|
+
)
|
|
1270
|
+
regex_match = routing_param_regex.match(request.authorized_view_name)
|
|
1271
|
+
if regex_match and regex_match.group("authorized_view_name"):
|
|
1272
|
+
header_params["authorized_view_name"] = regex_match.group(
|
|
1273
|
+
"authorized_view_name"
|
|
1274
|
+
)
|
|
1275
|
+
|
|
1276
|
+
if header_params:
|
|
1277
|
+
metadata = tuple(metadata) + (
|
|
1278
|
+
gapic_v1.routing_header.to_grpc_metadata(header_params),
|
|
1279
|
+
)
|
|
1280
|
+
|
|
1281
|
+
# Validate the universe domain.
|
|
1282
|
+
self._validate_universe_domain()
|
|
1283
|
+
|
|
1284
|
+
# Send the request.
|
|
1285
|
+
response = rpc(
|
|
1286
|
+
request,
|
|
1287
|
+
retry=retry,
|
|
1288
|
+
timeout=timeout,
|
|
1289
|
+
metadata=metadata,
|
|
1290
|
+
)
|
|
1291
|
+
|
|
1292
|
+
# Done; return the response.
|
|
1293
|
+
return response
|
|
1294
|
+
|
|
1295
|
+
def check_and_mutate_row(
|
|
1296
|
+
self,
|
|
1297
|
+
request: Optional[Union[bigtable.CheckAndMutateRowRequest, dict]] = None,
|
|
1298
|
+
*,
|
|
1299
|
+
table_name: Optional[str] = None,
|
|
1300
|
+
row_key: Optional[bytes] = None,
|
|
1301
|
+
predicate_filter: Optional[data.RowFilter] = None,
|
|
1302
|
+
true_mutations: Optional[MutableSequence[data.Mutation]] = None,
|
|
1303
|
+
false_mutations: Optional[MutableSequence[data.Mutation]] = None,
|
|
1304
|
+
app_profile_id: Optional[str] = None,
|
|
1305
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
1306
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
1307
|
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
|
1308
|
+
) -> bigtable.CheckAndMutateRowResponse:
|
|
1309
|
+
r"""Mutates a row atomically based on the output of a
|
|
1310
|
+
predicate Reader filter.
|
|
1311
|
+
|
|
1312
|
+
Args:
|
|
1313
|
+
request (Union[google.cloud.bigtable_v2.types.CheckAndMutateRowRequest, dict]):
|
|
1314
|
+
The request object. Request message for
|
|
1315
|
+
Bigtable.CheckAndMutateRow.
|
|
1316
|
+
table_name (str):
|
|
1317
|
+
Optional. The unique name of the table to which the
|
|
1318
|
+
conditional mutation should be applied.
|
|
1319
|
+
|
|
1320
|
+
Values are of the form
|
|
1321
|
+
``projects/<project>/instances/<instance>/tables/<table>``.
|
|
1322
|
+
|
|
1323
|
+
This corresponds to the ``table_name`` field
|
|
1324
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1325
|
+
should not be set.
|
|
1326
|
+
row_key (bytes):
|
|
1327
|
+
Required. The key of the row to which
|
|
1328
|
+
the conditional mutation should be
|
|
1329
|
+
applied.
|
|
1330
|
+
|
|
1331
|
+
This corresponds to the ``row_key`` field
|
|
1332
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1333
|
+
should not be set.
|
|
1334
|
+
predicate_filter (google.cloud.bigtable_v2.types.RowFilter):
|
|
1335
|
+
The filter to be applied to the contents of the
|
|
1336
|
+
specified row. Depending on whether or not any results
|
|
1337
|
+
are yielded, either ``true_mutations`` or
|
|
1338
|
+
``false_mutations`` will be executed. If unset, checks
|
|
1339
|
+
that the row contains any values at all.
|
|
1340
|
+
|
|
1341
|
+
This corresponds to the ``predicate_filter`` field
|
|
1342
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1343
|
+
should not be set.
|
|
1344
|
+
true_mutations (MutableSequence[google.cloud.bigtable_v2.types.Mutation]):
|
|
1345
|
+
Changes to be atomically applied to the specified row if
|
|
1346
|
+
``predicate_filter`` yields at least one cell when
|
|
1347
|
+
applied to ``row_key``. Entries are applied in order,
|
|
1348
|
+
meaning that earlier mutations can be masked by later
|
|
1349
|
+
ones. Must contain at least one entry if
|
|
1350
|
+
``false_mutations`` is empty, and at most 100000.
|
|
1351
|
+
|
|
1352
|
+
This corresponds to the ``true_mutations`` field
|
|
1353
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1354
|
+
should not be set.
|
|
1355
|
+
false_mutations (MutableSequence[google.cloud.bigtable_v2.types.Mutation]):
|
|
1356
|
+
Changes to be atomically applied to the specified row if
|
|
1357
|
+
``predicate_filter`` does not yield any cells when
|
|
1358
|
+
applied to ``row_key``. Entries are applied in order,
|
|
1359
|
+
meaning that earlier mutations can be masked by later
|
|
1360
|
+
ones. Must contain at least one entry if
|
|
1361
|
+
``true_mutations`` is empty, and at most 100000.
|
|
1362
|
+
|
|
1363
|
+
This corresponds to the ``false_mutations`` field
|
|
1364
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1365
|
+
should not be set.
|
|
1366
|
+
app_profile_id (str):
|
|
1367
|
+
This value specifies routing for
|
|
1368
|
+
replication. If not specified, the
|
|
1369
|
+
"default" application profile will be
|
|
1370
|
+
used.
|
|
1371
|
+
|
|
1372
|
+
This corresponds to the ``app_profile_id`` field
|
|
1373
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1374
|
+
should not be set.
|
|
1375
|
+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
|
|
1376
|
+
should be retried.
|
|
1377
|
+
timeout (float): The timeout for this request.
|
|
1378
|
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
|
1379
|
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
|
1380
|
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
|
1381
|
+
be of type `bytes`.
|
|
1382
|
+
|
|
1383
|
+
Returns:
|
|
1384
|
+
google.cloud.bigtable_v2.types.CheckAndMutateRowResponse:
|
|
1385
|
+
Response message for
|
|
1386
|
+
Bigtable.CheckAndMutateRow.
|
|
1387
|
+
|
|
1388
|
+
"""
|
|
1389
|
+
# Create or coerce a protobuf request object.
|
|
1390
|
+
# - Quick check: If we got a request object, we should *not* have
|
|
1391
|
+
# gotten any keyword arguments that map to the request.
|
|
1392
|
+
flattened_params = [
|
|
1393
|
+
table_name,
|
|
1394
|
+
row_key,
|
|
1395
|
+
predicate_filter,
|
|
1396
|
+
true_mutations,
|
|
1397
|
+
false_mutations,
|
|
1398
|
+
app_profile_id,
|
|
1399
|
+
]
|
|
1400
|
+
has_flattened_params = (
|
|
1401
|
+
len([param for param in flattened_params if param is not None]) > 0
|
|
1402
|
+
)
|
|
1403
|
+
if request is not None and has_flattened_params:
|
|
1404
|
+
raise ValueError(
|
|
1405
|
+
"If the `request` argument is set, then none of "
|
|
1406
|
+
"the individual field arguments should be set."
|
|
1407
|
+
)
|
|
1408
|
+
|
|
1409
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
1410
|
+
# there are no flattened fields), or create one.
|
|
1411
|
+
if not isinstance(request, bigtable.CheckAndMutateRowRequest):
|
|
1412
|
+
request = bigtable.CheckAndMutateRowRequest(request)
|
|
1413
|
+
# If we have keyword arguments corresponding to fields on the
|
|
1414
|
+
# request, apply these.
|
|
1415
|
+
if table_name is not None:
|
|
1416
|
+
request.table_name = table_name
|
|
1417
|
+
if row_key is not None:
|
|
1418
|
+
request.row_key = row_key
|
|
1419
|
+
if predicate_filter is not None:
|
|
1420
|
+
request.predicate_filter = predicate_filter
|
|
1421
|
+
if true_mutations is not None:
|
|
1422
|
+
request.true_mutations = true_mutations
|
|
1423
|
+
if false_mutations is not None:
|
|
1424
|
+
request.false_mutations = false_mutations
|
|
1425
|
+
if app_profile_id is not None:
|
|
1426
|
+
request.app_profile_id = app_profile_id
|
|
1427
|
+
|
|
1428
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
1429
|
+
# and friendly error handling.
|
|
1430
|
+
rpc = self._transport._wrapped_methods[self._transport.check_and_mutate_row]
|
|
1431
|
+
|
|
1432
|
+
header_params = {}
|
|
1433
|
+
|
|
1434
|
+
routing_param_regex = re.compile(
|
|
1435
|
+
"^(?P<table_name>projects/[^/]+/instances/[^/]+/tables/[^/]+)$"
|
|
1436
|
+
)
|
|
1437
|
+
regex_match = routing_param_regex.match(request.table_name)
|
|
1438
|
+
if regex_match and regex_match.group("table_name"):
|
|
1439
|
+
header_params["table_name"] = regex_match.group("table_name")
|
|
1440
|
+
|
|
1441
|
+
if request.app_profile_id:
|
|
1442
|
+
header_params["app_profile_id"] = request.app_profile_id
|
|
1443
|
+
|
|
1444
|
+
routing_param_regex = re.compile(
|
|
1445
|
+
"^(?P<authorized_view_name>projects/[^/]+/instances/[^/]+/tables/[^/]+/authorizedViews/[^/]+)$"
|
|
1446
|
+
)
|
|
1447
|
+
regex_match = routing_param_regex.match(request.authorized_view_name)
|
|
1448
|
+
if regex_match and regex_match.group("authorized_view_name"):
|
|
1449
|
+
header_params["authorized_view_name"] = regex_match.group(
|
|
1450
|
+
"authorized_view_name"
|
|
1451
|
+
)
|
|
1452
|
+
|
|
1453
|
+
if header_params:
|
|
1454
|
+
metadata = tuple(metadata) + (
|
|
1455
|
+
gapic_v1.routing_header.to_grpc_metadata(header_params),
|
|
1456
|
+
)
|
|
1457
|
+
|
|
1458
|
+
# Validate the universe domain.
|
|
1459
|
+
self._validate_universe_domain()
|
|
1460
|
+
|
|
1461
|
+
# Send the request.
|
|
1462
|
+
response = rpc(
|
|
1463
|
+
request,
|
|
1464
|
+
retry=retry,
|
|
1465
|
+
timeout=timeout,
|
|
1466
|
+
metadata=metadata,
|
|
1467
|
+
)
|
|
1468
|
+
|
|
1469
|
+
# Done; return the response.
|
|
1470
|
+
return response
|
|
1471
|
+
|
|
1472
|
+
def ping_and_warm(
|
|
1473
|
+
self,
|
|
1474
|
+
request: Optional[Union[bigtable.PingAndWarmRequest, dict]] = None,
|
|
1475
|
+
*,
|
|
1476
|
+
name: Optional[str] = None,
|
|
1477
|
+
app_profile_id: Optional[str] = None,
|
|
1478
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
1479
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
1480
|
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
|
1481
|
+
) -> bigtable.PingAndWarmResponse:
|
|
1482
|
+
r"""Warm up associated instance metadata for this
|
|
1483
|
+
connection. This call is not required but may be useful
|
|
1484
|
+
for connection keep-alive.
|
|
1485
|
+
|
|
1486
|
+
Args:
|
|
1487
|
+
request (Union[google.cloud.bigtable_v2.types.PingAndWarmRequest, dict]):
|
|
1488
|
+
The request object. Request message for client connection
|
|
1489
|
+
keep-alive and warming.
|
|
1490
|
+
name (str):
|
|
1491
|
+
Required. The unique name of the instance to check
|
|
1492
|
+
permissions for as well as respond. Values are of the
|
|
1493
|
+
form ``projects/<project>/instances/<instance>``.
|
|
1494
|
+
|
|
1495
|
+
This corresponds to the ``name`` field
|
|
1496
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1497
|
+
should not be set.
|
|
1498
|
+
app_profile_id (str):
|
|
1499
|
+
This value specifies routing for
|
|
1500
|
+
replication. If not specified, the
|
|
1501
|
+
"default" application profile will be
|
|
1502
|
+
used.
|
|
1503
|
+
|
|
1504
|
+
This corresponds to the ``app_profile_id`` field
|
|
1505
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1506
|
+
should not be set.
|
|
1507
|
+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
|
|
1508
|
+
should be retried.
|
|
1509
|
+
timeout (float): The timeout for this request.
|
|
1510
|
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
|
1511
|
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
|
1512
|
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
|
1513
|
+
be of type `bytes`.
|
|
1514
|
+
|
|
1515
|
+
Returns:
|
|
1516
|
+
google.cloud.bigtable_v2.types.PingAndWarmResponse:
|
|
1517
|
+
Response message for
|
|
1518
|
+
Bigtable.PingAndWarm connection
|
|
1519
|
+
keepalive and warming.
|
|
1520
|
+
|
|
1521
|
+
"""
|
|
1522
|
+
# Create or coerce a protobuf request object.
|
|
1523
|
+
# - Quick check: If we got a request object, we should *not* have
|
|
1524
|
+
# gotten any keyword arguments that map to the request.
|
|
1525
|
+
flattened_params = [name, app_profile_id]
|
|
1526
|
+
has_flattened_params = (
|
|
1527
|
+
len([param for param in flattened_params if param is not None]) > 0
|
|
1528
|
+
)
|
|
1529
|
+
if request is not None and has_flattened_params:
|
|
1530
|
+
raise ValueError(
|
|
1531
|
+
"If the `request` argument is set, then none of "
|
|
1532
|
+
"the individual field arguments should be set."
|
|
1533
|
+
)
|
|
1534
|
+
|
|
1535
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
1536
|
+
# there are no flattened fields), or create one.
|
|
1537
|
+
if not isinstance(request, bigtable.PingAndWarmRequest):
|
|
1538
|
+
request = bigtable.PingAndWarmRequest(request)
|
|
1539
|
+
# If we have keyword arguments corresponding to fields on the
|
|
1540
|
+
# request, apply these.
|
|
1541
|
+
if name is not None:
|
|
1542
|
+
request.name = name
|
|
1543
|
+
if app_profile_id is not None:
|
|
1544
|
+
request.app_profile_id = app_profile_id
|
|
1545
|
+
|
|
1546
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
1547
|
+
# and friendly error handling.
|
|
1548
|
+
rpc = self._transport._wrapped_methods[self._transport.ping_and_warm]
|
|
1549
|
+
|
|
1550
|
+
header_params = {}
|
|
1551
|
+
|
|
1552
|
+
routing_param_regex = re.compile("^(?P<name>projects/[^/]+/instances/[^/]+)$")
|
|
1553
|
+
regex_match = routing_param_regex.match(request.name)
|
|
1554
|
+
if regex_match and regex_match.group("name"):
|
|
1555
|
+
header_params["name"] = regex_match.group("name")
|
|
1556
|
+
|
|
1557
|
+
if request.app_profile_id:
|
|
1558
|
+
header_params["app_profile_id"] = request.app_profile_id
|
|
1559
|
+
|
|
1560
|
+
if header_params:
|
|
1561
|
+
metadata = tuple(metadata) + (
|
|
1562
|
+
gapic_v1.routing_header.to_grpc_metadata(header_params),
|
|
1563
|
+
)
|
|
1564
|
+
|
|
1565
|
+
# Validate the universe domain.
|
|
1566
|
+
self._validate_universe_domain()
|
|
1567
|
+
|
|
1568
|
+
# Send the request.
|
|
1569
|
+
response = rpc(
|
|
1570
|
+
request,
|
|
1571
|
+
retry=retry,
|
|
1572
|
+
timeout=timeout,
|
|
1573
|
+
metadata=metadata,
|
|
1574
|
+
)
|
|
1575
|
+
|
|
1576
|
+
# Done; return the response.
|
|
1577
|
+
return response
|
|
1578
|
+
|
|
1579
|
+
def read_modify_write_row(
|
|
1580
|
+
self,
|
|
1581
|
+
request: Optional[Union[bigtable.ReadModifyWriteRowRequest, dict]] = None,
|
|
1582
|
+
*,
|
|
1583
|
+
table_name: Optional[str] = None,
|
|
1584
|
+
row_key: Optional[bytes] = None,
|
|
1585
|
+
rules: Optional[MutableSequence[data.ReadModifyWriteRule]] = None,
|
|
1586
|
+
app_profile_id: Optional[str] = None,
|
|
1587
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
1588
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
1589
|
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
|
1590
|
+
) -> bigtable.ReadModifyWriteRowResponse:
|
|
1591
|
+
r"""Modifies a row atomically on the server. The method
|
|
1592
|
+
reads the latest existing timestamp and value from the
|
|
1593
|
+
specified columns and writes a new entry based on
|
|
1594
|
+
pre-defined read/modify/write rules. The new value for
|
|
1595
|
+
the timestamp is the greater of the existing timestamp
|
|
1596
|
+
or the current server time. The method returns the new
|
|
1597
|
+
contents of all modified cells.
|
|
1598
|
+
|
|
1599
|
+
Args:
|
|
1600
|
+
request (Union[google.cloud.bigtable_v2.types.ReadModifyWriteRowRequest, dict]):
|
|
1601
|
+
The request object. Request message for
|
|
1602
|
+
Bigtable.ReadModifyWriteRow.
|
|
1603
|
+
table_name (str):
|
|
1604
|
+
Optional. The unique name of the table to which the
|
|
1605
|
+
read/modify/write rules should be applied.
|
|
1606
|
+
|
|
1607
|
+
Values are of the form
|
|
1608
|
+
``projects/<project>/instances/<instance>/tables/<table>``.
|
|
1609
|
+
|
|
1610
|
+
This corresponds to the ``table_name`` field
|
|
1611
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1612
|
+
should not be set.
|
|
1613
|
+
row_key (bytes):
|
|
1614
|
+
Required. The key of the row to which
|
|
1615
|
+
the read/modify/write rules should be
|
|
1616
|
+
applied.
|
|
1617
|
+
|
|
1618
|
+
This corresponds to the ``row_key`` field
|
|
1619
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1620
|
+
should not be set.
|
|
1621
|
+
rules (MutableSequence[google.cloud.bigtable_v2.types.ReadModifyWriteRule]):
|
|
1622
|
+
Required. Rules specifying how the
|
|
1623
|
+
specified row's contents are to be
|
|
1624
|
+
transformed into writes. Entries are
|
|
1625
|
+
applied in order, meaning that earlier
|
|
1626
|
+
rules will affect the results of later
|
|
1627
|
+
ones.
|
|
1628
|
+
|
|
1629
|
+
This corresponds to the ``rules`` field
|
|
1630
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1631
|
+
should not be set.
|
|
1632
|
+
app_profile_id (str):
|
|
1633
|
+
This value specifies routing for
|
|
1634
|
+
replication. If not specified, the
|
|
1635
|
+
"default" application profile will be
|
|
1636
|
+
used.
|
|
1637
|
+
|
|
1638
|
+
This corresponds to the ``app_profile_id`` field
|
|
1639
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1640
|
+
should not be set.
|
|
1641
|
+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
|
|
1642
|
+
should be retried.
|
|
1643
|
+
timeout (float): The timeout for this request.
|
|
1644
|
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
|
1645
|
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
|
1646
|
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
|
1647
|
+
be of type `bytes`.
|
|
1648
|
+
|
|
1649
|
+
Returns:
|
|
1650
|
+
google.cloud.bigtable_v2.types.ReadModifyWriteRowResponse:
|
|
1651
|
+
Response message for
|
|
1652
|
+
Bigtable.ReadModifyWriteRow.
|
|
1653
|
+
|
|
1654
|
+
"""
|
|
1655
|
+
# Create or coerce a protobuf request object.
|
|
1656
|
+
# - Quick check: If we got a request object, we should *not* have
|
|
1657
|
+
# gotten any keyword arguments that map to the request.
|
|
1658
|
+
flattened_params = [table_name, row_key, rules, app_profile_id]
|
|
1659
|
+
has_flattened_params = (
|
|
1660
|
+
len([param for param in flattened_params if param is not None]) > 0
|
|
1661
|
+
)
|
|
1662
|
+
if request is not None and has_flattened_params:
|
|
1663
|
+
raise ValueError(
|
|
1664
|
+
"If the `request` argument is set, then none of "
|
|
1665
|
+
"the individual field arguments should be set."
|
|
1666
|
+
)
|
|
1667
|
+
|
|
1668
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
1669
|
+
# there are no flattened fields), or create one.
|
|
1670
|
+
if not isinstance(request, bigtable.ReadModifyWriteRowRequest):
|
|
1671
|
+
request = bigtable.ReadModifyWriteRowRequest(request)
|
|
1672
|
+
# If we have keyword arguments corresponding to fields on the
|
|
1673
|
+
# request, apply these.
|
|
1674
|
+
if table_name is not None:
|
|
1675
|
+
request.table_name = table_name
|
|
1676
|
+
if row_key is not None:
|
|
1677
|
+
request.row_key = row_key
|
|
1678
|
+
if rules is not None:
|
|
1679
|
+
request.rules = rules
|
|
1680
|
+
if app_profile_id is not None:
|
|
1681
|
+
request.app_profile_id = app_profile_id
|
|
1682
|
+
|
|
1683
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
1684
|
+
# and friendly error handling.
|
|
1685
|
+
rpc = self._transport._wrapped_methods[self._transport.read_modify_write_row]
|
|
1686
|
+
|
|
1687
|
+
header_params = {}
|
|
1688
|
+
|
|
1689
|
+
routing_param_regex = re.compile(
|
|
1690
|
+
"^(?P<table_name>projects/[^/]+/instances/[^/]+/tables/[^/]+)$"
|
|
1691
|
+
)
|
|
1692
|
+
regex_match = routing_param_regex.match(request.table_name)
|
|
1693
|
+
if regex_match and regex_match.group("table_name"):
|
|
1694
|
+
header_params["table_name"] = regex_match.group("table_name")
|
|
1695
|
+
|
|
1696
|
+
if request.app_profile_id:
|
|
1697
|
+
header_params["app_profile_id"] = request.app_profile_id
|
|
1698
|
+
|
|
1699
|
+
routing_param_regex = re.compile(
|
|
1700
|
+
"^(?P<authorized_view_name>projects/[^/]+/instances/[^/]+/tables/[^/]+/authorizedViews/[^/]+)$"
|
|
1701
|
+
)
|
|
1702
|
+
regex_match = routing_param_regex.match(request.authorized_view_name)
|
|
1703
|
+
if regex_match and regex_match.group("authorized_view_name"):
|
|
1704
|
+
header_params["authorized_view_name"] = regex_match.group(
|
|
1705
|
+
"authorized_view_name"
|
|
1706
|
+
)
|
|
1707
|
+
|
|
1708
|
+
if header_params:
|
|
1709
|
+
metadata = tuple(metadata) + (
|
|
1710
|
+
gapic_v1.routing_header.to_grpc_metadata(header_params),
|
|
1711
|
+
)
|
|
1712
|
+
|
|
1713
|
+
# Validate the universe domain.
|
|
1714
|
+
self._validate_universe_domain()
|
|
1715
|
+
|
|
1716
|
+
# Send the request.
|
|
1717
|
+
response = rpc(
|
|
1718
|
+
request,
|
|
1719
|
+
retry=retry,
|
|
1720
|
+
timeout=timeout,
|
|
1721
|
+
metadata=metadata,
|
|
1722
|
+
)
|
|
1723
|
+
|
|
1724
|
+
# Done; return the response.
|
|
1725
|
+
return response
|
|
1726
|
+
|
|
1727
|
+
def generate_initial_change_stream_partitions(
|
|
1728
|
+
self,
|
|
1729
|
+
request: Optional[
|
|
1730
|
+
Union[bigtable.GenerateInitialChangeStreamPartitionsRequest, dict]
|
|
1731
|
+
] = None,
|
|
1732
|
+
*,
|
|
1733
|
+
table_name: Optional[str] = None,
|
|
1734
|
+
app_profile_id: Optional[str] = None,
|
|
1735
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
1736
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
1737
|
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
|
1738
|
+
) -> Iterable[bigtable.GenerateInitialChangeStreamPartitionsResponse]:
|
|
1739
|
+
r"""NOTE: This API is intended to be used by Apache Beam BigtableIO.
|
|
1740
|
+
Returns the current list of partitions that make up the table's
|
|
1741
|
+
change stream. The union of partitions will cover the entire
|
|
1742
|
+
keyspace. Partitions can be read with ``ReadChangeStream``.
|
|
1743
|
+
|
|
1744
|
+
Args:
|
|
1745
|
+
request (Union[google.cloud.bigtable_v2.types.GenerateInitialChangeStreamPartitionsRequest, dict]):
|
|
1746
|
+
The request object. NOTE: This API is intended to be used
|
|
1747
|
+
by Apache Beam BigtableIO. Request
|
|
1748
|
+
message for
|
|
1749
|
+
Bigtable.GenerateInitialChangeStreamPartitions.
|
|
1750
|
+
table_name (str):
|
|
1751
|
+
Required. The unique name of the table from which to get
|
|
1752
|
+
change stream partitions. Values are of the form
|
|
1753
|
+
``projects/<project>/instances/<instance>/tables/<table>``.
|
|
1754
|
+
Change streaming must be enabled on the table.
|
|
1755
|
+
|
|
1756
|
+
This corresponds to the ``table_name`` field
|
|
1757
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1758
|
+
should not be set.
|
|
1759
|
+
app_profile_id (str):
|
|
1760
|
+
This value specifies routing for
|
|
1761
|
+
replication. If not specified, the
|
|
1762
|
+
"default" application profile will be
|
|
1763
|
+
used. Single cluster routing must be
|
|
1764
|
+
configured on the profile.
|
|
1765
|
+
|
|
1766
|
+
This corresponds to the ``app_profile_id`` field
|
|
1767
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1768
|
+
should not be set.
|
|
1769
|
+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
|
|
1770
|
+
should be retried.
|
|
1771
|
+
timeout (float): The timeout for this request.
|
|
1772
|
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
|
1773
|
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
|
1774
|
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
|
1775
|
+
be of type `bytes`.
|
|
1776
|
+
|
|
1777
|
+
Returns:
|
|
1778
|
+
Iterable[google.cloud.bigtable_v2.types.GenerateInitialChangeStreamPartitionsResponse]:
|
|
1779
|
+
NOTE: This API is intended to be used
|
|
1780
|
+
by Apache Beam BigtableIO. Response
|
|
1781
|
+
message for
|
|
1782
|
+
Bigtable.GenerateInitialChangeStreamPartitions.
|
|
1783
|
+
|
|
1784
|
+
"""
|
|
1785
|
+
# Create or coerce a protobuf request object.
|
|
1786
|
+
# - Quick check: If we got a request object, we should *not* have
|
|
1787
|
+
# gotten any keyword arguments that map to the request.
|
|
1788
|
+
flattened_params = [table_name, app_profile_id]
|
|
1789
|
+
has_flattened_params = (
|
|
1790
|
+
len([param for param in flattened_params if param is not None]) > 0
|
|
1791
|
+
)
|
|
1792
|
+
if request is not None and has_flattened_params:
|
|
1793
|
+
raise ValueError(
|
|
1794
|
+
"If the `request` argument is set, then none of "
|
|
1795
|
+
"the individual field arguments should be set."
|
|
1796
|
+
)
|
|
1797
|
+
|
|
1798
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
1799
|
+
# there are no flattened fields), or create one.
|
|
1800
|
+
if not isinstance(
|
|
1801
|
+
request, bigtable.GenerateInitialChangeStreamPartitionsRequest
|
|
1802
|
+
):
|
|
1803
|
+
request = bigtable.GenerateInitialChangeStreamPartitionsRequest(request)
|
|
1804
|
+
# If we have keyword arguments corresponding to fields on the
|
|
1805
|
+
# request, apply these.
|
|
1806
|
+
if table_name is not None:
|
|
1807
|
+
request.table_name = table_name
|
|
1808
|
+
if app_profile_id is not None:
|
|
1809
|
+
request.app_profile_id = app_profile_id
|
|
1810
|
+
|
|
1811
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
1812
|
+
# and friendly error handling.
|
|
1813
|
+
rpc = self._transport._wrapped_methods[
|
|
1814
|
+
self._transport.generate_initial_change_stream_partitions
|
|
1815
|
+
]
|
|
1816
|
+
|
|
1817
|
+
# Certain fields should be provided within the metadata header;
|
|
1818
|
+
# add these here.
|
|
1819
|
+
metadata = tuple(metadata) + (
|
|
1820
|
+
gapic_v1.routing_header.to_grpc_metadata(
|
|
1821
|
+
(("table_name", request.table_name),)
|
|
1822
|
+
),
|
|
1823
|
+
)
|
|
1824
|
+
|
|
1825
|
+
# Validate the universe domain.
|
|
1826
|
+
self._validate_universe_domain()
|
|
1827
|
+
|
|
1828
|
+
# Send the request.
|
|
1829
|
+
response = rpc(
|
|
1830
|
+
request,
|
|
1831
|
+
retry=retry,
|
|
1832
|
+
timeout=timeout,
|
|
1833
|
+
metadata=metadata,
|
|
1834
|
+
)
|
|
1835
|
+
|
|
1836
|
+
# Done; return the response.
|
|
1837
|
+
return response
|
|
1838
|
+
|
|
1839
|
+
def read_change_stream(
|
|
1840
|
+
self,
|
|
1841
|
+
request: Optional[Union[bigtable.ReadChangeStreamRequest, dict]] = None,
|
|
1842
|
+
*,
|
|
1843
|
+
table_name: Optional[str] = None,
|
|
1844
|
+
app_profile_id: Optional[str] = None,
|
|
1845
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
1846
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
1847
|
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
|
1848
|
+
) -> Iterable[bigtable.ReadChangeStreamResponse]:
|
|
1849
|
+
r"""NOTE: This API is intended to be used by Apache Beam
|
|
1850
|
+
BigtableIO. Reads changes from a table's change stream.
|
|
1851
|
+
Changes will reflect both user-initiated mutations and
|
|
1852
|
+
mutations that are caused by garbage collection.
|
|
1853
|
+
|
|
1854
|
+
Args:
|
|
1855
|
+
request (Union[google.cloud.bigtable_v2.types.ReadChangeStreamRequest, dict]):
|
|
1856
|
+
The request object. NOTE: This API is intended to be used
|
|
1857
|
+
by Apache Beam BigtableIO. Request
|
|
1858
|
+
message for Bigtable.ReadChangeStream.
|
|
1859
|
+
table_name (str):
|
|
1860
|
+
Required. The unique name of the table from which to
|
|
1861
|
+
read a change stream. Values are of the form
|
|
1862
|
+
``projects/<project>/instances/<instance>/tables/<table>``.
|
|
1863
|
+
Change streaming must be enabled on the table.
|
|
1864
|
+
|
|
1865
|
+
This corresponds to the ``table_name`` field
|
|
1866
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1867
|
+
should not be set.
|
|
1868
|
+
app_profile_id (str):
|
|
1869
|
+
This value specifies routing for
|
|
1870
|
+
replication. If not specified, the
|
|
1871
|
+
"default" application profile will be
|
|
1872
|
+
used. Single cluster routing must be
|
|
1873
|
+
configured on the profile.
|
|
1874
|
+
|
|
1875
|
+
This corresponds to the ``app_profile_id`` field
|
|
1876
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1877
|
+
should not be set.
|
|
1878
|
+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
|
|
1879
|
+
should be retried.
|
|
1880
|
+
timeout (float): The timeout for this request.
|
|
1881
|
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
|
1882
|
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
|
1883
|
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
|
1884
|
+
be of type `bytes`.
|
|
1885
|
+
|
|
1886
|
+
Returns:
|
|
1887
|
+
Iterable[google.cloud.bigtable_v2.types.ReadChangeStreamResponse]:
|
|
1888
|
+
NOTE: This API is intended to be used
|
|
1889
|
+
by Apache Beam BigtableIO. Response
|
|
1890
|
+
message for Bigtable.ReadChangeStream.
|
|
1891
|
+
|
|
1892
|
+
"""
|
|
1893
|
+
# Create or coerce a protobuf request object.
|
|
1894
|
+
# - Quick check: If we got a request object, we should *not* have
|
|
1895
|
+
# gotten any keyword arguments that map to the request.
|
|
1896
|
+
flattened_params = [table_name, app_profile_id]
|
|
1897
|
+
has_flattened_params = (
|
|
1898
|
+
len([param for param in flattened_params if param is not None]) > 0
|
|
1899
|
+
)
|
|
1900
|
+
if request is not None and has_flattened_params:
|
|
1901
|
+
raise ValueError(
|
|
1902
|
+
"If the `request` argument is set, then none of "
|
|
1903
|
+
"the individual field arguments should be set."
|
|
1904
|
+
)
|
|
1905
|
+
|
|
1906
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
1907
|
+
# there are no flattened fields), or create one.
|
|
1908
|
+
if not isinstance(request, bigtable.ReadChangeStreamRequest):
|
|
1909
|
+
request = bigtable.ReadChangeStreamRequest(request)
|
|
1910
|
+
# If we have keyword arguments corresponding to fields on the
|
|
1911
|
+
# request, apply these.
|
|
1912
|
+
if table_name is not None:
|
|
1913
|
+
request.table_name = table_name
|
|
1914
|
+
if app_profile_id is not None:
|
|
1915
|
+
request.app_profile_id = app_profile_id
|
|
1916
|
+
|
|
1917
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
1918
|
+
# and friendly error handling.
|
|
1919
|
+
rpc = self._transport._wrapped_methods[self._transport.read_change_stream]
|
|
1920
|
+
|
|
1921
|
+
# Certain fields should be provided within the metadata header;
|
|
1922
|
+
# add these here.
|
|
1923
|
+
metadata = tuple(metadata) + (
|
|
1924
|
+
gapic_v1.routing_header.to_grpc_metadata(
|
|
1925
|
+
(("table_name", request.table_name),)
|
|
1926
|
+
),
|
|
1927
|
+
)
|
|
1928
|
+
|
|
1929
|
+
# Validate the universe domain.
|
|
1930
|
+
self._validate_universe_domain()
|
|
1931
|
+
|
|
1932
|
+
# Send the request.
|
|
1933
|
+
response = rpc(
|
|
1934
|
+
request,
|
|
1935
|
+
retry=retry,
|
|
1936
|
+
timeout=timeout,
|
|
1937
|
+
metadata=metadata,
|
|
1938
|
+
)
|
|
1939
|
+
|
|
1940
|
+
# Done; return the response.
|
|
1941
|
+
return response
|
|
1942
|
+
|
|
1943
|
+
def prepare_query(
|
|
1944
|
+
self,
|
|
1945
|
+
request: Optional[Union[bigtable.PrepareQueryRequest, dict]] = None,
|
|
1946
|
+
*,
|
|
1947
|
+
instance_name: Optional[str] = None,
|
|
1948
|
+
query: Optional[str] = None,
|
|
1949
|
+
app_profile_id: Optional[str] = None,
|
|
1950
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
1951
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
1952
|
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
|
1953
|
+
) -> bigtable.PrepareQueryResponse:
|
|
1954
|
+
r"""Prepares a GoogleSQL query for execution on a
|
|
1955
|
+
particular Bigtable instance.
|
|
1956
|
+
|
|
1957
|
+
Args:
|
|
1958
|
+
request (Union[google.cloud.bigtable_v2.types.PrepareQueryRequest, dict]):
|
|
1959
|
+
The request object. Request message for
|
|
1960
|
+
Bigtable.PrepareQuery
|
|
1961
|
+
instance_name (str):
|
|
1962
|
+
Required. The unique name of the instance against which
|
|
1963
|
+
the query should be executed. Values are of the form
|
|
1964
|
+
``projects/<project>/instances/<instance>``
|
|
1965
|
+
|
|
1966
|
+
This corresponds to the ``instance_name`` field
|
|
1967
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1968
|
+
should not be set.
|
|
1969
|
+
query (str):
|
|
1970
|
+
Required. The query string.
|
|
1971
|
+
This corresponds to the ``query`` field
|
|
1972
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1973
|
+
should not be set.
|
|
1974
|
+
app_profile_id (str):
|
|
1975
|
+
Optional. This value specifies routing for preparing the
|
|
1976
|
+
query. Note that this ``app_profile_id`` is only used
|
|
1977
|
+
for preparing the query. The actual query execution will
|
|
1978
|
+
use the app profile specified in the
|
|
1979
|
+
``ExecuteQueryRequest``. If not specified, the
|
|
1980
|
+
``default`` application profile will be used.
|
|
1981
|
+
|
|
1982
|
+
This corresponds to the ``app_profile_id`` field
|
|
1983
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
1984
|
+
should not be set.
|
|
1985
|
+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
|
|
1986
|
+
should be retried.
|
|
1987
|
+
timeout (float): The timeout for this request.
|
|
1988
|
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
|
1989
|
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
|
1990
|
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
|
1991
|
+
be of type `bytes`.
|
|
1992
|
+
|
|
1993
|
+
Returns:
|
|
1994
|
+
google.cloud.bigtable_v2.types.PrepareQueryResponse:
|
|
1995
|
+
Response message for
|
|
1996
|
+
Bigtable.PrepareQueryResponse
|
|
1997
|
+
|
|
1998
|
+
"""
|
|
1999
|
+
# Create or coerce a protobuf request object.
|
|
2000
|
+
# - Quick check: If we got a request object, we should *not* have
|
|
2001
|
+
# gotten any keyword arguments that map to the request.
|
|
2002
|
+
flattened_params = [instance_name, query, app_profile_id]
|
|
2003
|
+
has_flattened_params = (
|
|
2004
|
+
len([param for param in flattened_params if param is not None]) > 0
|
|
2005
|
+
)
|
|
2006
|
+
if request is not None and has_flattened_params:
|
|
2007
|
+
raise ValueError(
|
|
2008
|
+
"If the `request` argument is set, then none of "
|
|
2009
|
+
"the individual field arguments should be set."
|
|
2010
|
+
)
|
|
2011
|
+
|
|
2012
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
2013
|
+
# there are no flattened fields), or create one.
|
|
2014
|
+
if not isinstance(request, bigtable.PrepareQueryRequest):
|
|
2015
|
+
request = bigtable.PrepareQueryRequest(request)
|
|
2016
|
+
# If we have keyword arguments corresponding to fields on the
|
|
2017
|
+
# request, apply these.
|
|
2018
|
+
if instance_name is not None:
|
|
2019
|
+
request.instance_name = instance_name
|
|
2020
|
+
if query is not None:
|
|
2021
|
+
request.query = query
|
|
2022
|
+
if app_profile_id is not None:
|
|
2023
|
+
request.app_profile_id = app_profile_id
|
|
2024
|
+
|
|
2025
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
2026
|
+
# and friendly error handling.
|
|
2027
|
+
rpc = self._transport._wrapped_methods[self._transport.prepare_query]
|
|
2028
|
+
|
|
2029
|
+
header_params = {}
|
|
2030
|
+
|
|
2031
|
+
routing_param_regex = re.compile("^(?P<name>projects/[^/]+/instances/[^/]+)$")
|
|
2032
|
+
regex_match = routing_param_regex.match(request.instance_name)
|
|
2033
|
+
if regex_match and regex_match.group("name"):
|
|
2034
|
+
header_params["name"] = regex_match.group("name")
|
|
2035
|
+
|
|
2036
|
+
if request.app_profile_id:
|
|
2037
|
+
header_params["app_profile_id"] = request.app_profile_id
|
|
2038
|
+
|
|
2039
|
+
if header_params:
|
|
2040
|
+
metadata = tuple(metadata) + (
|
|
2041
|
+
gapic_v1.routing_header.to_grpc_metadata(header_params),
|
|
2042
|
+
)
|
|
2043
|
+
|
|
2044
|
+
# Validate the universe domain.
|
|
2045
|
+
self._validate_universe_domain()
|
|
2046
|
+
|
|
2047
|
+
# Send the request.
|
|
2048
|
+
response = rpc(
|
|
2049
|
+
request,
|
|
2050
|
+
retry=retry,
|
|
2051
|
+
timeout=timeout,
|
|
2052
|
+
metadata=metadata,
|
|
2053
|
+
)
|
|
2054
|
+
|
|
2055
|
+
# Done; return the response.
|
|
2056
|
+
return response
|
|
2057
|
+
|
|
2058
|
+
def execute_query(
|
|
2059
|
+
self,
|
|
2060
|
+
request: Optional[Union[bigtable.ExecuteQueryRequest, dict]] = None,
|
|
2061
|
+
*,
|
|
2062
|
+
instance_name: Optional[str] = None,
|
|
2063
|
+
query: Optional[str] = None,
|
|
2064
|
+
app_profile_id: Optional[str] = None,
|
|
2065
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
2066
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
2067
|
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
|
2068
|
+
) -> Iterable[bigtable.ExecuteQueryResponse]:
|
|
2069
|
+
r"""Executes a SQL query against a particular Bigtable
|
|
2070
|
+
instance.
|
|
2071
|
+
|
|
2072
|
+
Args:
|
|
2073
|
+
request (Union[google.cloud.bigtable_v2.types.ExecuteQueryRequest, dict]):
|
|
2074
|
+
The request object. Request message for
|
|
2075
|
+
Bigtable.ExecuteQuery
|
|
2076
|
+
instance_name (str):
|
|
2077
|
+
Required. The unique name of the instance against which
|
|
2078
|
+
the query should be executed. Values are of the form
|
|
2079
|
+
``projects/<project>/instances/<instance>``
|
|
2080
|
+
|
|
2081
|
+
This corresponds to the ``instance_name`` field
|
|
2082
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
2083
|
+
should not be set.
|
|
2084
|
+
query (str):
|
|
2085
|
+
Required. The query string.
|
|
2086
|
+
|
|
2087
|
+
Exactly one of ``query`` and ``prepared_query`` is
|
|
2088
|
+
required. Setting both or neither is an
|
|
2089
|
+
``INVALID_ARGUMENT``.
|
|
2090
|
+
|
|
2091
|
+
This corresponds to the ``query`` field
|
|
2092
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
2093
|
+
should not be set.
|
|
2094
|
+
app_profile_id (str):
|
|
2095
|
+
Optional. This value specifies routing for replication.
|
|
2096
|
+
If not specified, the ``default`` application profile
|
|
2097
|
+
will be used.
|
|
2098
|
+
|
|
2099
|
+
This corresponds to the ``app_profile_id`` field
|
|
2100
|
+
on the ``request`` instance; if ``request`` is provided, this
|
|
2101
|
+
should not be set.
|
|
2102
|
+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
|
|
2103
|
+
should be retried.
|
|
2104
|
+
timeout (float): The timeout for this request.
|
|
2105
|
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
|
2106
|
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
|
2107
|
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
|
2108
|
+
be of type `bytes`.
|
|
2109
|
+
|
|
2110
|
+
Returns:
|
|
2111
|
+
Iterable[google.cloud.bigtable_v2.types.ExecuteQueryResponse]:
|
|
2112
|
+
Response message for
|
|
2113
|
+
Bigtable.ExecuteQuery
|
|
2114
|
+
|
|
2115
|
+
"""
|
|
2116
|
+
# Create or coerce a protobuf request object.
|
|
2117
|
+
# - Quick check: If we got a request object, we should *not* have
|
|
2118
|
+
# gotten any keyword arguments that map to the request.
|
|
2119
|
+
flattened_params = [instance_name, query, app_profile_id]
|
|
2120
|
+
has_flattened_params = (
|
|
2121
|
+
len([param for param in flattened_params if param is not None]) > 0
|
|
2122
|
+
)
|
|
2123
|
+
if request is not None and has_flattened_params:
|
|
2124
|
+
raise ValueError(
|
|
2125
|
+
"If the `request` argument is set, then none of "
|
|
2126
|
+
"the individual field arguments should be set."
|
|
2127
|
+
)
|
|
2128
|
+
|
|
2129
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
2130
|
+
# there are no flattened fields), or create one.
|
|
2131
|
+
if not isinstance(request, bigtable.ExecuteQueryRequest):
|
|
2132
|
+
request = bigtable.ExecuteQueryRequest(request)
|
|
2133
|
+
# If we have keyword arguments corresponding to fields on the
|
|
2134
|
+
# request, apply these.
|
|
2135
|
+
if instance_name is not None:
|
|
2136
|
+
request.instance_name = instance_name
|
|
2137
|
+
if query is not None:
|
|
2138
|
+
request.query = query
|
|
2139
|
+
if app_profile_id is not None:
|
|
2140
|
+
request.app_profile_id = app_profile_id
|
|
2141
|
+
|
|
2142
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
2143
|
+
# and friendly error handling.
|
|
2144
|
+
rpc = self._transport._wrapped_methods[self._transport.execute_query]
|
|
2145
|
+
|
|
2146
|
+
header_params = {}
|
|
2147
|
+
|
|
2148
|
+
routing_param_regex = re.compile("^(?P<name>projects/[^/]+/instances/[^/]+)$")
|
|
2149
|
+
regex_match = routing_param_regex.match(request.instance_name)
|
|
2150
|
+
if regex_match and regex_match.group("name"):
|
|
2151
|
+
header_params["name"] = regex_match.group("name")
|
|
2152
|
+
|
|
2153
|
+
if request.app_profile_id:
|
|
2154
|
+
header_params["app_profile_id"] = request.app_profile_id
|
|
2155
|
+
|
|
2156
|
+
if header_params:
|
|
2157
|
+
metadata = tuple(metadata) + (
|
|
2158
|
+
gapic_v1.routing_header.to_grpc_metadata(header_params),
|
|
2159
|
+
)
|
|
2160
|
+
|
|
2161
|
+
# Validate the universe domain.
|
|
2162
|
+
self._validate_universe_domain()
|
|
2163
|
+
|
|
2164
|
+
# Send the request.
|
|
2165
|
+
response = rpc(
|
|
2166
|
+
request,
|
|
2167
|
+
retry=retry,
|
|
2168
|
+
timeout=timeout,
|
|
2169
|
+
metadata=metadata,
|
|
2170
|
+
)
|
|
2171
|
+
|
|
2172
|
+
# Done; return the response.
|
|
2173
|
+
return response
|
|
2174
|
+
|
|
2175
|
+
def __enter__(self) -> "BigtableClient":
|
|
2176
|
+
return self
|
|
2177
|
+
|
|
2178
|
+
def __exit__(self, type, value, traceback):
|
|
2179
|
+
"""Releases underlying transport's resources.
|
|
2180
|
+
|
|
2181
|
+
.. warning::
|
|
2182
|
+
ONLY use as a context manager if the transport is NOT shared
|
|
2183
|
+
with other clients! Exiting the with block will CLOSE the transport
|
|
2184
|
+
and may cause errors in other clients!
|
|
2185
|
+
"""
|
|
2186
|
+
self.transport.close()
|
|
2187
|
+
|
|
2188
|
+
|
|
2189
|
+
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
|
|
2190
|
+
gapic_version=package_version.__version__
|
|
2191
|
+
)
|
|
2192
|
+
|
|
2193
|
+
|
|
2194
|
+
__all__ = ("BigtableClient",)
|