
    it	                         d dl mZmZmZmZ d dlZddlmZ  G d d      Z	dej                  deej                  ej                  f   fd	Zy)
    )ListOptionalTupleUnionN   )RecordBatchStreamc                       e Zd ZdZ	 ddeeej                  f   dee	   fdZ
deej                     fdZd Zdej                  fd	Ze	 dd
ej                  dee	   fd       Zy)AsyncRecordBatchReaderzo
    An async iterator over a stream of RecordBatches.

    Also allows access to the schema of the stream
    Ninnermax_batch_lengthc                     t        |t        j                        r)| j                  ||      | _        |j
                  | _        yt        |t              r|| _        |j
                  | _        yt        d      )z

        Attributes
        ----------
        schema : pa.Schema
            The schema of the batches produced by the stream.
            Accessing the schema does not consume any data from the stream
        z,inner must be a RecordBatchStream or a TableN)
isinstancepaTable_async_iter_from_table_innerschemar   	TypeError)selfr   r   s      I/mnt/e/genesis-system/.venv/lib/python3.12/site-packages/lancedb/arrow.py__init__zAsyncRecordBatchReader.__init__   s[     eRXX&55e=MNDK%*\\DK01DK%*\\DKJKK    returnc                 D   K   | 2 cg c3 d{   }|7 6 c}S c c}w w)z
        Read all the record batches from the stream

        This consumes the entire stream and returns a list of record batches

        If there are a lot of results this may consume a lot of memory
        N )r   batchs     r   read_allzAsyncRecordBatchReader.read_all(   s#      *.......s$    
 c                     | S Nr   r   s    r   	__aiter__z AsyncRecordBatchReader.__aiter__2   s    r   c                 R   K   | j                   j                          d {   S 7 wr   )r   	__anext__r    s    r   r#   z AsyncRecordBatchReader.__anext__5   s     [[**,,,,s   '%'tablec                H   K   | j                  |      }|D ]  }| 	 yw)z
        Create an AsyncRecordBatchReader from a Table

        This is useful when you have a Table that you want to iterate
        over asynchronously
        )max_chunksizeN)
to_batches)r$   r   batchesr   s       r   r   z-AsyncRecordBatchReader._async_iter_from_table8   s0      ""1A"B 	EK	s    "r   )__name__
__module____qualname____doc__r   r   r   r   r   intr   r   RecordBatchr   r!   r#   staticmethodr   r   r   r   r
   r
      s     +/L&01L #3-L,/R^^ 4 /- - ;?xx+3C= r   r
   readerr   c                      t         t        j                        st        d       j	                          fd}t        j                  j                  j                   |             fS )Nz"reader must be a RecordBatchReaderc               3   .   K     E d {    y 7 wr   r   )r   r0   s   r   all_batchesz peek_reader.<locals>.all_batchesN   s     s   
)r   r   RecordBatchReaderr   read_next_batchfrom_batchesr   )r0   r3   r   s   ` @r   peek_readerr7   G   sZ     fb223<==""$E "&&33ELL+-PPPr   )typingr   r   r   r   pyarrowr   _lancedbr   r
   r4   r.   r7   r   r   r   <module>r;      sP    0 /  '9 9xQ  Q
2>>2///0Qr   