Skip to content

Commit b57424d

Browse files
committed
chore: updated gapic layer for execute_query
1 parent bb482e9 commit b57424d

File tree

12 files changed

+1048
-68
lines changed

12 files changed

+1048
-68
lines changed

google/cloud/firestore_v1/services/firestore/async_client.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
from google.cloud.firestore_v1.types import common
5353
from google.cloud.firestore_v1.types import document
5454
from google.cloud.firestore_v1.types import document as gf_document
55+
from google.cloud.firestore_v1.types import explain_stats
5556
from google.cloud.firestore_v1.types import firestore
5657
from google.cloud.firestore_v1.types import query
5758
from google.cloud.firestore_v1.types import query_profile
@@ -236,6 +237,9 @@ def __init__(
236237
If a Callable is given, it will be called with the same set of initialization
237238
arguments as used in the FirestoreTransport constructor.
238239
If set to None, a transport is chosen automatically.
240+
NOTE: "rest" transport functionality is currently in a
241+
beta state (preview). We welcome your feedback via an
242+
issue in this library's source repository.
239243
client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]):
240244
Custom options for the client.
241245
@@ -1247,6 +1251,109 @@ async def sample_run_query():
12471251
# Done; return the response.
12481252
return response
12491253

1254+
def execute_pipeline(
1255+
self,
1256+
request: Optional[Union[firestore.ExecutePipelineRequest, dict]] = None,
1257+
*,
1258+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
1259+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1260+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1261+
) -> Awaitable[AsyncIterable[firestore.ExecutePipelineResponse]]:
1262+
r"""Executes a pipeline query.
1263+
1264+
.. code-block:: python
1265+
1266+
# This snippet has been automatically generated and should be regarded as a
1267+
# code template only.
1268+
# It will require modifications to work:
1269+
# - It may require correct/in-range values for request initialization.
1270+
# - It may require specifying regional endpoints when creating the service
1271+
# client as shown in:
1272+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
1273+
from google.cloud import firestore_v1
1274+
1275+
async def sample_execute_pipeline():
1276+
# Create a client
1277+
client = firestore_v1.FirestoreAsyncClient()
1278+
1279+
# Initialize request argument(s)
1280+
structured_pipeline = firestore_v1.StructuredPipeline()
1281+
structured_pipeline.pipeline.stages.name = "name_value"
1282+
1283+
request = firestore_v1.ExecutePipelineRequest(
1284+
structured_pipeline=structured_pipeline,
1285+
transaction=b'transaction_blob',
1286+
database="database_value",
1287+
)
1288+
1289+
# Make the request
1290+
stream = await client.execute_pipeline(request=request)
1291+
1292+
# Handle the response
1293+
async for response in stream:
1294+
print(response)
1295+
1296+
Args:
1297+
request (Optional[Union[google.cloud.firestore_v1.types.ExecutePipelineRequest, dict]]):
1298+
The request object. The request for
1299+
[Firestore.ExecutePipeline][google.firestore.v1.Firestore.ExecutePipeline].
1300+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
1301+
should be retried.
1302+
timeout (float): The timeout for this request.
1303+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1304+
sent along with the request as metadata. Normally, each value must be of type `str`,
1305+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
1306+
be of type `bytes`.
1307+
1308+
Returns:
1309+
AsyncIterable[google.cloud.firestore_v1.types.ExecutePipelineResponse]:
1310+
The response for [Firestore.Execute][].
1311+
"""
1312+
# Create or coerce a protobuf request object.
1313+
# - Use the request object if provided (there's no risk of modifying the input as
1314+
# there are no flattened fields), or create one.
1315+
if not isinstance(request, firestore.ExecutePipelineRequest):
1316+
request = firestore.ExecutePipelineRequest(request)
1317+
1318+
# Wrap the RPC method; this adds retry and timeout information,
1319+
# and friendly error handling.
1320+
rpc = self._client._transport._wrapped_methods[
1321+
self._client._transport.execute_pipeline
1322+
]
1323+
1324+
header_params = {}
1325+
1326+
routing_param_regex = re.compile("^projects/(?P<project_id>[^/]+)(?:/.*)?$")
1327+
regex_match = routing_param_regex.match(request.database)
1328+
if regex_match and regex_match.group("project_id"):
1329+
header_params["project_id"] = regex_match.group("project_id")
1330+
1331+
routing_param_regex = re.compile(
1332+
"^projects/[^/]+/databases/(?P<database_id>[^/]+)(?:/.*)?$"
1333+
)
1334+
regex_match = routing_param_regex.match(request.database)
1335+
if regex_match and regex_match.group("database_id"):
1336+
header_params["database_id"] = regex_match.group("database_id")
1337+
1338+
if header_params:
1339+
metadata = tuple(metadata) + (
1340+
gapic_v1.routing_header.to_grpc_metadata(header_params),
1341+
)
1342+
1343+
# Validate the universe domain.
1344+
self._client._validate_universe_domain()
1345+
1346+
# Send the request.
1347+
response = rpc(
1348+
request,
1349+
retry=retry,
1350+
timeout=timeout,
1351+
metadata=metadata,
1352+
)
1353+
1354+
# Done; return the response.
1355+
return response
1356+
12501357
def run_aggregation_query(
12511358
self,
12521359
request: Optional[Union[firestore.RunAggregationQueryRequest, dict]] = None,

google/cloud/firestore_v1/services/firestore/client.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
from google.cloud.firestore_v1.types import common
6868
from google.cloud.firestore_v1.types import document
6969
from google.cloud.firestore_v1.types import document as gf_document
70+
from google.cloud.firestore_v1.types import explain_stats
7071
from google.cloud.firestore_v1.types import firestore
7172
from google.cloud.firestore_v1.types import query
7273
from google.cloud.firestore_v1.types import query_profile
@@ -551,6 +552,9 @@ def __init__(
551552
If a Callable is given, it will be called with the same set of initialization
552553
arguments as used in the FirestoreTransport constructor.
553554
If set to None, a transport is chosen automatically.
555+
NOTE: "rest" transport functionality is currently in a
556+
beta state (preview). We welcome your feedback via an
557+
issue in this library's source repository.
554558
client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]):
555559
Custom options for the client.
556560
@@ -1630,6 +1634,107 @@ def sample_run_query():
16301634
# Done; return the response.
16311635
return response
16321636

