a
    bg                     @  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rd 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                   @  sx   e Zd Zddddedd fdeddeddddddddd	d
ddddddddddddZddddZddddZdS )CassandraLoaderNc                 C  s   i S )N )_r   r   |/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/document_loaders/cassandra.py<lambda>#       zCassandraLoader.<lambda>F)query_parametersquery_timeoutquery_tracequery_custom_payloadquery_execution_profilequery_paging_state
query_hostquery_execute_aszOptional[str]zOptional[Session]zUnion[str, Statement, None]zCallable[[Any], str]zCallable[[Any], dict]zUnion[dict, Sequence, None]zOptional[float]boolzOptional[dict]r   zOptional[Host]None)tablesessionkeyspacequerypage_content_mappermetadata_mapperr   r   r   r   r   r   r   r   returnc             	   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Y n0 |r|pn||}d| d| d| _||d	| _n|| _i | _|p||| _|| _	|| _
||	|
|||d
| _|tur|| jd< |tur|| jd< 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.configr(   r)   ImportErrorModuleNotFoundErrorr$   metadatar"   r%   r&   query_kwargs_NOT_SET)selfr!   r"   r#   r$   r%   r&   r   r   r   r   r   r   r   r   r(   r)   Z	_keyspacer   r   r   __init__   s>    +

zCassandraLoader.__init__zIterator[Document])r'   c                 c  sP   | j j| jfi | jD ]2}| j }|| | t| 	||dV  qd S N)Zpage_contentr3   )
r"   executer$   r4   r3   copyupdater&   r   r%   r6   rowr3   r   r   r   	lazy_loadp   s    

zCassandraLoader.lazy_loadzAsyncIterator[Document]c                 C sV   t | j| jfi | jI d H D ]2}| j }|| | t| 	||dV  qd S r8   )
r   r"   r$   r4   r3   r:   r;   r&   r   r%   r<   r   r   r   
alazy_loadx   s    "

zCassandraLoader.alazy_load)__name__
__module____qualname__strr5   r7   r>   r?   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   objectr5   Zcassandra.clusterr   Zcassandra.poolr   Zcassandra.queryr   r   r   r   r   r   <module>   s   (