o
    gZh/=                     @   sH   d dl Zd dlmZ ddlmZ ddlmZmZm	Z	 G dd deZ
dS )    N)ObjectApiResponse   )NamespacedClient)SKIP_IN_PATH_quote_rewrite_parametersc                0   @   s  e Zd Zeddddddddedeje dejejeej	e f  deje d	eje d
e
ej fddZe ddddddedeje dejejeej	e f  deje d	eje d
e
ej fddZe ddddddddddedeje deje dejejeej	e f  deje deje dejejddef  d	eje dejejddef  d
e
ej fddZe ddddddedeje dejejeej	e f  deje d	eje d
e
ej fddZedddhddddddddddddddddddddddddeje d eje deje deje d!eje d"eje d#ejejeejf  dejejeej	e f  deje deje d$eje dejejddef  d%eje d&ejejddef  dejejeejf  d	eje d'eje dejejddef  d(ejejeejeejf f  d)eje dejejddef  d
e
ej f,d*d+Zedddddddddd,d'edeje d!eje d#ejejeejf  dejejeej	e f  deje d	eje d)eje d
e
ej fd-d.ZdS )/	SqlClientT)body_fieldsN)error_tracefilter_pathhumanprettycursorr
   r   r   r   returnc          
      C   s   |du rt dd}i }i }|dur||d< |dur||d< |dur&||d< |dur.||d< |dur6||d< d	d	d
}	| jd|||	|dS )z
        Clears the SQL cursor

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/clear-sql-cursor-api.html>`_

        :param cursor: Cursor to clear.
        Nz)Empty value passed for parameter 'cursor'z/_sql/closer   r
   r   r   r   application/jsonacceptzcontent-typePOSTparamsheadersbody
ValueErrorperform_request)
selfr   r
   r   r   r   _SqlClient__path_SqlClient__body_SqlClient__query_SqlClient__headers r    U/var/www/html/lang_env/lib/python3.10/site-packages/elasticsearch/_sync/client/sql.pyclear_cursor   s&   

zSqlClient.clear_cursoridc          	      C   |   |t v rtddt| }i }|dur||d< |dur!||d< |dur)||d< |dur1||d< dd	i}| jd
|||dS )a(  
        Deletes an async SQL search or a stored synchronous SQL search. If the search
        is still running, the API cancels it.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/delete-async-sql-search-api.html>`_

        :param id: Identifier for the search.
        %Empty value passed for parameter 'id'z/_sql/async/delete/Nr
   r   r   r   r   r   DELETEr   r   r   r   r   r   	r   r#   r
   r   r   r   r   r   r   r    r    r!   delete_asyncB       zSqlClient.delete_async)	delimiterr
   r   formatr   
keep_aliver   wait_for_completion_timeoutr,   r-   r.   zt.Literal[-1]zt.Literal[0]r/   c       	         C   s   |t v rtddt| }
i }|dur||d< |dur!||d< |dur)||d< |dur1||d< |dur9||d< |durA||d	< |durI||d
< |	durQ|	|d< ddi}| jd|
||dS )a  
        Returns the current status and available results for an async SQL search or stored
        synchronous SQL search

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/get-async-sql-search-api.html>`_

        :param id: Identifier for the search.
        :param delimiter: Separator for CSV results. The API only supports this parameter
            for CSV responses.
        :param format: Format for the response. You must specify a format using this
            parameter or the Accept HTTP header. If you specify both, the API uses this
            parameter.
        :param keep_alive: Retention period for the search and its results. Defaults
            to the `keep_alive` period for the original SQL search.
        :param wait_for_completion_timeout: Period to wait for complete results. Defaults
            to no timeout, meaning the request waits for complete search results.
        r%   z/_sql/async/Nr,   r
   r   r-   r   r.   r   r/   r   r   GETr'   r(   )r   r#   r,   r
   r   r-   r   r.   r   r/   r   r   r   r    r    r!   	get_asynce   s0   !zSqlClient.get_asyncc          	      C   r$   )a  
        Returns the current status of an async SQL search or a stored synchronous SQL
        search

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/get-async-sql-search-status-api.html>`_

        :param id: Identifier for the search.
        r%   z/_sql/async/status/Nr
   r   r   r   r   r   r0   r'   r(   r)   r    r    r!   get_async_status   r+   zSqlClient.get_async_statusr   request_timeout)r	   Zignore_deprecated_options)catalogcolumnarr   r
   
