Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Linchin committed Aug 27, 2024
1 parent f08a35d commit 560ba95
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 32 deletions.
10 changes: 6 additions & 4 deletions google/cloud/firestore_v1/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def _make_stream(
] = gapic_v1.method.DEFAULT,
timeout: Optional[float] = None,
explain_options: Optional[ExplainOptions] = None,
) -> Generator[Optional[List[AggregationResult]], Any, Optional[ExplainMetrics]]:
) -> Generator[List[AggregationResult], Any, Optional[ExplainMetrics]]:
"""Internal method for stream(). Runs the aggregation query.
This sends a ``RunAggregationQuery`` RPC and then returns a generator
Expand All @@ -161,7 +161,7 @@ def _make_stream(
explain_metrics will be available on the returned generator.
Yields:
Optional[List[AggregationResult]]:
List[AggregationResult]:
The result of aggregations of this query.
Returns:
Expand Down Expand Up @@ -198,10 +198,12 @@ def _make_stream(
metrics = response.explain_metrics

result = _query_response_to_result(response)
if len(result) > 0 or metrics is None:
if len(result) > 0 or explain_options.analyze is True:
# When explain_options.analyze == False, the query isn't run
# but query profiling results are returned. In this case we
# do not yield an empty result.
# do not yield an empty result. But when
# explain_options.analyze == True, we yield even if result is
# empty.
yield result

return metrics
Expand Down
10 changes: 5 additions & 5 deletions google/cloud/firestore_v1/base_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from typing import (
TYPE_CHECKING,
Any,
Coroutine,
Awaitable,
List,
Optional,
Tuple,
Expand Down Expand Up @@ -66,7 +66,7 @@ class AggregationResult(object):
:param value: The resulting read_time
"""

def __init__(self, alias: str, value: int | float, read_time=None):
def __init__(self, alias: str, value: float, read_time=None):
self.alias = alias
self.value = value
self.read_time = read_time
Expand Down Expand Up @@ -241,7 +241,7 @@ def get(
explain_options: Optional[ExplainOptions] = None,
) -> (
QueryResultsList[AggregationResult]
| Coroutine[Any, Any, List[AggregationResult]]
| Awaitable[Any, Any, List[AggregationResult]]
):
"""Runs the aggregation query.
Expand All @@ -264,7 +264,7 @@ def get(
explain_metrics will be available on the returned generator.
Returns:
QueryResultsList[AggregationResult] | Coroutine[Any, Any, List[AggregationResult]]:
QueryResultsList[AggregationResult] | Awaitable[Any, Any, List[AggregationResult]]:
The aggregation query results.
"""
Expand All @@ -281,7 +281,7 @@ def stream(
explain_options: Optional[ExplainOptions] = None,
) -> (
StreamGenerator[Optional[List[AggregationResult]]]
| AsyncStreamGenerator[List[AggregationResult], Any, None]
| AsyncStreamGenerator[List[AggregationResult], Any]
):
"""Runs the aggregation query.
Expand Down
4 changes: 0 additions & 4 deletions google/cloud/firestore_v1/base_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
NoReturn,
Optional,
Tuple,
TypeVar,
Union,
)

Expand All @@ -39,9 +38,6 @@
from google.cloud.firestore_v1.types import Document, firestore, write


T = TypeVar("T")


class BaseDocumentReference(object):
"""A reference to a document in a Firestore database.
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/firestore_v1/base_vector_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,5 @@ def stream(
timeout: float = None,
*,
explain_options: Optional[ExplainOptions] = None,
) -> Generator[Optional[DocumentSnapshot], Any, Optional[ExplainMetrics]]:
) -> Generator[DocumentSnapshot, Any, Optional[ExplainMetrics]]:
"""Reads the documents in the collection that match this query."""
6 changes: 3 additions & 3 deletions google/cloud/firestore_v1/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def _chunkify(
snapshots = _q.get()

if snapshots:
last_document = snapshots[-1] # type: ignore
last_document = snapshots[-1]

num_returned += len(snapshots)

Expand Down Expand Up @@ -353,7 +353,7 @@ def _make_stream(
retry: Optional[retries.Retry] = gapic_v1.method.DEFAULT,
timeout: Optional[float] = None,
explain_options: Optional[ExplainOptions] = None,
) -> Generator[Optional[DocumentSnapshot], Any, Optional[ExplainMetrics]]:
) -> Generator[DocumentSnapshot, Any, Optional[ExplainMetrics]]:
"""Internal method for stream(). Read the documents in the collection
that match this query.
Expand Down Expand Up @@ -388,7 +388,7 @@ def _make_stream(
explain_metrics will be available on the returned generator.
Yields:
Optional[DocumentSnapshot]:
DocumentSnapshot:
The next document that fulfills the query.
Returns:
Expand Down
7 changes: 2 additions & 5 deletions google/cloud/firestore_v1/query_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
)


from typing import List, Optional, TypeVar


T = TypeVar("T")
from typing import List, Optional


class QueryResultsList(list):
Expand All @@ -32,7 +29,7 @@ class QueryResultsList(list):
is added to return the query profile results.
Args:
docs (list[T]):
docs (list):
The list of query results.
explain_options
(Optional[:class:`~google.cloud.firestore_v1.query_profile.ExplainOptions`]):
Expand Down
11 changes: 7 additions & 4 deletions google/cloud/firestore_v1/stream_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"""
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Generator, Optional
from typing import TYPE_CHECKING, Any, Generator, Optional, TypeVar

