Ë
    kQêj,  ã                   óL  — d Z ddlmZmZmZmZmZ ddlmZ ddl	Z
ddlZddlmZ ddlmZ ddlmZ ej&                  Zeej(                  ej*                  ee   eeef   f   Z	 d	ed
ej0                  fd„Zdee   d
eej(                     fd„Z G d„ d«      Z G d„ d«      Zg d¢Zy)z4Handles to SQL queries running on a remote database.é    )ÚAnyÚMappingÚOptionalÚSequenceÚUnion)ÚUUIDN)ÚLOOPé   )Ú_lancedb)ÚAsyncRecordBatchReaderÚvalueÚreturnc                 ó°  — t        | t        j                  «      r0t        j                  | j	                  «       g| j
                  ¬«      S t        | t        j                  «      r| j                  «       } t        | t        j                  «      rp| j                  dk(  r$t        j                  | j                  d«      «      S | j                  dk7  rt        d| j                  › d�«      ‚t        j                  | «      } t        | t        j                  «      r)t        j                  j                  | t!        | «      «      S t        j                  | g«      S )z5One parameter as a one-element array of its own type.)Útyper   r
   z>a numpy query parameter must be a scalar or a 1-D vector, got z dimensions)Ú
isinstanceÚpaÚScalarÚarrayÚas_pyr   ÚChunkedArrayÚcombine_chunksÚnpÚndarrayÚndimÚreshapeÚ
ValueErrorÚArrayÚFixedSizeListArrayÚfrom_arraysÚlen)r   s    úP/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/lancedb/sql.pyÚ_parameter_arrayr"      sô   € ä�%œŸ™Ô#Ü�x‰x˜Ÿ™›˜¨e¯j©jÔ9Ð9ô �%œŸ™Ô)Ø×$Ñ$Ó&ˆÜ�%œŸ™Ô$Ø�:‰:˜Š?Ü—8‘8˜EŸM™M¨!Ó,Ó-Ð-Ø�:‰:˜Š?ÜðØ—z‘z�l +ð/óð ô —‘˜“ˆÜ�%œŸ™Ô"Ü×$Ñ$×0Ñ0°¼¸E»
ÓCÐCÜ�8‰8�U�GÓÐó    Ú
parametersc           
      óþ  — | €yt        | t        j                  «      r| }�n t        | t        j                  «      r^| j	                  «       j                  «       }t        |«      dk(  r|d   n*t        j                  j                  g | j                  ¬«      }�n(t        | t        «      rlt        j                  j                  | j                  «       D �cg c]  }t        |«      ‘Œ c}| j                  «       D �cg c]  }t        |«      ‘Œ c}¬«      }n¬t        | t        «      r{t        | t        t         f«      set        j                  j                  | D �cg c]  }t        |«      ‘Œ c}t#        t        | «      «      D �cg c]  }t        |dz   «      ‘Œ c}¬«      }n!t%        dt'        | «      j(                  › �«      ‚|j*                  dk7  rt-        d|j*                  › �«      ‚|S c c}w c c}w c c}w c c}w )aN  Turn ``parameters`` into the one-row batch a parameterized query sends.

    Scalars keep the type pyarrow infers for them (numpy scalars keep their
    dtype), a ``pyarrow.Scalar`` keeps its own type, and a 1-D numpy or
    pyarrow array becomes a ``FixedSizeList`` of its element type, which is
    what a vector column stores.
    Nr
   r   )Úschema)Únamesz_query parameters must be a sequence, a mapping, or a one-row pyarrow RecordBatch or Table, not z.query parameters must be exactly one row, got )r   r   ÚRecordBatchÚTabler   Ú
to_batchesr    Úfrom_pylistr&   r   r   Úvaluesr"   ÚkeysÚstrr   ÚbytesÚrangeÚ	TypeErrorr   Ú__name__Únum_rowsr   )r$   ÚbatchÚbatchesr   ÚnameÚpositions         r!   Úto_parameter_batchr8   4   s¬  € ð ÐØä�*œbŸn™nÔ-ØŠÜ	�J¤§¡Ô	)Ø×+Ñ+Ó-×8Ñ8Ó:ˆô �7‹|˜qÒ ð �AŠJä—‘×+Ñ+¨B°z×7HÑ7HÐ+ÓIò 	ô
 
�J¤Ô	(Ü—‘×*Ñ*Ø2<×2CÑ2CÓ2EÖF¨Ô˜eÕ$ÒFØ)3¯©Ó):Ö; ”3�t•9Ò;ð +ó 
‰ô 
�J¤Ô	)´*¸ZÌ#ÌuÈÔ2VÜ—‘×*Ñ*Ø2<Ö=¨Ô˜eÕ$Ò=Ü5:¼3¸z»?Ó5KÖL¨”3�x !‘|Õ$ÒLð +ó 
‰ô
 ð1Ü15°jÓ1A×1JÑ1JÐ0KðMó
