o
    EDi                     @   s\   d dl mZ d dlmZ G dd deZG dd deZG dd deZG d	d
 d
eZdS )   )BlockStreamProfileInfo)Progressc                       4   e Zd ZdZ	d	 fdd	Zdd Zdd Z  ZS )
QueryResultz3
    Stores query result from multiple blocks.
    Fc                    s0   || _ || _g | _g | _|| _tt|   d S N)packet_generatorwith_column_typesdatacolumns_with_typescolumnarsuperr   __init__)selfr   r   r   	__class__ Q/var/www/Datamplify/venv/lib/python3.10/site-packages/clickhouse_driver/result.pyr   
   s   zQueryResult.__init__c                 C   s   t |dd }|d u rd S |jr@| jr6| }| jr,t|D ]\}}| j| | qd S dd |D | _d S | j|  d S | jsI|j| _d S d S )Nblockc                 S      g | ]}t |qS r   )list.0cr   r   r   
<listcomp>&       z%QueryResult.store.<locals>.<listcomp>)	getattrnum_rowsr   get_columnsr	   	enumerateextendget_rowsr
   )r   packetr   columnsicolumnr   r   r   store   s   zQueryResult.storec                 C   sF   | j D ]}| | q| j}| jrdd | jD }| jr!|| jfS |S )z/
        :return: stored query result.
        c                 S   r   r   )tupler   r   r   r   r   7   r   z*QueryResult.get_result.<locals>.<listcomp>)r   r%   r	   r   r   r
   )r   r!   r	   r   r   r   
get_result-   s   

zQueryResult.get_result)FF)__name__
__module____qualname____doc__r   r%   r'   __classcell__r   r   r   r   r      s    r   c                       s<   e Zd ZdZ fddZdd Zdd Z fdd	Z  ZS )
ProgressQueryResultzx
    Stores query result and progress information from multiple blocks.
    Provides iteration over query progress.
    c                    s"   t  | _tt| j|i | d S r   )r   progress_totalsr   r-   r   )r   argskwargsr   r   r   r   E   s   zProgressQueryResult.__init__c                 C      | S r   r   r   r   r   r   __iter__I      zProgressQueryResult.__iter__c                 C   sD   	 t | j}t|dd }|r| j| | jj| jjfS | | q)NTprogress)nextr   r   r.   	incrementrows
total_rowsr%   )r   r!   progress_packetr   r   r   __next__L   s   

zProgressQueryResult.__next__c                    s   | D ]}qt t|  S r   )r   r-   r'   )r   _r   r   r   r'   X   s   zProgressQueryResult.get_result)	r(   r)   r*   r+   r   r3   r;   r'   r,   r   r   r   r   r-   ?   s    r-   c                       r   )
IterQueryResultzP
    Provides iteration over returned data by chunks (streaming by chunks).
    Fc                    s$   || _ || _d| _tt|   d S )NT)r   r   first_blockr   r=   r   )r   r   r   r   r   r   r   e   s   zIterQueryResult.__init__c                 C   r1   r   r   r2   r   r   r   r3   n   r4   zIterQueryResult.__iter__c                 C   sV   t | j}t|dd }|d u rg S | jr'| jr'd| _|jg}||  |S | S )Nr   F)r6   r   r   r>   r   r
   r   r    )r   r!   r   rvr   r   r   r;   q   s   
zIterQueryResult.__next__)F)r(   r)   r*   r+   r   r3   r;   r,   r   r   r   r   r=   `   s    	r=   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
	QueryInfoc                 C   s   t  | _t | _d| _d S )N    )r   profile_infor   r5   elapsedr2   r   r   r   r      s   
zQueryInfo.__init__c                 C   
   || _ d S r   )rB   )r   rB   r   r   r   store_profile      
zQueryInfo.store_profilec                 C   s    | j r| j | d S || _ d S r   )r5   r7   )r   r5   r   r   r   store_progress   s   
zQueryInfo.store_progressc                 C   rD   r   )rC   )r   rC   r   r   r   store_elapsed   rF   zQueryInfo.store_elapsedN)r(   r)   r*   r   rE   rG   rH   r   r   r   r   r@      s
    r@   N)	blockstreamprofileinfor   r5   r   objectr   r-   r=   r@   r   r   r   r   <module>   s    :! 