from google.cloud.firestore_v1.query_profile import (
ExplainMetrics,
Expand All @@ -27,11 +27,14 @@
from google.cloud.firestore_v1.query_profile import ExplainOptions


class StreamGenerator(Generator[Any, Any, Optional[ExplainMetrics]]):
T = TypeVar("T")


class StreamGenerator(Generator[T, Any, None]):
"""Generator for the streamed results.
Args:
response_generator (Generator):
response_generator (Generator[T, Any, Optional[ExplainMetrics]]):
The inner generator that yields the returned document in the stream.
explain_options
(Optional[:class:`~google.cloud.firestore_v1.query_profile.ExplainOptions`]):
Expand All @@ -40,7 +43,7 @@ class StreamGenerator(Generator[Any, Any, Optional[ExplainMetrics]]):

def __init__(
self,
response_generator: Generator[Any, Any, Optional[ExplainMetrics]],
response_generator: Generator[T, Any, Optional[ExplainMetrics]],
explain_options: Optional[ExplainOptions] = None,
):
self._generator = response_generator
Expand Down
8 changes: 4 additions & 4 deletions google/cloud/firestore_v1/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class _NumericValue(object):
"""Hold a single integer / float value.
Args:
value (int | float): value held in the helper.
value (float): value held in the helper.
"""

def __init__(self, value) -> None:
Expand Down Expand Up @@ -133,7 +133,7 @@ class Increment(_NumericValue):
https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1#google.firestore.v1.DocumentTransform.FieldTransform.FIELDS.google.firestore.v1.ArrayValue.google.firestore.v1.DocumentTransform.FieldTransform.increment
Args:
value (int | float): value used to increment the field.
value (float): value used to increment the field.
"""


Expand All @@ -144,7 +144,7 @@ class Maximum(_NumericValue):
https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1#google.firestore.v1.DocumentTransform.FieldTransform.FIELDS.google.firestore.v1.ArrayValue.google.firestore.v1.DocumentTransform.FieldTransform.maximum
Args:
value (int | float): value used to bound the field.
value (float): value used to bound the field.
"""


Expand All @@ -155,5 +155,5 @@ class Minimum(_NumericValue):
https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1#google.firestore.v1.DocumentTransform.FieldTransform.FIELDS.google.firestore.v1.ArrayValue.google.firestore.v1.DocumentTransform.FieldTransform.minimum
Args:
value (int | float): value used to bound the field.
value (float): value used to bound the field.
"""
4 changes: 2 additions & 2 deletions google/cloud/firestore_v1/vector_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def _make_stream(
retry: Optional[retries.Retry] = gapic_v1.method.DEFAULT,
timeout: Optional[float] = None,
explain_options: Optional[ExplainOptions] = None,
) -> Generator[Optional[DocumentSnapshot], Any, Optional[ExplainMetrics]]:
) -> Generator[DocumentSnapshot, Any, Optional[ExplainMetrics]]:
"""Reads the documents in the collection that match this query.
This sends a ``RunQuery`` RPC and then returns a generator which
Expand All @@ -151,7 +151,7 @@ def _make_stream(
explain_metrics will be available on the returned generator.
Yields:
Optional[DocumentSnapshot]:
DocumentSnapshot:
The next document that fulfills the query.
Returns:
Expand Down

0 comments on commit 560ba95

Please sign in to comment.