
    ɯei-                         d dl mZ d dlmZmZmZmZ d dlZ G d de      Z	 G d d      Z
 G d d	e
      Z G d
 de
      Zy)    )abstractmethod)DictList
NamedTupleTupleNc                   N    e Zd ZU dZeed<   eed<   dZeed<   dZe	ed<   defdZ
y)	QueryRecordz[Contains the query information returned from the Snowflake database after the query is run.query_idsql_textNis_describe	thread_idreturnc           	         | j                   )| j                  d| j                   d| j                   dS | j                   6| j                  *d| j                   d| j                   d| j                    dS | j                   6| j                  *d| j                   d| j                   d| j                   dS d| j                   d| j                   d| j                    d| j                   d	S )NzQueryRecord(query_id=z, sql_text=)z, is_describe=z, thread_id=)r   r   r
   r   selfs    b/var/www/html/glpi_dashboard/venv/lib/python3.12/site-packages/snowflake/snowpark/query_history.py__repr__zQueryRecord.__repr__   s   #(>*4==/T]]OSTUU)dnn.D*4==/T]]OSabfbrbrasstuu%$..*D*4==/T]]OS_`d`n`n_oopqq*4==/T]]OSabfbrbrass  AE  AO  AO  @P  PQ  R  R    )__name__
__module____qualname____doc__str__annotations__r   boolr   intr    r   r   r	   r	   
   s1    eMMKIsR# Rr   r	   c                   &    e Zd Zededdfd       Zy)QueryListenerquery_recordr   Nc                      y)z
        notify query listener of a query event
        Args:
            query_record: record of the query to notify the listener of
            **kwargs: optional keyword arguments
        Returns:
            None
        Nr   r   r!   kwargss      r   _notifyzQueryListener._notify   s     	r   )r   r   r   r   r	   r%   r   r   r   r    r       s"    	K 	d 	 	r   r    c                       e Zd ZdZ	 	 	 	 ddddededededd	fd
Zd Zd Zdedd	fdZ	e
dee   fd       Ze
defd       Ze
defd       Ze
defd       Ze
deeee   f   fd       Zy	)QueryHistoryzA context manager that listens to and records SQL queries that are pushed down to the Snowflake database.

    See also:
        :meth:`snowflake.snowpark.Session.query_history`.
    session"snowflake.snowpark.session.Sessioninclude_describeinclude_thread_idinclude_errorinclude_dataframe_profilingr   Nc                 t    || _         g | _        || _        || _        || _        || _        i | _        i | _        y N)r(   _queries_include_describe_include_thread_id_include_error_include_dataframe_profiling_dataframe_queries_describe_queries)r   r(   r*   r+   r,   r-   s         r   __init__zQueryHistory.__init__2   sB     +-!1"3+,G)8:EGr   c                     | S r/   r   r   s    r   	__enter__zQueryHistory.__enter__E       r   c                 N    | j                   j                  j                  |        y r/   r(   _connremove_query_listenerr   exc_typeexc_valexc_tbs       r   __exit__zQueryHistory.__exit__H       006r   r!   c                     | j                   rNd|v rJ|d   }|| j                  vrg | j                  |<   | j                  |   j                  |j                         | j                  j                  |       y )Ndataframe_uuid)r4   r5   appendr
   r0   )r   r!   r$   df_uuids       r   r%   zQueryHistory._notifyK   sm    ,,6) !12$"9"9979D++G4''0778M8MN\*r   c                     | j                   S r/   )r0   r   s    r   querieszQueryHistory.queriesT   s    }}r   c                     | j                   S )zKWhen True, QueryRecords for describe queries are recorded by this listener.)r1   r   s    r   r*   zQueryHistory.include_describeX   s     %%%r   c                     | j                   S )z@When True, thread id of the query are recorded by this listener.)r2   r   s    r   r+   zQueryHistory.include_thread_id]        &&&r   c                     | j                   S )zRWhen True, queries that have error during execution are recorded by this listener.)r3   r   s    r   r,   zQueryHistory.include_errorb   s     """r   c                     | j                   S )z2Returns a map of dataframe plan uuid to query ids.)r5   r   s    r   dataframe_querieszQueryHistory.dataframe_queriesg   rM   r   )FFFF)r   r   r   r   r   r7   r9   rC   r	   r%   propertyr   rJ   r*   r+   r,   r   r   r   rP   r   r   r   r'   r'   +   s    "'"'#,1H5H H  	H
 H &*H 
H&7+K +d + k*   &$ & & '4 ' ' #t # # '4T#Y#7 ' 'r   r'   c                   r    e Zd Z	 ddddeddfdZd Zd Zd	eddfd
Ze	defd       Z
e	dee   fd       Zy)AstListenerr(   r)   include_failuresr   Nc                 .    || _         g | _        || _        y)a  
        Initializes the AstListener.

        Args:
            session: The session to listen to.
            include_failures: When True, the listener will include failed queries in the history. This can be useful
                 for debugging and testing.
        N)r(   _ast_batches_include_failures)r   r(   rT   s      r   r7   zAstListener.__init__n   s     ')!1r   c                     | S r/   r   r   s    r   r9   zAstListener.__enter__   r:   r   c                 N    | j                   j                  j                  |        y r/   r<   r?   s       r   rC   zAstListener.__exit__   rD   r   r!   c                 J    d|v r| j                   j                  |d          y y )NdataframeAst)rV   rG   r#   s      r   r%   zAstListener._notify   s(    V#$$VN%;< $r   c                     | j                   S r/   )rW   r   s    r   rT   zAstListener.include_failures   s    %%%r   c                     | j                   S r/   )rV   r   s    r   base64_batcheszAstListener.base64_batches   s       r   )F)r   r   r   r   r7   r9   rC   r	   r%   rQ   rT   r   r   r^   r   r   r   rS   rS   m   s     "'252 2 
	2"7=K =d = &$ & & !S	 ! !r   rS   )abcr   typingr   r   r   r   snowflake.snowpark	snowflaker	   r    r'   rS   r   r   r   <module>rc      sD     0 0 R* R& ?'= ?'D"!- "!r   