Ë
    kQêjo$  ã                  ód  — d Z ddlmZ ddlmZ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rddlZdd	lmZ dd
lmZmZ dZe
eee
ee	eef   f      eeef   df   ZeZdZ	 e G d„ d«      «       Z 	 	 	 	 	 	 dd„Z!ddd„Z"dd„Z#dd„Z$dd„Z%dd„Z&d d„Z' G d„ d«      Z( G d„ d«      Z)y)!a~  Materialized views: tables defined by a query over a source table and
maintained by refresh. See ``DBConnection.create_materialized_view``.

Local creation and refresh require the ``experimental-functions`` Cargo feature
in a source build. Published packages disable it. Opening, reading, listing and
dropping existing views and remote Cloud/Enterprise operations remain available.
é    )Úannotations)ÚTYPE_CHECKINGÚDictÚListÚOptionalÚSequenceÚTupleÚUnionN)Ú	dataclassé   )ÚLOOP)ÚAsyncJobÚJobÚ
_typed_job©ÚRefreshMaterializedViewResult)Ú
AsyncTableÚ
LanceTables   mv.definitioné   c                  ó   — e Zd ZU dZded<   y)ÚMaterializedViewDefinitiona)  The query that defines a materialized view, as stored::

        SELECT columns
        FROM [ns.]table [, function(args) AS alias | , UNNEST(column) AS alias]
        [WHERE predicate] [GROUP BY expr, ...] [LIMIT n]

    A Function in ``FROM`` position yields one row per element it returns.
    ÚstrÚqueryN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__© ó    ú^/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/lancedb/materialized_view.pyr   r   /   s   … ñð ƒJØJr    r   c                ó¬   — | j                   xs i }|j                  t        «      }|€t        d|› d�«      ‚t	        t        j                  |«      |«      S )NzTable 'z' is not a materialized view)ÚmetadataÚgetÚDEFINITION_META_KEYÚ
ValueErrorÚ_definition_from_valueÚjsonÚloads)ÚschemaÚnamer#   Úraws       r!   Ú_definition_from_schemar-   >   sP   € ð �‰Ò$ "€HØ
�,‰,Ô*Ó
+€CØ
€{Ü˜7 4 &Ð(DÐEÓFÐFÜ!¤$§*¡*¨S£/°4Ó8Ð8r    c                ó@   — t        t        j                  | «      |«      S )zBParse the definition native code hands over, in its stored layout.)r'   r(   r)   )r,   r+   s     r!   Ú_definition_from_jsonr/   H   s   € ä!¤$§*¡*¨S£/°4Ó8Ð8r    c                ó  — | j                  d«      }|�:t        |t        «      r	|t        kD  rt	        d|› d|› d�«      ‚t        | d   ¬«      S | j                  d«      }|dvrt	        d|› d	|› d
�«      ‚t        t        | «      ¬«      S )NÚformatzmaterialized view 'z' is stored in format z., which this version of lancedb cannot refreshr   )r   Úkind)ÚselectÚnamespaced_selectz' is stored in format kind 'z/', which this version of lancedb cannot refresh)r$   Ú
isinstanceÚintÚDEFINITION_FORMATÚNotImplementedErrorr   Ú_legacy_query)Úvaluer+   Úfmtr2   s       r!   r'   r'   M   s­   € Ø
�)‰)�HÓ
€CØ
€ä˜#œsÔ# sÔ->Ò'>Ü%Ø% d VÐ+AÀ#Àð G9ð 9óð ô *°°g±Ô?Ð?à�9‰9�VÓ€DØÐ2Ñ2Ü!Ø! $ Ð'CÀDÀ6ð J;ð ;ó
ð 	
ô &¬M¸%Ó,@ÔAÐAr    c                óD   — | rt        d„ | D «       «      r| S t        | «      S )Nc              3  ón   K  — | ]-  }|d k(  xs" |j                  «       xs |j                  «       –— Œ/ y­w)Ú_N)ÚislowerÚisdigit)Ú.0Úcs     r!   ú	<genexpr>z _legacy_ident.<locals>.<genexpr>b   s-   è ø€ ÒI¸q�A˜‘HÒ: §	¡	£Ò:¨q¯y©y«{Ó:ÑIùs   ‚35)ÚallÚ_quote_identifier©r+   s    r!   Ú_legacy_identrG   a   s"   € Ù”ÑIÀDÔIÔIØˆÜ˜TÓ"Ð"r    c                óÚ  — | j                  dg «      }|reg }|D ]L  }|d   |d   }}||t        |«      fv r|j                  |«       Œ.|j                  |› dt        |«      › �«       ŒN dj	                  |«      }nd}dj	                  d„ g | j                  d	g «      ¢| d
   ‘D «       «      }d|› d|› �}| j                  d«      �|d| d   › �z  }| j                  d«      �|d| d   › �z  }|S )zBRender the pre-format structured layout as the query it described.ÚprojectionsÚoutputÚ
