
    (ph%                        S r SSKJr  SSKJrJrJrJrJrJ	r	  SSK
JrJr  SSK
Jr  SSKJrJrJr  SSKJr  SSKJr  \(       a  SS	KJr  SS
KJr  SSKJr   " S S\5      rg)aU  Classes for representing aggregation queries for the Google Cloud Firestore API.

A :class:`~google.cloud.firestore_v1.aggregation.AggregationQuery` can be created directly from
a :class:`~google.cloud.firestore_v1.collection.Collection` and that can be
a more common way to create an aggregation query than direct usage of the constructor.
    )annotations)TYPE_CHECKINGAny	GeneratorListOptionalUnion)
exceptionsgapic_v1)retry)AggregationResultBaseAggregationQuery_query_response_to_result)QueryResultsList)StreamGenerator)transaction)ExplainMetrics)ExplainOptionsc                  <  ^  \ rS rSrSr  SU 4S jjrS\R                  R                  S4SS.       SS jjjr	SS jr
S rS\R                  R                  SS4         SS	 jjrS\R                  R                  S4SS.         SS
 jjjrSrU =r$ )AggregationQuery+   z5Represents an aggregation query to the Firestore API.c                ,   > [         [        U ]  U5        g N)superr   __init__)selfnested_query	__class__s     X/var/www/html/venv/lib/python3.13/site-packages/google/cloud/firestore_v1/aggregation.pyr   AggregationQuery.__init__.   s     	.|<    N)explain_optionsc                   SnU R                  UUUUS9n[        U5      nUc  SnOUR                  5       n[        XtU5      $ )a+  Runs the aggregation query.

This sends a ``RunAggregationQuery`` RPC and returns a list of
aggregation results in the stream of ``RunAggregationQueryResponse``
messages.

Args:
    transaction
        (Optional[:class:`~google.cloud.firestore_v1.transaction.Transaction`]):
        An existing transaction that this query will run in.
        If a ``transaction`` is used and it already has write operations
        added, this method cannot be used (i.e. read-after-write is not
        allowed).
    retry (google.api_core.retry.Retry): Designation of what errors, if any,
        should be retried.  Defaults to a system-specified policy.
    timeout (float): The timeout for this request.  Defaults to a
        system-specified value.
    explain_options
        (Optional[:class:`~google.cloud.firestore_v1.query_profile.ExplainOptions`]):
        Options to enable query profiling for this query. When set,
        explain_metrics will be available on the returned generator.

Returns:
    QueryResultsList[AggregationResult]: The aggregation query results.

Nr   r   timeoutr"   )streamlistget_explain_metricsr   )r   r   r   r%   r"   explain_metricsresultresult_lists           r   getAggregationQuery.get4   sZ    D 26#+	  
 6l""O$88:OoNNr!   c                    U R                  UUUU5      u  pVU R                  R                  R                  " SUU R                  R                  S.UD6$ )!Helper method for :meth:`stream`.)requestmetadata )_prep_stream_client_firestore_apirun_aggregation_query_rpc_metadata)r   r   r   r%   r"   r0   kwargss          r   _get_stream_iterator%AggregationQuery._get_stream_iteratorg   s^    ++	
 ||**@@ 
\\//
 
 	
r!   c                    Ucf  U[         R                  R                  L a8  U R                  R                  R
                  nUR                  nUR                  nUR                  U5      $ g)r/   F)	r   methodDEFAULTr4   r5   
