Ë
    kQêjt/  ã                   ó  — d Z ddlZddlZddlmZ ddlmZmZmZm	Z	m
Z
mZ ddlZddlmZ ddlmZ ddlmZmZmZ  e
d	«      Zg d
¢Z G d„ dee   «      ZdZdedefd„Zdededefd„Z G d„ dee   «      Zdddeegef   dee   fd„Zy)zIHandles to asynchronous registry jobs, SQL queries, and local operations.é    N)Ú	timedelta)ÚAnyÚCallableÚGenericÚOptionalÚTypeVarÚcast)ÚLOOPé   )Ú_lancedb)ÚJobDescriptionÚJobFailureInfoÚJobInfoÚT)ÚAsyncJobÚJobr   r   r   c                   ó´  — e Zd ZdZ	 ddee   deeegef      fd„Ze	dee
   fd„«       Zde
fd„Zdd	ee   defd
„Zd„ Zdd„Ze	dee
   fd„«       Ze	dee
   fd„«       Ze	dee   fd„«       Ze	dee   fd„«       Ze	dee   fd„«       Ze	dee   fd„«       Ze	dee
   fd„«       Ze	dee
   fd„«       Zde
dee   fd„Zdddœdee   dee
   ddfd„Zde
fd„Zy)r   zÛA handle to an operation that may still be running.

    The operation may already be complete when the handle is created. ``T``
    is the endpoint's terminal result type; unit-result jobs resolve to
    ``None``.
    NÚinnerÚresult_decoderc                 ó    — || _         || _        y ©N)Ú_innerÚ_result_decoder)Úselfr   r   s      úP/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/lancedb/job.pyÚ__init__zAsyncJob.__init__%   s   € ð
 ˆŒØ-ˆÕó    Úreturnc                 óJ   — | j                   �| j                   j                  S dS )aO  The operation's opaque ID, interpreted according to :attr:`job_type`.

        Registry jobs expose a registry job ID; SQL-backed jobs expose a
        connection-scoped query ID as a string. Local operations return ``None``.
        Query IDs cannot be used with registry job APIs or to resume after a
        client restart.
        N©r   Úid©r   s    r   r!   zAsyncJob.id-   s    € ð "&§¡Ð!8ˆt�{‰{�~‰~ÐB¸dÐBr   c              ƒ   ól   K  — | j                   €y| j                   j                  «       ƒ d{  –—† S 7 Œ­w)a4  The operation's current lifecycle state: "running", "finished",
        "failed", or "cancelled".

        A point snapshot; unlike `wait` it does not block or raise on a
        terminal failure state. States a newer server reports that this
        client version does not know pass through as-is.
        NÚfinished)r   Ústatusr"   s    r   r%   zAsyncJob.status8   s.   è ø€ ð �;‰;ÐØØ—[‘[×'Ñ'Ó)×)Ð)Ð)ús   ‚+4­2®4Útimeoutc              ƒ   óv  K  — | j                   €t        t        d«      S |€#| j                   j                  «       ƒ d{  –—† }nDt	        j
                  | j                   j                  «       |j                  «       «      ƒ d{  –—† }| j                  �| j                  |«      S t        t        |«      S 7 Œv7 Œ3­w)a.  Wait until the operation reaches a terminal state.

        Returns the endpoint's typed result, or ``None`` for a unit-result
        job.

        Raises `JobFailedError` if the operation failed, `JobCancelledError`
        if it was cancelled, and `TimeoutError` if `timeout` elapses first.
        N)r   r	   r   ÚwaitÚasyncioÚwait_forÚtotal_secondsr   )r   r&   Úresults      r   r(   zAsyncJob.waitD   s•   è ø€ ð �;‰;ÐÜœ˜4“=Ð Øˆ?ØŸ;™;×+Ñ+Ó-×-‰Fä"×+Ñ+¨D¯K©K×,<Ñ,<Ó,>À×@UÑ@UÓ@WÓX×XˆFØ×ÑÐ+Ø×'Ñ'¨Ó/Ð/Ü”A�v‹Ðð .øàXús"   ‚<B9¾B5¿AB9ÂB7Â2B9Â7B9c              ƒ   ón   K  — | j                   €y| j                   j                  «       ƒ d{  –—†  y7 Œ­w©zARequest cancellation. Cancelling a finished operation is a no-op.N)r   Úcancelr"   s    r   r/   zAsyncJob.cancelW   s)   è ø€ à�;‰;ÐØØ�k‰k× Ñ Ó"×"Ò"úó   ‚+5­3®5c              ƒ   ón   K  — | j                   €y| j                   j                  «       ƒ d{  –—†  y7 Œ­w)aä  Ask the backend for this job's current state, and for a server-side
        job its full record, then cache it for the properties below.

        Registry details are `None` until this runs, because submitting an
        operation does not fetch its full registry record. Query-backed jobs
        expose only lifecycle state through this method. For registry jobs,
        `status` fetches the whole record too; `wait` records only the terminal
        state it establishes.
        N)r   Úrefreshr"   s    r   r2   zAsyncJob.refresh]   s+   è ø€ ð �;‰;ÐØØ�k‰k×!Ñ!Ó#×#Ò#úr0   c                 óH   — | j                   €y| j                   j                  S )zœThe last observed lifecycle state, without contacting the backend.

        `None` until the handle has talked to it. See :meth:`AsyncJob.refresh`.
        r$   )r   Ú_stater"   s    r   ÚstatezAsyncJob.statek   s!   € ð �;‰;ÐØØ�{‰{×!Ñ!Ð!r   c                 óJ   — | j                   �| j                   j                  S dS )a  The job's kind of work, without contacting the backend.

        SQL-backed handles report ``"query"`` immediately. Registry handles
        report the server's job type after :meth:`refresh` or :meth:`status`.
        In-process handles return ``None``.
        N©r   Újob_typer"   s    r   r8   zAsyncJob.job_typeu   s"   € ð (,§{¡{Ð'>ˆt�{‰{×#Ñ#ÐHÀDÐHr   c                 ó$   — | j                  d«      S )z:When the job was created, in milliseconds since the epoch.Úcreation_ms©Ú_fieldr"   s    r   r:   zAsyncJob.creation_ms   ó   € ð �{‰{˜=Ó)Ð)r   c                 ó$   — | j                  d«      S )z:The job-type-specific specification it was submitted with.Úspecr;   r"   s    r   r?   zAsyncJob.spec„   ó   € ð �{‰{˜6Ó"Ð"r   c                 ó$   — | j                  d«      S )a  The job-type-specific terminal result, as reported data rather than
        the typed model :meth:`AsyncJob.wait` returns.

        `None` until the job succeeds, so a job that never terminates reports
        its progress through :meth:`AsyncJob.events` instead.
        r,   r;   r"   s    r   r,   zAsyncJob.result‰   s   € ð �{‰{˜8Ó$Ð$r   c                 ó$   — | j                  d«      S )zCWhy the job failed, when it failed and the server reports a reason.Úfailurer;   r"   s    r   rC   zAsyncJob.failure“   ó   € ð �{‰{˜9Ó%Ð%r   c                 ó$   — | j                  d«      S ©NÚ
_spec_jsonr;   r"   s    r   rG   zAsyncJob._spec_json˜   ó   € à�{‰{˜<Ó(Ð(r   c                 ó$   — | j                  d«      S ©NÚ_result_jsonr;   r"   s    r   rK   zAsyncJob._result_jsonœ   ó   € à�{‰{˜>Ó*Ð*r   Únamec                 ój   — | j                   �| j                   j                  nd }|�t        ||«      S d S r   )r   Ú_descriptionÚgetattr)r   rM   Údescriptions      r   r<   zAsyncJob._field    s3   € Ø26·+±+Ð2I�d—k‘k×.Ò.ÈtˆØ-8Ð-DŒw�{ DÓ)ÐNÈ$ÐNr   ©ÚlimitÚfilterrS   rT   úpa.Tablec             ƒ   ó†   K  — | j                   €t        d«      ‚| j                   j                  ||¬«      ƒ d{  –—† S 7 Œ­w)a—  This job's recorded lifecycle events.

        Where the properties above report a terminal result only once the job
        reaches one, events are written as the job runs and outlive the workers
        that produced them. A distributed job records a `claim`/`claim_complete`
        pair per unit of work, each carrying `rows_processed`, so a job that
        never finishes still accounts for what it did.

        Parameters
        ----------
        limit: int, optional
            Maximum event rows to return. The server caps results at 1000 by
            default and 10,000 at most, and truncates without saying so, so
            pass this for a job that emits an event per fragment.
        filter: str, optional
            SQL-like expression over the `state`, `updated_by`, `emitted_from`,
            `emitted_by`, and `claim_entity` columns, such as
            ``state = 'claim_complete'``.
        Nú8job event history is only available for server-side jobsrR   )r   ÚNotImplementedErrorÚevents©r   rS   rT   s      r   rY   zAsyncJob.events¤   sD   è ø€ ð2 �;‰;ÐÜ%ØJóð ð —[‘[×'Ñ'¨e¸FÐ'ÓC×CÐCÐCús   ‚8Aº?»Ac                 ó   — t        d| «      S )Nr   ©Ú	_job_reprr"   s    r   Ú__repr__zAsyncJob.__repr__Ã   s   € Ü˜ TÓ*Ð*r   r   ©r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   ÚpropertyÚstrr!   r%   r   r(   r/   r2   r5   r8   Úintr:   r?   r,   r   rC   rG   rK   r<   rY   r^   © r   r   r   r      sà  „ ñð 8<ñ.à˜‰}ð.ð ! ¨3¨%°¨(Ñ!3Ñ4ó.ð ðC�H˜S‘Mò Có ðCð
*˜có 
*ñ (¨9Ñ"5ð Àó ò&#ó$ð ð"�x ‘}ò "ó ð"ð ðI˜( 3™-ò Ió ðIð ð*˜X c™]ò *ó ð*ð ð#�h˜s‘mò #ó ð#ð ð%˜ ™ò %ó ð%ð ð&˜ .Ñ1ò &ó ð&ð ð)˜H S™Mò )ó ð)ð ð+˜h s™mò +ó ð+ðO˜3ð O 8¨C¡=ó Oð  $Ø $ò	Dð ˜‰}ðDð ˜‘ð	Dð
 
óDð>+˜#ô +r   r   z    Úvaluer   c                 ó˜   — 	 t        j                  | d¬«      }|j	                  ddt
        z   «      S # t        $ r t        | «      cY S w xY w)z?Render a job payload as indented JSON, aligned under its field.é   )Úindentú
)ÚjsonÚdumpsÚ	TypeErrorÚreprÚreplaceÚ_REPR_INDENT)rh   Úrendereds     r   Ú_repr_payloadrt   Ê   sL   € ðÜ—:‘:˜e¨AÔ.ˆð ×Ñ˜D $¬Ñ"5Ó6Ð6øô ò Ü�E‹{Òðús   ‚2 ²A	ÁA	ÚkindÚjobc                 ó@  — |j                   }|€&|j                  �d|j                  ›d�nd}| › d|› d�S g }|j                  �|j                  d|j                  ›�«       |j                  d|›�«       dD ]'  }t        ||«      }|€Œ|j                  |› d|›�«       Œ) d	D ]0  }t        ||«      }|€Œ|j                  |› dt	        |«      › �«       Œ2 |j
                  �|j                  d
|j
                  ›�«       dj                  d„ |D «       «      }| › d|› d�S )zÊRender every field the handle currently knows, omitting the rest.

    One field per line, with the JSON payloads indented, because a refresh
    job's spec and result are the point of printing it.
    zid=z, Ú ú(znot refreshed)zstate=)r8   r:   ú=)r?   r,   zfailure=c              3   ó4   K  — | ]  }d t         › |› d�–— Œ y­w)rl   ú,N)rr   )Ú.0Úfields     r   ú	<genexpr>z_job_repr.<locals>.<genexpr>í   s   è ø€ ÒC°5�Rœ�~ e W¨AÔ.ÑCùs   ‚z
))r5   r!   ÚappendrP   rt   rC   Újoin)ru   rv   r5   ÚknownÚfieldsrM   rh   Úbodys           r   r]   r]   Ó   s=  € ð �I‰I€EØ€}à&)§f¡fÐ&8�#�c—f‘f�Z˜rÑ"¸bˆØ��q˜˜˜~Ð.Ð.à€FØ
‡v�vÐØ�‰˜˜CŸF™F˜:Ð&Ô'Ø
‡M�M�F˜5˜)Ð$Ô%Ø+ò /ˆÜ˜˜TÓ"ˆØÑØ�M‰M˜T˜F ! E 9Ð-Õ.ð/ð #ò <ˆÜ˜˜TÓ"ˆØÑØ�M‰M˜T˜F !¤M°%Ó$8Ð#9Ð:Õ;ð<ð ‡{�{ÐØ�‰˜ §¡ Ð0Ô1Ø�7‰7ÑC¸FÔCÓC€DØˆV�1�T�F˜#ÐÐr   c                   ó   — e Zd ZdZdeee      fd„Zedee	   fd„«       Z
de	fd„Zddee   defd	„Zd
„ Zdd„Zedee	   fd„«       Zedee	   fd„«       Zedee   fd„«       Zedee   fd„«       Zedee   fd„«       Zedee   fd„«       Zedee	   fd„«       Zedee	   fd„«       Zde	dee   fd„Zdddœdee   dee	   ddfd„Zde	fd„Zy)r   z@Synchronous counterpart of `AsyncJob` with the same result type.r   c                 ó   — || _         y r   )r   )r   r   s     r   r   zJob.__init__ô   s	   € Øˆ�r   r   c                 óJ   — | j                   �| j                   j                  S dS )zeIdentifies the operation on the server that is running it.

        See :attr:`AsyncJob.id`.
        Nr    r"   s    r   r!   zJob.id÷   s    € ð "&§¡Ð!8ˆt�{‰{�~‰~ÐB¸dÐBr   c                 óv   — | j                   €yt        j                  | j                   j                  «       «      S )z�The operation's current lifecycle state: "running", "finished",
        "failed", or "cancelled".

        See :meth:`AsyncJob.status`.
        r$   )r   r
   Úrunr%   r"   s    r   r%   z