fetch_sizefield_multi_value_leniencyfilterr   r-   r   index_using_frozenr.   keep_on_completionpage_timeoutr   r   queryr3   runtime_mappings	time_zoner/   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   c                C   sz  d}i }i }|dur||d< |dur||d< |dur||d< |dur&||d< |dur.||d< |dur6||d< |dur>||d	< |durF||d
< |	durN|	|d< |
durV|
|d< |dur^||d< |durf||d< |durn||d< |durv||d< |dur~||d< |dur||d< |dur||d< |dur||d< |dur||d< |dur||d< |dur||d< ddd}| j d||||dS )u	  
        Executes a SQL request

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/sql-search-api.html>`_

        :param catalog: Default catalog (cluster) for queries. If unspecified, the queries
            execute on the data in the local cluster only.
        :param columnar: If true, the results in a columnar fashion: one row represents
            all the values of a certain column from the current page of results.
        :param cursor: Cursor used to retrieve a set of paginated results. If you specify
            a cursor, the API only uses the `columnar` and `time_zone` request body parameters.
            It ignores other request body parameters.
        :param fetch_size: The maximum number of rows (or entries) to return in one response
        :param field_multi_value_leniency: Throw an exception when encountering multiple
            values for a field (default) or be lenient and return the first value from
            the list (without any guarantees of what that will be - typically the first
            in natural ascending order).
        :param filter: Elasticsearch query DSL for additional filtering.
        :param format: Format for the response.
        :param index_using_frozen: If true, the search can run on frozen indices. Defaults
            to false.
        :param keep_alive: Retention period for an async or saved synchronous search.
        :param keep_on_completion: If true, Elasticsearch stores synchronous searches
            if you also specify the wait_for_completion_timeout parameter. If false,
            Elasticsearch only stores async searches that don’t finish before the wait_for_completion_timeout.
        :param page_timeout: The timeout before a pagination request fails.
        :param params: Values for parameters in the query.
        :param query: SQL query to run.
        :param request_timeout: The timeout before the request fails.
        :param runtime_mappings: Defines one or more runtime fields in the search request.
            These fields take precedence over mapped fields with the same name.
        :param time_zone: ISO-8601 time zone ID for the search.
        :param wait_for_completion_timeout: Period to wait for complete results. Defaults
            to no timeout, meaning the request waits for complete search results. If
            the search doesn’t finish within this period, the search becomes async.
        z/_sqlNr4   r5   r   r
   r6   r7   r8   r   r-   r   r9   r.   r:   r;   r   r   r<   r3   r=   r>   r/   r   r   r   r   )r   )r   r4   r5   r   r
   r6   r7   r8   r   r-   r   r9   r.   r:   r;   r   r   r<   r3   r=   r>   r/   r   r   r   r   r    r    r!   r<      sb   E

zSqlClient.query)r
   r6   r8   r   r   r   r>   c                C   s   |du rt dd}	i }
i }|dur||
d< |dur||d< |dur&||
d< |dur.||
d< |dur6||d< |dur>||d	< |durF||d
< |durN||
d< ddd}| jd|	|||
dS )a  
        Translates SQL into Elasticsearch queries

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/sql-translate-api.html>`_

        :param query: SQL query to run.
        :param fetch_size: The maximum number of rows (or entries) to return in one response.
        :param filter: Elasticsearch query DSL for additional filtering.
        :param time_zone: ISO-8601 time zone ID for the search.
        Nz(Empty value passed for parameter 'query'z/_sql/translater<   r
   r6   r8   r   r   r   r>   r   r   r   r   r   )r   r<   r
   r6   r8   r   r   r   r>   r   r   r   r   r    r    r!   	translate9  s2   

zSqlClient.translate)__name__
__module____qualname__r   strtOptionalboolUnionSequencer   Anyr"   r*   r1   r2   intMappingr<   r?   r    r    r    r!   r      s   $"	
9"	
s	
r   )typingrD   Zelastic_transportr   _baser   utilsr   r   r   r   r    r    r    r!   <module>   s
   