ð 	
ð ‡~�~˜ÒÜØ<¸U¿^¹^Ð<LÐMó
ð 	
ð €Lùò# GùÚ;ùò >ùÚLs   ÃG+Ã;G0
ÅG5ÆG:
c                   óN   — e Zd ZdZd	d„Zedefd„«       Zdefd„Z	de
fd„Zd
d„Zy)Ú
AsyncQueryz@A handle to a submitted SQL query on an asynchronous connection.c                 ó   — || _         y ©N©Ú_inner©ÚselfÚinners     r!   Ú__init__zAsyncQuery.__init__c   ó	   € Øˆ�r#   r   c                 ó.   — | j                   j                  S ©zAThe stable identifier scoped to the connection that submitted it.©r>   Úid©r@   s    r!   rG   zAsyncQuery.idf   ó   € ð �{‰{�~‰~Ðr#   c              ƒ   óR   K  — | j                   j                  «       ƒ d{  –—† S 7 Œ­w)ú-Get a point-in-time description of the query.N)r>   ÚdescriberH   s    r!   rL   zAsyncQuery.describek   s   è ø€ à—[‘[×)Ñ)Ó+×+Ð+Ð+ús   ‚' %¡'c              ƒ   ód   K  — t        | j                  j                  «       ƒ d{  –—† «      S 7 Œ­w)a&  Wait for the initial result stream and return its Arrow reader.

        Results are single-consumer. Calling this method more than once on the
        same query raises an error. Later batches are streamed as they become
        available without waiting for the full query to finish.
        N)r   r>   ÚreaderrH   s    r!   rN   zAsyncQuery.readero   s&   è ø€ ô &¨D¯K©K×,>Ñ,>Ó,@×&@ÓAÐAÐ&@ús   ‚#0¥.¦	0Nc              ƒ   óT   K  — | j                   j                  «       ƒ d{  –—†  y7 Œ­w©z"Request cancellation of the query.N)r>   ÚcancelrH   s    r!   rQ   zAsyncQuery.cancelx   s   è ø€ à�k‰k× Ñ Ó"×"Ò"ús   ‚( &¡()rA   z_lancedb.SqlQuery©r   N)r2   Ú
__module__Ú__qualname__Ú__doc__rB   Úpropertyr   rG   ÚQueryDescriptionrL   r   rN   rQ   © r#   r!   r:   r:   `   sF   „ ÙJóð ð�Dò ó ðð,Ð 0ó ,ðBÐ4ó Bô#r#   r:   c                   óf   — e Zd ZdZdefd„Zedefd„«       Zde	fd„Z
dej                  fd„Zd
d	„Zy)ÚQueryz/Synchronous counterpart of :class:`AsyncQuery`.rA   c                 ó   — || _         y r<   r=   r?   s     r!   rB   zQuery.__init__€   rC   r#   r   c                 ó.   — | j                   j                  S rE   rF   rH   s    r!   rG   zQuery.idƒ   rI   r#   c                 ó\   — t        j                  | j                  j                  «       «      S )rK   )r	   Úrunr>   rL   rH   s    r!   rL   zQuery.describeˆ   s   € ä�x‰x˜Ÿ™×,Ñ,Ó.Ó/Ð/r#   c                 óÒ   ‡‡— t        j                  | j                  j                  «       «      Šˆfd„Šˆfd„}t        j
                  j                  ‰j                   |«       «      S )a)  Wait for the initial result stream and return a blocking reader.

        Results are single-consumer. Calling this method more than once on the
        same query raises an error. Later batches block only until they become
        available, without waiting for the full query to finish.
        c                  ój   •— 	 t        j                  ‰ j                  «       «      S # t        $ r Y y w xY wr<   )r	   r^   Ú	__anext__ÚStopAsyncIteration)rN   s   €r!   Ú
next_batchz Query.reader.<locals>.next_batch•   s2   ø€ ðÜ—x‘x × 0Ñ 0Ó 2Ó3Ð3øÜ%ò Ùðús   ƒ"& ¦	2±2c               3   ó>   •K  —  ‰«       x} �| –—  ‰«       x} �Œy y ­wr<   rX   )r4   rc   s    €r!   r5   zQuery.reader.<locals>.batches›   s(   øè ø€ Ù&›LÐ(�5Ð5Ø’ñ '›LÐ(�5Ó5ùs   ƒ›)r	   r^   r>   rN   r   ÚRecordBatchReaderÚfrom_batchesr&   )r@   r5   rc   rN   s     @@r!   rN   zQuery.readerŒ   sK   ù€ ô —‘˜$Ÿ+™+×,Ñ,Ó.Ó/ˆô	ô	ô ×#Ñ#×0Ñ0°·±ÁÃ	ÓJÐJr#   Nc                 ó^   — t        j                  | j                  j                  «       «       yrP   )r	   r^   r>   rQ   rH   s    r!   rQ   zQuery.cancel¡   s   € ä�‰�—‘×#Ñ#Ó%Õ&r#   rR   )r2   rS   rT   rU   r:   rB   rV   r   rG   rW   rL   r   re   rN   rQ   rX   r#   r!   rZ   rZ   }   sR   „ Ù9ð˜jó ð ð�Dò ó ðð0Ð*ó 0ðK˜×,Ñ,ó Kô*'r#   rZ   )r:   rZ   rW   ÚQueryParameters)rU   Útypingr   r   r   r   r   Úuuidr   Únumpyr   Úpyarrowr   Úlancedb.background_loopr	   Ú r   Úarrowr   rW   r(   r)   r.   rh   r   r"   r8   r:   rZ   Ú__all__rX   r#   r!   ú<module>rq      s³   ðñ ;ç :Õ :Ý ã Û å (å Ý )à×,Ñ,Ð à˜Ÿ™¨¯©°(¸3±-ÀÈÈcÈÑARÐRÑS€ðð˜Cð  B§H¡Hó ð.)Ø˜Ñ)ð)àˆb�n‰nÑó)÷X#ñ #÷:&'ñ &'òR I�r#   