Job.statusÿ   s-   € ð �;‰;ÐØÜ�x‰x˜Ÿ™×*Ñ*Ó,Ó-Ð-r   Nr&   c                 ó–   — | j                   €t        t        d«      S t        j                  | j                   j                  |«      «      S )a/  Block until the operation reaches a terminal state.

        Returns the endpoint's typed result, or ``None`` for a unit-result
        job.

        Raises `JobFailedError` if the operation failed, `JobCancelledError`
        if it was cancelled, and `TimeoutError` if `timeout` elapses first.
        N)r   r	   r   r
   r‰   r(   )r   r&   s     r   r(   zJob.wait	  s8   € ð �;‰;ÐÜœ˜4“=Ð Ü�x‰x˜Ÿ™×(Ñ(¨Ó1Ó2Ð2r   c                 óx   — | j                   €yt        j                  | j                   j                  «       «       yr.   )r   r
   r‰   r/   r"   s    r   r/   z
Job.cancel  s(   € à�;‰;ÐØÜ�‰�—‘×#Ñ#Ó%Õ&r   c                 óx   — | j                   €yt        j                  | j                   j                  «       «       y)zhAsk the backend for this job's current state and record.

        See :meth:`AsyncJob.refresh`.
        N)r   r
   r‰   r2   r"   s    r   r2   zJob.refresh  s*   € ð
 �;‰;ÐØÜ�‰�—‘×$Ñ$Ó&Õ'r   c                 óJ   — | j                   �| j                   j                  S dS )z>The last observed lifecycle state. See :attr:`AsyncJob.state`.r$   )r   r5   r"   s    r   r5   z	Job.state%  s"   € ð %)§K¡KÐ$;ˆt�{‰{× Ñ ÐKÀÐKr   c                 óJ   — | j                   �| j                   j                  S dS )z.The job's type. See :attr:`AsyncJob.job_type`.Nr7   r"   s    r   r8   zJob.job_type*  s"   € ð (,§{¡{Ð'>ˆt�{‰{×#Ñ#ÐHÀDÐHr   c                 ó$   — | j                  d«      S )z;When the job was created. See :attr:`AsyncJob.creation_ms`.r:   r;   r"   s    r   r:   zJob.creation_ms/  r=   r   c                 ó$   — | j                  d«      S )z3The job's specification. See :attr:`AsyncJob.spec`.r?   r;   r"   s    r   r?   zJob.spec4  r@   r   c                 ó$   — | j                  d«      S )z7The job's terminal result. See :attr:`AsyncJob.result`.r,   r;   r"   s    r   r,   z
Job.result9  s   € ð �{‰{˜8Ó$Ð$r   c                 ó$   — | j                  d«      S )z1Why the job failed. See :attr:`AsyncJob.failure`.rC   r;   r"   s    r   rC   zJob.failure>  rD   r   c                 ó$   — | j                  d«      S rF   r;   r"   s    r   rG   zJob._spec_jsonC  rH   r   c                 ó$   — | j                  d«      S rJ   r;   r"   s    r   rK   zJob._result_jsonG  rL   r   rM   c                 óJ   — | j                   �t        | j                   |«      S d S r   )r   rP   )r   rM   s     r   r<   z
Job._fieldK  s!   € Ø-1¯[©[Ð-DŒw�t—{‘{ DÓ)ÐNÈ$ÐNr   rR   rS   rT   rU   c                ó�   — | j                   €t        d«      ‚t        j                  | j                   j	                  ||¬«      «      S )zTThis job's recorded lifecycle events.

        See :meth:`AsyncJob.events`.
        rW   rR   )r   rX   r
   r‰   rY   rZ   s      r   rY   z
Job.eventsN  sC   € ð �;‰;ÐÜ%ØJóð ô �x‰x˜Ÿ™×*Ñ*°¸vÐ*ÓFÓGÐGr   c                 ó   — t        d| «      S )Nr   r\   r"   s    r   r^   zJob.__repr__^  s   € Ü˜ Ó%Ð%r   r   r_   )r`   ra   rb   rc   r   r   r   r   rd   re   r!   r%   r   r(   r/   r2   r5   r8   rf   r:   r   r?   r,   r   rC   rG   rK   r<   rY   r^   rg   r   r   r   r   ñ   sÆ  „ ÙJð˜h x°¡{Ñ3ó ð ðC�H˜S‘Mò Có ðCð.˜ó .ñ3˜H YÑ/ð 3¸1ó 3ò'ó(ð ðL�x ‘}ò Ló ðLð ðI˜( 3™-ò Ió ðIð ð*˜X c™]ò *ó ð*ð ð#�h˜s‘mò #ó ð#ð ð%˜ ™ò %ó ð%ð ð&˜ .Ñ1ò &ó ð&ð ð)˜H S™Mò )ó ð)ð ð+˜h s™mò +ó ð+ðO˜3ð O 8¨C¡=ó Oð  $Ø $ò	Hð ˜‰}ðHð ˜‘ð	Hð
 
óHð &˜#ô &r   r   r   z_lancedb.Jobr   c                 ó   — t        | |«      S )z?Bind an internal JSON-producing job to its public result model.)r   )r   r   s     r   Ú
_typed_jobr™   b  s   € ô �E˜>Ó*Ð*r   )rc   r)   rm   Údatetimer   Útypingr   r   r   r   r   r	   ÚpyarrowÚpaÚlancedb.background_loopr
   rx   r   r   r   r   r   Ú__all__r   rr   re   rt   r]   r   r™   rg   r   r   ú<module>r       s¿   ðñ Pã Û Ý ß B× Bã å (å ß =Ñ =áˆCƒL€ò€ôg+ˆw�q‰zô g+ðT €ð7˜ð 7 ó 7ð�Cð ˜cð  có ô<n&ˆ'�!‰*ô n&ðb+Øð+Ø+3°S°E¸1°HÑ+=ð+àˆa�[ô+r   