o
    ȳgW
                     @  sR   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 dZdS )    )annotations)TYPE_CHECKINGIteratorListOptional)get_from_envODPSc                   @  sD   e Zd ZdZdddZeddddddZdddZdddZdS )MaxComputeAPIWrapperz7Interface for querying Alibaba Cloud MaxCompute tables.clientr	   c                 C  s
   || _ dS )zvInitialize MaxCompute document loader.

        Args:
            client: odps.ODPS MaxCompute client object.
        N)r   )selfr    r   e/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/langchain_community/utilities/max_compute.py__init__   s   
zMaxComputeAPIWrapper.__init__N)	access_idsecret_access_keyendpointstrprojectr   Optional[str]r   returnc             
   C  s   zddl m} W n ty } ztd|d}~ww |p tdd}|p'td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   r   r   r   from_params   s.   
z MaxComputeAPIWrapper.from_paramsqueryIterator[dict]c                 c  sd    | j | }|jdkrtd|D ]
}dd |D V  qW d    d S 1 s+w   Y  d S )Nr   zTable contains no data.c                 S  s   i | ]\}}||qS r   r   ).0kvr   r   r   
<dictcomp>I   s    z3MaxComputeAPIWrapper.lazy_query.<locals>.<dictcomp>)r   execute_sqlopen_readercountr   )r   r    readerrecordr   r   r   
lazy_queryC   s   
"zMaxComputeAPIWrapper.lazy_query
List[dict]c                 C  s   t | |S )N)listr+   )r   r    r   r   r   r    K   s   zMaxComputeAPIWrapper.query)r   r	   )
r   r   r   r   r   r   r   r   r   r
   )r    r   r   r!   )r    r   r   r,   )	__name__
__module____qualname____doc__r   classmethodr   r+   r    r   r   r   r   r
      s    

,r
   N)
__future__r   typingr   r   r   r   langchain_core.utilsr   r   r	   r
   r   r   r   r   <module>   s    