o
    Zh                     @  s   d dl mZ d dlmZmZmZmZmZmZm	Z	m
Z
 d dlmZ d dlmZ d dlmZ e ZerCd dlmZ d dlmZ d dlmZ G d	d
 d
eZdS )    )annotations)TYPE_CHECKINGAnyAsyncIteratorCallableIteratorOptionalSequenceUnion)Document)
BaseLoader)aexecute_cql)Session)Host)	Statementc                
   @  sP   e Zd Zddddedd fdeddeddddd)d!d"Zd*d$d%Zd+d'd(ZdS ),CassandraLoaderNc                 C  s   i S )N )_r   r   e/var/www/html/lang_env/lib/python3.10/site-packages/langchain_community/document_loaders/cassandra.py<lambda>#   s    zCassandraLoader.<lambda>F)query_parametersquery_timeoutquery_tracequery_custom_payloadquery_execution_profilequery_paging_state
query_hostquery_execute_astableOptional[str]sessionOptional[Session]keyspacequeryUnion[str, Statement, None]page_content_mapperCallable[[Any], str]metadata_mapperCallable[[Any], dict]r   Union[dict, Sequence, None]r   Optional[float]r   boolr   Optional[dict]r   r   r   r   Optional[Host]r   returnNonec             	   C  s   |r|rt d|s|st d|r|r.|s.z
ddlm}m} W n ttfy-   tdw |rG|p5||}d| d| d| _||d	| _n|| _i | _|pR||| _|| _	|| _
||	|
|||d
| _|turm|| jd< |turx|| jd< dS dS )a  
        Document Loader for Apache Cassandra.

        Args:
            table: The table to load the data from.
                (do not use together with the query parameter)
            session: The cassandra driver session.
                If not provided, the cassio resolved session will be used.
            keyspace: The keyspace of the table.
                If not provided, the cassio resolved keyspace will be used.
            query: The query used to load the data.
                (do not use together with the table parameter)
            page_content_mapper: a function to convert a row to string page content.
                Defaults to the str representation of the row.
            metadata_mapper: a function to convert a row to document metadata.
            query_parameters: The query parameters used when calling session.execute .
            query_timeout: The query timeout used when calling session.execute .
            query_trace: Whether to use tracing when calling session.execute .
            query_custom_payload: The query custom_payload used when calling
                session.execute .
            query_execution_profile: The query execution_profile used when calling
                session.execute .
            query_host: The query host used when calling session.execute .
            query_execute_as: The query execute_as used when calling session.execute .
        z$Cannot specify both query and table.zMust specify query or table.r   )check_resolve_keyspacecheck_resolve_sessionz_Could not import a recent cassio package.Please install it with `pip install --upgrade cassio`.zSELECT * FROM .;)r   r"   )
parameterstraceZcustom_payloadZpaging_statehostZ
execute_astimeoutZexecution_profileN)
ValueErrorZcassio.configr0   r1   ImportErrorModuleNotFoundErrorr#   metadatar    r%   r'   query_kwargs_NOT_SET)selfr   r    r"   r#   r%   r'   r   r   r   r   r   r   r   r   r0   r1   Z	_keyspacer   r   r   __init__   sB   +
zCassandraLoader.__init__Iterator[Document]c                 c  sR    | j j| jfi | jD ]}| j }|| | t| 	||dV  qd S N)Zpage_contentr;   )
r    executer#   r<   r;   copyupdater'   r   r%   r>   rowr;   r   r   r   	lazy_loadp   s   


zCassandraLoader.lazy_loadAsyncIterator[Document]c                 C sX   t | j| jfi | jI d H D ]}| j }|| | t| 	||dV  qd S rA   )
r   r    r#   r<   r;   rC   rD   r'   r   r%   rE   r   r   r   
alazy_loadx   s   "


zCassandraLoader.alazy_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   r   r-   r   r   r.   r/   )r.   r@   )r.   rH   )__name__
__module____qualname__strr=   r?   rG   rI   r   r   r   r   r      s&    	
Tr   N)
__future__r   typingr   r   r   r   r   r   r	   r
   Zlangchain_core.documentsr   Z)langchain_community.document_loaders.baser   Z'langchain_community.utilities.cassandrar   objectr=   Zcassandra.clusterr   Zcassandra.poolr   Zcassandra.queryr   r   r   r   r   r   <module>   s    (