Ë
    V¼Sf¼  ã                  óz   — d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	m
Z
mZ ddlmZmZmZmZ  G d„ d	e
«      Zy
)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)Ú
exceptions)Úgapic_v1)Úretry)ÚAggregationResultÚBaseAggregationQueryÚ_query_response_to_result)Ú	GeneratorÚUnionÚListÚAnyc                  ó¸   ‡ — e Zd ZdZ	 	 dˆ fd„Zdej                  j                  df	 	 	 	 	 d	d„Zd„ Z	d„ Z
dej                  j                  df	 	 	 	 	 d
d„Zˆ xZS )ÚAggregationQueryz5Represents an aggregation query to the Firestore API.c                ó,   •— t         t        | �  |«       y )N)Úsuperr   Ú__init__)ÚselfÚnested_queryÚ	__class__s     €údC:\Users\user\Documents\project_loop\venv\Lib\site-packages\google/cloud/firestore_v1/aggregation.pyr   zAggregationQuery.__init__(   s   ø€ ô 	Ô Ñ.¨|Õ<ó    Nc                ó@   — | j                  |||¬«      }t        |«      S )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.

        Returns:
            list: The aggregation query results

        )Útransactionr   Útimeout)ÚstreamÚlist)r   r   r   r   Úresults        r   ÚgetzAggregationQuery.get.   s"   € ð8 —‘¨¸EÈ7�ÓSˆÜ�F‹|Ðr   c                ó¨   — | j                  |||«      \  }} | j                  j                  j                  d|| j                  j                  dœ|¤ŽS )ú!Helper method for :meth:`stream`.)ÚrequestÚmetadata© )Ú_prep_streamÚ_clientÚ_firestore_apiÚrun_aggregation_queryÚ_rpc_metadata)r   r   r   r   r!   Úkwargss         r   Ú_get_stream_iteratorz%AggregationQuery._get_stream_iteratorM   s`   € à×+Ñ+ØØØó
‰ˆ�ð Aˆt�|‰|×*Ñ*×@Ñ@ð 
ØØ—\‘\×/Ñ/ñ
ð ñ
ð 	
r   c                óÒ   — |€e|t         j                  j                  u r8| j                  j                  j
                  }|j                  }|j                  }|j                  |«      S y)r    F)	r   ÚmethodÚDEFAULTr%   r&   Ú
_transportr'   Ú_retryÚ
_predicate)r   Úexcr   r   Ú	transportÚgapic_callables         r   Ú_retry_query_after_exceptionz-AggregationQuery._retry_query_after_exception[   sY   € àÐØœŸ™×/Ñ/Ñ/Ø ŸL™L×7Ñ7×BÑB�	Ø!*×!@Ñ!@�Ø&×-Ñ-�Ø×#Ñ# CÓ(Ð(àr   c              #  ó   K  — | j                  |||«      }	 	 t        |d«      }|€yt        |«      }|–— Œ # t        j                  $ r1}| j	                  |||«      r| j                  |||«      }Y d}~Œ_‚ d}~ww xY w­w)aù  Runs the aggregation query.

        This sends a ``RunAggregationQuery`` RPC and then returns an iterator 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 (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.

        Yields:
            :class:`~google.cloud.firestore_v1.base_aggregation.AggregationResult`:
            The result of aggregations of this query
        N)r*   Únextr   ÚGoogleAPICallErrorr4   r	   )r   r   r   r   Úresponse_iteratorÚresponser1   r   s           r   r   zAggregationQuery.streamf   s¤   è ø€ ð@ !×5Ñ5ØØØó
Ðð
 ðÜÐ 1°4Ó8�ð ÐØÜ.¨xÓ8ˆFØŠLð# øô ×0Ñ0ò 	Ø×4Ñ4°S¸%ÀÔMØ(,×(AÑ(AØ#ØØó)Ð%ô
 àûð	üs1   ‚A>˜7 ¤A>·A;Á
&A6Á0A>Á5A6Á6A;Á;A>)ÚreturnÚNone)r   ú:Union[retries.Retry, None, gapic_v1.method._MethodDefault]r   úfloat | Noner:   zList[AggregationResult])r   r<   r   r=   r:   z4Union[Generator[List[AggregationResult], Any, None]])Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r,   r-   r   r*   r4   r   Ú__classcell__)r   s   @r   r   r   %   s“   ø„ Ù?ð=ð 
õ=ð ð �O‰O×#Ñ#Ø $ðð
ðð ðð 
!óò>
ò	ð ð �O‰O×#Ñ#Ø $ð6ð
ð6ð ð6ð 
>÷6r   r   N)rA   Ú
__future__r   Úgoogle.api_corer   r   r   ÚretriesÚ*google.cloud.firestore_v1.base_aggregationr   r   r	   Útypingr
   r   r   r   r   r#   r   r   ú<module>rH      s9   ðñõ #å &Ý $Ý ,÷ñ ÷ /Ó .ôwÐ+õ wr   