1637+
def execute_pipeline(
1638+
self,
1639+
request: Optional[Union[firestore.ExecutePipelineRequest, dict]] = None,
1640+
*,
1641+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
1642+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1643+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1644+
) -> Iterable[firestore.ExecutePipelineResponse]:
1645+
r"""Executes a pipeline query.
1646+
1647+
.. code-block:: python
1648+
1649+
# This snippet has been automatically generated and should be regarded as a
1650+
# code template only.
1651+
# It will require modifications to work:
1652+
# - It may require correct/in-range values for request initialization.
1653+
# - It may require specifying regional endpoints when creating the service
1654+
# client as shown in:
1655+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
1656+
from google.cloud import firestore_v1
1657+
1658+
def sample_execute_pipeline():
1659+
# Create a client
1660+
client = firestore_v1.FirestoreClient()
1661+
1662+
# Initialize request argument(s)
1663+
structured_pipeline = firestore_v1.StructuredPipeline()
1664+
structured_pipeline.pipeline.stages.name = "name_value"
1665+
1666+
request = firestore_v1.ExecutePipelineRequest(
1667+
structured_pipeline=structured_pipeline,
1668+
transaction=b'transaction_blob',
1669+
database="database_value",
1670+
)
1671+
1672+
# Make the request
1673+
stream = client.execute_pipeline(request=request)
1674+
1675+
# Handle the response
1676+
for response in stream:
1677+
print(response)
1678+
1679+
Args:
1680+
request (Union[google.cloud.firestore_v1.types.ExecutePipelineRequest, dict]):
1681+
The request object. The request for
1682+
[Firestore.ExecutePipeline][google.firestore.v1.Firestore.ExecutePipeline].
1683+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
1684+
should be retried.
1685+
timeout (float): The timeout for this request.
1686+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1687+
sent along with the request as metadata. Normally, each value must be of type `str`,
1688+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
1689+
be of type `bytes`.
1690+
1691+
Returns:
1692+
Iterable[google.cloud.firestore_v1.types.ExecutePipelineResponse]:
1693+
The response for [Firestore.Execute][].
1694+
"""
1695+
# Create or coerce a protobuf request object.
1696+
# - Use the request object if provided (there's no risk of modifying the input as
1697+
# there are no flattened fields), or create one.
1698+
if not isinstance(request, firestore.ExecutePipelineRequest):
1699+
request = firestore.ExecutePipelineRequest(request)
1700+
1701+
# Wrap the RPC method; this adds retry and timeout information,
1702+
# and friendly error handling.
1703+
rpc = self._transport._wrapped_methods[self._transport.execute_pipeline]
1704+
1705+
header_params = {}
1706+
1707+
routing_param_regex = re.compile("^projects/(?P<project_id>[^/]+)(?:/.*)?$")
1708+
regex_match = routing_param_regex.match(request.database)
1709+
if regex_match and regex_match.group("project_id"):
1710+
header_params["project_id"] = regex_match.group("project_id")
1711+
1712+
routing_param_regex = re.compile(
1713+
"^projects/[^/]+/databases/(?P<database_id>[^/]+)(?:/.*)?$"
1714+
)
1715+
regex_match = routing_param_regex.match(request.database)
1716+
if regex_match and regex_match.group("database_id"):
1717+
header_params["database_id"] = regex_match.group("database_id")
1718+
1719+
if header_params:
1720+
metadata = tuple(metadata) + (
1721+
gapic_v1.routing_header.to_grpc_metadata(header_params),
1722+
)
1723+
1724+
# Validate the universe domain.
1725+
self._validate_universe_domain()
1726+
1727+
# Send the request.
1728+
response = rpc(
1729+
request,
1730+
retry=retry,
1731+
timeout=timeout,
1732+
metadata=metadata,
1733+
)
1734+
1735+
# Done; return the response.
1736+
return response
1737+
16331738
def run_aggregation_query(
16341739
self,
16351740
request: Optional[Union[firestore.RunAggregationQueryRequest, dict]] = None,

google/cloud/firestore_v1/services/firestore/transports/base.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,11 @@ def _prep_wrapped_messages(self, client_info):
286286
default_timeout=300.0,
287287
client_info=client_info,
288288
),
289+
self.execute_pipeline: gapic_v1.method.wrap_method(
290+
self.execute_pipeline,
291+
default_timeout=None,
292+
client_info=client_info,
293+
),
289294
self.run_aggregation_query: gapic_v1.method.wrap_method(
290295
self.run_aggregation_query,
291296
default_retry=retries.Retry(
@@ -509,6 +514,18 @@ def run_query(
509514
]:
510515
raise NotImplementedError()
511516

517+
@property
518+
def execute_pipeline(
519+
self,
520+
) -> Callable[
521+
[firestore.ExecutePipelineRequest],
522+
Union[
523+
firestore.ExecutePipelineResponse,
524+
Awaitable[firestore.ExecutePipelineResponse],
525+
],
526+
]:
527+
raise NotImplementedError()
528+
512529
@property
513530
def run_aggregation_query(
514531
self,

google/cloud/firestore_v1/services/firestore/transports/grpc.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,34 @@ def run_query(
571571
)
572572
return self._stubs["run_query"]
573573

574+
@property
575+
def execute_pipeline(
576+
self,
577+
) -> Callable[
578+
[firestore.ExecutePipelineRequest], firestore.ExecutePipelineResponse
579+
]:
580+
r"""Return a callable for the execute pipeline method over gRPC.
581+
582+
Executes a pipeline query.
583+
584+
Returns:
585+
Callable[[~.ExecutePipelineRequest],
586+
~.ExecutePipelineResponse]:
587+
A function that, when called, will call the underlying RPC
588+
on the server.
589+
"""
590+
# Generate a "stub function" on-the-fly which will actually make
591+
# the request.
592+
# gRPC handles serialization and deserialization, so we just need
593+
# to pass in the functions for each.
594+
if "execute_pipeline" not in self._stubs:
595+
self._stubs["execute_pipeline"] = self._logged_channel.unary_stream(
596+
"/google.firestore.v1.Firestore/ExecutePipeline",
597+
request_serializer=firestore.ExecutePipelineRequest.serialize,
598+
response_deserializer=firestore.ExecutePipelineResponse.deserialize,
599+
)
600+
return self._stubs["execute_pipeline"]
601+
574602
@property
575603
def run_aggregation_query(
576604
self,

google/cloud/firestore_v1/services/firestore/transports/grpc_asyncio.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,34 @@ def run_query(
587587
)
588588
return self._stubs["run_query"]
589589

590+
@property
591+
def execute_pipeline(
592+
self,
593+
) -> Callable[
594+
[firestore.ExecutePipelineRequest], Awaitable[firestore.ExecutePipelineResponse]
595+
]:
596+
r"""Return a callable for the execute pipeline method over gRPC.
597+
598+
Executes a pipeline query.
599+
600+
Returns:
601+
Callable[[~.ExecutePipelineRequest],
602+
Awaitable[~.ExecutePipelineResponse]]:
603+
A function that, when called, will call the underlying RPC
604+
on the server.
605+
"""
606+
# Generate a "stub function" on-the-fly which will actually make
607+
# the request.
608+
# gRPC handles serialization and deserialization, so we just need
609+
# to pass in the functions for each.
610+
if "execute_pipeline" not in self._stubs:
611+
self._stubs["execute_pipeline"] = self._logged_channel.unary_stream(
612+
"/google.firestore.v1.Firestore/ExecutePipeline",
613+
request_serializer=firestore.ExecutePipelineRequest.serialize,
614+
response_deserializer=firestore.ExecutePipelineResponse.deserialize,
615+
)
616+
return self._stubs["execute_pipeline"]
617+
590618
@property
591619
def run_aggregation_query(
592620
self,
@@ -962,6 +990,11 @@ def _prep_wrapped_messages(self, client_info):
962990
default_timeout=300.0,
963991
client_info=client_info,
964992
),
993+
self.execute_pipeline: self._wrap_method(
994+
self.execute_pipeline,
995+
default_timeout=None,
996+
client_info=client_info,
997+
),
965998
self.run_aggregation_query: self._wrap_method(
966999
self.run_aggregation_query,
9671000
default_retry=retries.AsyncRetry(

0 commit comments

Comments
 (0)