expressionz AS z, Ú*ú.c              3  ó2   K  — | ]  }t        |«      –— Œ y ­w©N)rG   )rA   Úparts     r!   rC   z _legacy_query.<locals>.<genexpr>u   s   è ø€ ò àô 	�d×ñùs   ‚Úsource_namespaceÚsource_tablezSELECT z FROM Úfilterz WHERE Úlimitz LIMIT )r$   rE   ÚappendrG   Újoin)	r:   rI   ÚitemsÚprJ   rK   ÚcolumnsÚtabler   s	            r!   r9   r9   g   s&  € à—)‘)˜M¨2Ó.€KÙØˆØò 	IˆAØ!" 8¡¨a°©o�JˆFØ˜fÔ&7¸Ó&?Ð@Ñ@Ø—‘˜ZÕ(à—‘ 
˜|¨4´¸fÓ0EÐ/FÐGÕHð	Ið —)‘)˜EÓ"‰àˆØ�H‰Hñ àO�e—i‘iÐ 2°BÓ7ÐO¸¸~Ñ9NÐOôó €Eð �g�Y˜f U GÐ,€EØ‡y�y�ÓÐ&Ø�7˜5 ™?Ð+Ð,Ñ,ˆØ‡y�y�ÓÐ%Ø�7˜5 ™>Ð*Ð+Ñ+ˆØ€Lr    c                ó2   — | j                  dd«      }d|› d�S )z:Quote a column name as a Lance SQL identifier (backticks).ú`z``)Úreplace)r+   Úescapeds     r!   rE   rE   �   s    € à�l‰l˜3 Ó%€GØˆwˆi�qˆ>Ðr    c                ó   — | €yt        | t        «      r| g} t        | t        «      rt        | j	                  «       «      S g }| D ]G  }t        |t        «      r|j                  |t        |«      f«       Œ0|\  }}|j                  ||f«       ŒI |S )aL  ``select`` items may be a column name, an ``(alias, expression)`` pair,
    or a dict of the same. A bare name projects itself and is quoted, so any
    valid column name works; dict and pair entries are kept verbatim because
    their right side is an expression.

    A lone string is one column, not a sequence of its characters.N)r5   r   ÚdictÚlistrW   rU   rE   )r3   Ú
