§
    .
0h¿%  ã                  óÂ   — d Z ddlmZ ddlmZmZmZmZmZm	Z	 ddl
mZmZ ddl
mZ ddlmZmZmZ ddlmZ ddlmZ erdd	lmZ dd
lmZ ddlmZ  G d„ de¦  «        ZdS )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                  ó¬   ‡ — e Zd ZdZdˆ fd„Zdej        j        dfddœdd„Zdd„Z	d„ Z
dej        j        ddfdd„Zdej        j        dfddœdd„Zˆ xZS )ÚAggregationQueryz5Represents an aggregation query to the Firestore API.ÚreturnÚNonec                óX   •— t          t          | ¦  «                             |¦  «         d S ©N)Úsuperr   Ú__init__)ÚselfÚnested_queryÚ	__class__s     €ú`/var/www/html/nourish/venv/lib/python3.11/site-packages/google/cloud/firestore_v1/aggregation.pyr   zAggregationQuery.__init__.   s*   ø€ õ 	Õ Ñ%Ô%×.Ò.¨|Ñ<Ô<Ð<Ð<Ð<ó    N)Úexplain_optionsr   ú"Union[retries.Retry, None, object]Útimeoutúfloat | Noner"   úOptional[ExplainOptions]ú#QueryResultsList[AggregationResult]c               óª   — d}|                       ||||¬¦  «        }t          |¦  «        }|€d}n|                     ¦   «         }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.
            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   r$   r"   )ÚstreamÚlistÚget_explain_metricsr   )r   r   r   r$   r"   Úexplain_metricsÚresultÚresult_lists           r    ÚgetzAggregationQuery.get4   sk   € ðD 26ˆà—’Ø#ØØØ+ð	 ñ 
ô 
ˆõ ˜6‘l”lˆàÐ"Ø"ˆOˆOà$×8Ò8Ñ:Ô:ˆOå ¨_¸oÑNÔNÐNr!   c                ó€   — |                       ||||¦  «        \  }} | 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"   r3   Úkwargss          r    Ú_get_stream_iteratorz%AggregationQuery._get_stream_iteratorg   se   € à×+Ò+ØØØØñ	
ô 
‰ˆð AˆtŒ|Ô*Ô@ð 
ØØ”\Ô/ð
ð 
ð ð
ð 
ð 	
r!   c                ó˜   — |€G|t           j        j        u r| j        j        j        }|j        }|j        }|                     |¦  «        S dS )r2   NF)	r   ÚmethodÚDEFAULTr7   r8   Ú
_transportr9   Ú_retryÚ
_predicate)r   Úexcr   r   Ú	transportÚgapic_callables         r    Ú_retry_query_after_exceptionz-AggregationQuery._retry_query_after_exceptionv   sN   € àÐØœÔ/Ð/Ð/Ø œLÔ7ÔB	Ø!*Ô!@Ø&Ô-Ø×#Ò# CÑ(Ô(Ð(àˆur!   r   ú!Optional[transaction.Transaction]úOptional[float]úAGenerator[List[AggregationResult], Any, Optional[ExplainMetrics]]c              #  óL  K  — d}|                       ||||¦  «        }	 	 t          |d¦  «        }nK# t          j        $ r9}|                      |||¦  «        r|                       |||¦  «        }Y d}~ŒU‚ d}~ww xY w|€n&|€|j        r|j        }t          |¦  «        }	|	r|	V — Œ†|S )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)r<   Únextr
   ÚGoogleAPICallErrorrF   r-   r   )
r   r   r   r$   r"   ÚmetricsÚresponse_iteratorÚresponserC   r.   s
             r    Ú_make_streamzAggregationQuery._make_stream   s   è è € ðN *.ˆà ×5Ò5ØØØØñ	
ô 
Ðð	ðÝÐ 1°4Ñ8Ô8øÝÔ0ð 	ð 	ð 	Ø×4Ò4°S¸%ÀÑMÔMð Ø(,×(AÒ(AØ#ØØñ)ô )Ð%ð
 HHHHàøøøøð	øøøð ÐØàˆ 8Ô#;ˆØ"Ô2å.¨xÑ8Ô8ˆFØð Øð-	ð0 ˆs   Ÿ0 °A8¿.A3Á2A3Á3A8ú#Optional['transaction.Transaction']ú(StreamGenerator[List[AggregationResult]]c               óT   — |                       ||||¬¦  «        }t          ||¦  «        S )a  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)   )rP   r   )r   r   r   r$   r"   Úinner_generators         r    r*   zAggregationQuery.streamÊ   s=   € ðF ×+Ò+Ø#ØØØ+ð	 ,ñ 
ô 
ˆõ ˜°Ñ@Ô@Ð@r!   )r   r   )r   r#   r$   r%   r"   r&   r   r'   r   )
r   rG   r   r#   r$   rH   r"   r&   r   rI   )
r   rQ   r   r#   r$   rH   r"   r&   r   rR   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r>   r?   r0   r<   rF   rP   r*   Ú__classcell__)r   s   @r    r   r   +   s  ø€ € € € € Ø?Ð?ð=ð =ð =ð =ð =ð =ð Ø4<´OÔ4KØ $ð	1Oð 59ð1Oð 1Oð 1Oð 1Oð 1Oð 1Oðf
ð 
ð 
ð 
ð	ð 	ð 	ð :>Ø4<´OÔ4KØ#'Ø48ðGð Gð Gð Gð GðV <@Ø4<´OÔ4KØ#'ð	)Að 59ð)Að )Að )Að )Að )Að )Að )Að )Að )Að )Ar!   r   N)rX   Ú
__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   r5   r!   r    ú<module>rc      s`  ððð ð #Ð "Ð "Ð "Ð "Ð "à GÐ GÐ GÐ GÐ GÐ GÐ GÐ GÐ GÐ GÐ GÐ GÐ GÐ GÐ GÐ Gà 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,ðð ð ð ð ð ð ð ð ð ð
 EÐ DÐ DÐ DÐ DÐ DØ FÐ FÐ FÐ FÐ FÐ Fð ð GØ5Ð5Ð5Ð5Ð5Ð5ØFÐFÐFÐFÐFÐFØFÐFÐFÐFÐFÐFðHAð HAð HAð HAð HAÐ+ñ HAô HAð HAð HAð HAr!   