|
40 | 40 | from google.auth import credentials as ga_credentials # type: ignore
|
41 | 41 | from google.oauth2 import service_account # type: ignore
|
42 | 42 |
|
| 43 | + |
43 | 44 | try:
|
44 | 45 | OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None]
|
45 | 46 | except AttributeError: # pragma: NO COVER
|
@@ -1293,6 +1294,109 @@ def read_change_stream(
|
1293 | 1294 | # Done; return the response.
|
1294 | 1295 | return response
|
1295 | 1296 |
|
| 1297 | + def execute_query( |
| 1298 | + self, |
| 1299 | + request: Optional[Union[bigtable.ExecuteQueryRequest, dict]] = None, |
| 1300 | + *, |
| 1301 | + instance_name: Optional[str] = None, |
| 1302 | + query: Optional[str] = None, |
| 1303 | + app_profile_id: Optional[str] = None, |
| 1304 | + retry: OptionalRetry = gapic_v1.method.DEFAULT, |
| 1305 | + timeout: Union[float, object] = gapic_v1.method.DEFAULT, |
| 1306 | + metadata: Sequence[Tuple[str, str]] = (), |
| 1307 | + ) -> Awaitable[AsyncIterable[bigtable.ExecuteQueryResponse]]: |
| 1308 | + r"""Executes a BTQL query against a particular Cloud |
| 1309 | + Bigtable instance. |
| 1310 | +
|
| 1311 | + Args: |
| 1312 | + request (Optional[Union[google.cloud.bigtable_v2.types.ExecuteQueryRequest, dict]]): |
| 1313 | + The request object. Request message for |
| 1314 | + Bigtable.ExecuteQuery |
| 1315 | + instance_name (:class:`str`): |
| 1316 | + Required. The unique name of the instance against which |
| 1317 | + the query should be executed. Values are of the form |
| 1318 | + ``projects/<project>/instances/<instance>`` |
| 1319 | +
|
| 1320 | + This corresponds to the ``instance_name`` field |
| 1321 | + on the ``request`` instance; if ``request`` is provided, this |
| 1322 | + should not be set. |
| 1323 | + query (:class:`str`): |
| 1324 | + Required. The query string. |
| 1325 | + This corresponds to the ``query`` field |
| 1326 | + on the ``request`` instance; if ``request`` is provided, this |
| 1327 | + should not be set. |
| 1328 | + app_profile_id (:class:`str`): |
| 1329 | + Optional. This value specifies routing for replication. |
| 1330 | + If not specified, the ``default`` application profile |
| 1331 | + will be used. |
| 1332 | +
|
| 1333 | + This corresponds to the ``app_profile_id`` field |
| 1334 | + on the ``request`` instance; if ``request`` is provided, this |
| 1335 | + should not be set. |
| 1336 | + retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, |
| 1337 | + should be retried. |
| 1338 | + timeout (float): The timeout for this request. |
| 1339 | + metadata (Sequence[Tuple[str, str]]): Strings which should be |
| 1340 | + sent along with the request as metadata. |
| 1341 | +
|
| 1342 | + Returns: |
| 1343 | + AsyncIterable[google.cloud.bigtable_v2.types.ExecuteQueryResponse]: |
| 1344 | + Response message for |
| 1345 | + Bigtable.ExecuteQuery |
| 1346 | +
|
| 1347 | + """ |
| 1348 | + # Create or coerce a protobuf request object. |
| 1349 | + # - Quick check: If we got a request object, we should *not* have |
| 1350 | + # gotten any keyword arguments that map to the request. |
| 1351 | + has_flattened_params = any([instance_name, query, app_profile_id]) |
| 1352 | + if request is not None and has_flattened_params: |
| 1353 | + raise ValueError( |
| 1354 | + "If the `request` argument is set, then none of " |
| 1355 | + "the individual field arguments should be set." |
| 1356 | + ) |
| 1357 | + |
| 1358 | + # - Use the request object if provided (there's no risk of modifying the input as |
| 1359 | + # there are no flattened fields), or create one. |
| 1360 | + if not isinstance(request, bigtable.ExecuteQueryRequest): |
| 1361 | + request = bigtable.ExecuteQueryRequest(request) |
| 1362 | + |
| 1363 | + # If we have keyword arguments corresponding to fields on the |
| 1364 | + # request, apply these. |
| 1365 | + if instance_name is not None: |
| 1366 | + request.instance_name = instance_name |
| 1367 | + if query is not None: |
| 1368 | + request.query = query |
| 1369 | + if app_profile_id is not None: |
| 1370 | + request.app_profile_id = app_profile_id |
| 1371 | + |
| 1372 | + # Wrap the RPC method; this adds retry and timeout information, |
| 1373 | + # and friendly error handling. |
| 1374 | + rpc = self._client._transport._wrapped_methods[ |
| 1375 | + self._client._transport.execute_query |
| 1376 | + ] |
| 1377 | + |
| 1378 | + # Certain fields should be provided within the metadata header; |
| 1379 | + # add these here. |
| 1380 | + metadata = tuple(metadata) + ( |
| 1381 | + gapic_v1.routing_header.to_grpc_metadata( |
| 1382 | + (("instance_name", request.instance_name),) |
| 1383 | + ), |
| 1384 | + ) |
| 1385 | + |
| 1386 | + # Validate the universe domain. |
| 1387 | + self._client._validate_universe_domain() |
| 1388 | + |
| 1389 | + # Send the request. |
| 1390 | + response = rpc( |
| 1391 | + request, |
| 1392 | + retry=retry, |
| 1393 | + timeout=timeout, |
| 1394 | + metadata=metadata, |
| 1395 | + ) |
| 1396 | + |
| 1397 | + # Done; return the response. |
| 1398 | + return response |
| 1399 | + |
1296 | 1400 | async def __aenter__(self) -> "BigtableAsyncClient":
|
1297 | 1401 | return self
|
1298 | 1402 |
|
|
0 commit comments