normalizedÚitemÚaliasrK   s        r!   Únormalize_selectre   ‡   s”   € ð €~ØÜ�&œ#ÔØ�ˆÜ�&œ$ÔÜ�F—L‘L“NÓ#Ð#Ø€JØò 3ˆÜ�dœCÔ Ø×Ñ˜tÔ%6°tÓ%<Ð=Õ>à $ÑˆE�:Ø×Ñ˜u jÐ1Õ2ð3ð Ðr    c                  ó€   — e Zd ZdZdd„Zdd„Zedd„«       Zedd„«       Zdd„Z	ddd	œ	 	 	 	 	 dd
„Z
ddd	œ	 	 	 	 	 dd„Zy)ÚAsyncMaterializedViewz·A handle on a materialized view: its table plus its definition.

    Obtained from ``AsyncConnection.create_materialized_view`` or
    ``AsyncConnection.open_materialized_view``.
    c                ó   — || _         y rO   ©Ú_table©ÚselfrZ   s     r!   Ú__init__zAsyncMaterializedView.__init__¥   s	   € Øˆ�r    c                ó"   — d| j                   ›d�S )NzAsyncMaterializedView(name=ú)rF   ©rl   s    r!   Ú__repr__zAsyncMaterializedView.__repr__¨   s   € Ø,¨T¯Y©Y¨M¸Ð;Ð;r    c                ó.   — | j                   j                  S rO   ©rj   r+   rp   s    r!   r+   zAsyncMaterializedView.name«   ó   € à�{‰{×ÑÐr    c                ó   — | j                   S )z�The view, as the table it is. Queries, indexes and search all
        apply; writes are not blocked, but a rebuild replaces them.ri   rp   s    r!   rZ   zAsyncMaterializedView.table¯   s   € ð �{‰{Ðr    c              ƒ  ó|   K  — | j                   j                  j                  «       ƒ d{  –—† }t        |«      S 7 Œ­w)ú The query that defines the view.N)rj   Ú_innerÚmaterialized_view_definitionr/   )rl   r,   s     r!   Ú
definitionz AsyncMaterializedView.definitionµ   s2   è ø€ à—K‘K×&Ñ&×CÑCÓE×EˆÜ$ SÓ)Ð)ð Fús   ‚(<ª:«<FN©ÚfullÚsource_versionc             ƒ  ól   K  — | j                   j                  j                  ||¬«      ƒ d{  –—† S 7 Œ­w)aâ  Recompute the view from its source.

        ``full=True`` forces a remote rebuild; otherwise the server chooses
        the refresh mode. Local views always rebuild, and ``source_version``
        selects a source version instead of the latest. Remote SQL refreshes
        do not support source-version pinning.

        Remote results leave ``mode``, ``rows_written``, and ``source_version``
        as ``None`` because the SQL job adapter does not expose these metrics.
        ©r}   r|   N)rj   rx   Úrefresh_materialized_view©rl   r|   r}   s      r!   ÚrefreshzAsyncMaterializedView.refreshº   s:   è ø€ ð —[‘[×'Ñ'×AÑAØ)°ð Bó 
÷ 
ð 	
ð 
ús   ‚+4­2®4c             ƒ  ó    K  — ddl m} t        | j                  j                  j                  ||¬«      ƒ d{  –—† |j                  «      S 7 Œ­w)a&  Submit a refresh and return its job without waiting.

        The job may already be complete for a local view. Remote refreshes are
        submitted through the SQL service. Options and result metrics follow
        [refresh][lancedb.materialized_view.AsyncMaterializedView.refresh].
        r   r   r   N)Ú_lancedbr   r   rj   rx   Úrefresh_materialized_view_asyncÚ	from_json)rl   r|   r}   r   s       r!   Úrefresh_asyncz#AsyncMaterializedView.refresh_asyncË   sP   è ø€ õ 	<äØ—+‘+×$Ñ$×DÑDØ-°Dð Eó ÷ ð *×3Ñ3ó	
