o
    Zh                     @  s\   d dl mZ d dlmZmZmZmZ d dlmZ d dl	m
Z
 d dlmZ G dd de
ZdS )	    )annotations)AnyIteratorOptionalSequence)Document)
BaseLoader)MaxComputeAPIWrapperc                   @  sB   e Zd ZdZddddddZeddddddZdddZdS )MaxComputeLoaderz+Load from `Alibaba Cloud MaxCompute` table.N)page_content_columnsmetadata_columnsquerystrapi_wrapperr	   r   Optional[Sequence[str]]r   c                C  s   || _ || _|| _|| _dS )a  Initialize Alibaba Cloud MaxCompute document loader.

        Args:
            query: SQL query to execute.
            api_wrapper: MaxCompute API wrapper.
            page_content_columns: The columns to write into the `page_content` of the
                Document. If unspecified, all columns will be written to `page_content`.
            metadata_columns: The columns to write into the `metadata` of the Document.
                If unspecified, all columns not added to `page_content` will be written.
        N)r   r   r   r   )selfr   r   r   r    r   g/var/www/html/lang_env/lib/python3.10/site-packages/langchain_community/document_loaders/max_compute.py__init__   s   
zMaxComputeLoader.__init__	access_idsecret_access_keyendpointprojectr   Optional[str]r   kwargsr   returnc                K  s$   t j||||d}| ||fi |S )a  Convenience constructor that builds the MaxCompute API wrapper from
            given parameters.

        Args:
            query: SQL query to execute.
            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	   from_params)clsr   r   r   r   r   r   r   r   r   r   r   %   s   zMaxComputeLoader.from_paramsIterator[Document]c                 #  s    j jD ]@}jrfdd| D  n| ddd   D }jr6fdd| D }n fdd| D }t||dV  qd S )	Nc                       i | ]\}}| j v r||qS r   )r   .0kvr   r   r   
<dictcomp>F   s    z.MaxComputeLoader.lazy_load.<locals>.<dictcomp>
c                 s  s"    | ]\}}| d | V  qdS )z: Nr   r!   r   r   r   	<genexpr>K   s     z-MaxComputeLoader.lazy_load.<locals>.<genexpr>c                   r    r   )r   r!   r%   r   r   r&   M   s     c                   s   i | ]\}}| vr||qS r   r   r!   )page_content_datar   r   r&   O   s    )page_contentmetadata)r   r   r   itemsjoinr   r   )r   rowr*   r+   r   )r)   r   r   	lazy_loadC   s   
zMaxComputeLoader.lazy_load)r   r   r   r	   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
      s    r
   N)
__future__r   typingr   r   r   r   Zlangchain_core.documentsr   Z)langchain_community.document_loaders.baser   Z)langchain_community.utilities.max_computer	   r
   r   r   r   r   <module>   s    