
    NgW
                    `    d dl mZ d dlmZmZmZmZ d dlmZ erd dl	m
Z
  G d d          ZdS )    )annotations)TYPE_CHECKINGIteratorListOptional)get_from_envODPSc                  J    e Zd ZdZddZeddddd            ZddZddZdS )MaxComputeAPIWrapperz7Interface for querying Alibaba Cloud MaxCompute tables.clientr
   c                    || _         dS )zvInitialize MaxCompute document loader.

        Args:
            client: odps.ODPS MaxCompute client object.
        N)r   )selfr   s     e/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/utilities/max_compute.py__init__zMaxComputeAPIWrapper.__init__   s         N)	access_idsecret_access_keyendpointstrprojectr   Optional[str]r   returnc               "   	 ddl m} n"# t          $ r}t          d          |d}~ww xY w|pt          dd          }|pt          dd          } |||||	          }|                    |          st          d
| d           | |          S )az  Convenience constructor that builds the odsp.ODPS MaxCompute client from
            given parameters.

        Args:
            endpoint: MaxCompute endpoint.
            project: A project is a basic organizational unit of MaxCompute, which is
                similar to a database.
            access_id: MaxCompute access ID. Should be passed in directly or set as the
                environment variable `MAX_COMPUTE_ACCESS_ID`.
            secret_access_key: MaxCompute secret access key. Should be passed in
                directly or set as the environment variable
                `MAX_COMPUTE_SECRET_ACCESS_KEY`.
        r   r	   zCould not import pyodps python package. Please install it with `pip install pyodps` or refer to https://pyodps.readthedocs.io/.Nr   MAX_COMPUTE_ACCESS_IDr   MAX_COMPUTE_SECRET_ACCESS_KEY)r   r   r   r   zThe project "z" does not exist.)odpsr
   ImportErrorr   exist_project
ValueError)clsr   r   r   r   r
   exr   s           r   from_paramsz MaxComputeAPIWrapper.from_params   s    ,	!!!!!!! 	 	 	2  		 Sk;R!S!S	- 
!@2
 2
 /	
 
 
 ##G,, 	IGWGGGHHHs6{{s   	 
(#(queryIterator[dict]c              #     K   | j                             |                                          5 }|j        dk    rt	          d          |D ]}d |D             V  	 d d d            d S # 1 swxY w Y   d S )Nr   zTable contains no data.c                    i | ]\  }}||	S  r(   ).0kvs      r   
<dictcomp>z3MaxComputeAPIWrapper.lazy_query.<locals>.<dictcomp>I   s    ///1q!///r   )r   execute_sqlopen_readercountr    )r   r$   readerrecords       r   
lazy_queryzMaxComputeAPIWrapper.lazy_queryC   s      [$$U++7799 	0V|q   !:;;;  0 0/////////0	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0s   .A++A/2A/
List[dict]c                F    t          |                     |                    S )N)listr2   )r   r$   s     r   r$   zMaxComputeAPIWrapper.queryK   s    DOOE**+++r   )r   r
   )
r   r   r   r   r   r   r   r   r   r   )r$   r   r   r%   )r$   r   r   r3   )	__name__
__module____qualname____doc__r   classmethodr#   r2   r$   r(   r   r   r   r      s        AA     $(+/* * * * * [*X0 0 0 0, , , , , ,r   r   N)
__future__r   typingr   r   r   r   langchain_core.utilsr   r   r
   r   r(   r   r   <module>r>      s    " " " " " " : : : : : : : : : : : : - - - - - - A, A, A, A, A, A, A, A, A, A,r   