ð 	
ðús   ‚6A¸A¹A)rZ   ú'AsyncTable'©Úreturnr   )rŠ   rˆ   ©rŠ   r   ©r|   Úboolr}   úOptional[int]rŠ   z'RefreshMaterializedViewResult')r|   r�   r}   rŽ   rŠ   z)'AsyncJob[RefreshMaterializedViewResult]'©r   r   r   r   rm   rq   Úpropertyr+   rZ   rz   r‚   r‡   r   r    r!   rg   rg   ž   s†   „ ñóó<ð ò ó ð ð òó ðó
*ð $ÀTñ
Øð
Ø5Bð
à	(ó
ð$ $ÀTñ
Øð
Ø5Bð
à	2ô
r    rg   c                  óŠ   — e Zd ZdZdd„Zdd„Zedd„«       Zedd„«       Zedd„«       Z	ddd	œ	 	 	 	 	 dd
„Z
ddd	œ	 	 	 	 	 dd„Zy)ÚMaterializedViewzdSynchronous variant of
    [AsyncMaterializedView][lancedb.materialized_view.AsyncMaterializedView].c                óF   — || _         t        |j                   «      | _        y rO   )rj   rg   Ú_asyncrk   s     r!   rm   zMaterializedView.__init__â   s   € ØˆŒÜ+¨E¯L©LÓ9ˆ�r    c                ó"   — d| j                   ›d�S )NzMaterializedView(name=ro   rF   rp   s    r!   rq   zMaterializedView.__repr__æ   s   € Ø'¨¯	©	 }°AÐ6Ð6r    c                ó.   — | j                   j                  S rO   rs   rp   s    r!   r+   zMaterializedView.nameé   rt   r    c                ó   — | j                   S )zThe view, as the table it is.ri   rp   s    r!   rZ   zMaterializedView.tableí   s   € ð �{‰{Ðr    c                ó\   — t        j                  | j                  j                  «       «      S )rw   )r   Úrunr”   rz   rp   s    r!   rz   zMaterializedView.definitionò   s    € ô �x‰x˜Ÿ™×.Ñ.Ó0Ó1Ð1r    FNr{   c               ób   — t        j                  | j                  j                  ||¬«      «      S )z‰Recompute the view from its source. See
        [AsyncMaterializedView.refresh][lancedb.materialized_view.AsyncMaterializedView.refresh].r{   )r   r™   r”   r‚   r�   s      r!   r‚   zMaterializedView.refresh÷   s'   € ô
 �x‰x˜Ÿ™×+Ñ+°ÀnÐ+ÓUÓVÐVr    c               ót   — t        t        j                  | j                  j	                  ||¬«      «      «      S )z¸Submit a refresh and return its job without waiting.

        See
        [AsyncMaterializedView.refresh_async][lancedb.materialized_view.AsyncMaterializedView.refresh_async].
        r{   )r   r   r™   r”   r‡   r�   s      r!   r‡   zMaterializedView.refresh_asyncþ   s4   € ô Ü�H‰HØ—‘×)Ñ)¨tÀNÐ)ÓSóó
ð 	
r    )rZ   ú'LanceTable'r‰   )rŠ   rœ   r‹   rŒ   )r|   r�   r}   rŽ   rŠ   z$'Job[RefreshMaterializedViewResult]'r�   r   r    r!   r’   r’   Þ   sš   „ ñQó:ó7ð ò ó ð ð òó ðð ò2ó ð2ð
 $ÀTñWØðWØ5BðWà	(óWð $ÀTñ
Øð
Ø5Bð
à	-ô
r    r’   )r*   z'pa.Schema'r+   r   rŠ   r   )Ú )r,   r   r+   r   rŠ   r   )r:   r`   r+   r   rŠ   r   )r+   r   rŠ   r   )r:   r`   rŠ   r   )r3   Ú	SelectArgrŠ   zOptional[List[Tuple[str, str]]])*r   Ú
__future__r   Útypingr   r   r   r   r   r	   r
   r(   Údataclassesr   Úbackground_loopr   Újobr   r   r   ÚpyarrowÚpar„   r   rZ   r   r   r%   r   rž   ÚMaterializedViewSourcer7   r   r-   r/   r'   rG   r9   rE   re   rg   r’   r   r    r!   ú<module>r§      sõ   ðñõ #ç N× NÑ Nã Ý !å !ß *Ñ *áÛå7ß-à&Ð àØØˆU�3˜˜c 3˜h™Ð'Ñ(Ñ)Øˆˆcˆ�NØð
ñ€	ð Ð ð Ð ð)ð
 ÷Kð Kó ðKð9Øð9Ø"ð9àó9ô9ó
Bó(#óó4ó÷.=
ñ =
÷@,
ò ,
r    