_transportr6   _retry
_predicate)r   excr   r   	transportgapic_callables         r   _retry_query_after_exception-AggregationQuery._retry_query_after_exceptionv   sY    /// LL77BB	!*!@!@&--##C((r!   c              #  h  #    SnU R                  UUUU5      n  [        US5      nUc   U$ Uc  UR
                  (       a  UR
                  n[        U5      n	U	(       a  U	v   MK  ! [        R                   a6  nU R	                  XU5      (       a  U R                  UUU5      n SnAM  e SnAff = f7f)a  Internal method for stream(). Runs the aggregation query.

This sends a ``RunAggregationQuery`` RPC and then returns a generator
which consumes each document returned in the stream of
``RunAggregationQueryResponse`` messages.

If a ``transaction`` is used and it already has write operations added,
this method cannot be used (i.e. read-after-write is not allowed).

Args:
    transaction
        (Optional[:class:`~google.cloud.firestore_v1.transaction.Transaction`]):
        An existing transaction that this query will run in.
    retry (Optional[google.api_core.retry.Retry]): Designation of what
        errors, if any, should be retried.  Defaults to a
        system-specified policy.
    timeout (Optional[float]): The timeout for this request.  Defaults
        to a system-specified value.
    explain_options
        (Optional[:class:`~google.cloud.firestore_v1.query_profile.ExplainOptions`]):
        Options to enable query profiling for this query. When set,
        explain_metrics will be available on the returned generator.

Yields:
    List[AggregationResult]:
    The result of aggregations of this query.

Returns:
    (Optional[google.cloud.firestore_v1.types.query_profile.ExplainMetrtics]):
    The results of query profiling, if received from the service.

N)r9   nextr
   GoogleAPICallErrorrD   r)   r   )
r   r   r   r%   r"   metricsresponse_iteratorresponserA   r*   s
             r   _make_streamAggregationQuery._make_stream   s     N *. 55	
  148   8#;#;"22.x8F-  00 	44SMM(,(A(A#)%
 	s3   B2A% >B2%B/9*B*#B2)B**B//B2c               <    U R                  UUUUS9n[        XT5      $ )aQ  Runs the aggregation query.

This sends a ``RunAggregationQuery`` RPC and then returns a generator
which consumes each document returned in the stream of
``RunAggregationQueryResponse`` messages.

If a ``transaction`` is used and it already has write operations added,
this method cannot be used (i.e. read-after-write is not allowed).

Args:
    transaction
        (Optional[:class:`~google.cloud.firestore_v1.transaction.Transaction`]):
        An existing transaction that this query will run in.
    retry (Optional[google.api_core.retry.Retry]): Designation of what
        errors, if any, should be retried.  Defaults to a
        system-specified policy.
    timeout (Optinal[float]): The timeout for this request.  Defaults
    to a system-specified value.
    explain_options
        (Optional[:class:`~google.cloud.firestore_v1.query_profile.ExplainOptions`]):
        Options to enable query profiling for this query. When set,
        explain_metrics will be available on the returned generator.

Returns:
    `StreamGenerator[List[AggregationResult]]`:
    A generator of the query results.
r$   )rL   r   )r   r   r   r%   r"   inner_generators         r   r&   AggregationQuery.stream   s3    F ++#+	 , 
 @@r!   r2   )returnNone)r   "Union[retries.Retry, None, object]r%   zfloat | Noner"   Optional[ExplainOptions]rQ   z#QueryResultsList[AggregationResult]r   )
r   z!Optional[transaction.Transaction]r   rS   r%   Optional[float]r"   rT   rQ   zAGenerator[List[AggregationResult], Any, Optional[ExplainMetrics]])
r   z#Optional['transaction.Transaction']r   rS   r%   rU   r"   rT   rQ   z(StreamGenerator[List[AggregationResult]])__name__
__module____qualname____firstlineno____doc__r   r   r<   r=   r,   r9   rD   rL   r&   __static_attributes____classcell__)r   s   @r   r   r   +   s)   ?= 
= 4<OO4K4K $	1O 591O 21O 	1O 21O 
-1Of
	 :>4<OO4K4K#'48G6G 2G !	G
 2G 
KGV <@4<OO4K4K#'	)A 59)A8)A 2)A !	)A 2)A 
2)A )Ar!   r   N)rZ   
__future__r   typingr   r   r   r   r   r	   google.api_corer
   r   r   retries*google.cloud.firestore_v1.base_aggregationr   r   r   'google.cloud.firestore_v1.query_resultsr   *google.cloud.firestore_v1.stream_generatorr   google.cloud.firestore_v1r   'google.cloud.firestore_v1.query_profiler   r   r   r2   r!   r   <module>rf      sM    # G G 0 , 
 E F 5FFHA+ HAr!   