a
    bg                     @  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                
   @  s`   e Zd ZdZdddddddddd	Zeddd
ddddddd dddZddddZdS )MaxComputeLoaderz+Load from `Alibaba Cloud MaxCompute` table.N)page_content_columnsmetadata_columnsstrr	   zOptional[Sequence[str]]queryapi_wrapperr   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.
        Nr   )selfr   r   r   r    r   ~/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/document_loaders/max_compute.py__init__   s    zMaxComputeLoader.__init__	access_idsecret_access_keyzOptional[str]r   )r   endpointprojectr   r   kwargs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_paramszIterator[Document])r   c                 #  s   j jD ]}jr0fdd| D  n| ddd   D }jrjfdd| D }n fdd| D }t||dV  qd S )	Nc                   s    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       z-MaxComputeLoader.lazy_load.<locals>.<genexpr>c                   s    i | ]\}}| j v r||qS r   )r   r   r"   r   r   r#   M   r&   c                   s   i | ]\}}| vr||qS r   r   r   )page_content_datar   r   r#   O   r&   )page_contentmetadata)r   r   r   itemsjoinr   r   )r   rowr(   r)   r   )r'   r   r   	lazy_loadC   s    
zMaxComputeLoader.lazy_load)__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
   