
    7|h                        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rd dlmZ d dlmZ d dlmZ  G d	 d
e      Zy)    )annotations)TYPE_CHECKINGAnyAsyncIteratorCallableIteratorOptionalSequenceUnion)Document)
BaseLoader)aexecute_cql)Session)Host)	Statementc            
          e Zd Zdddded fdeddedddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZd	dZd
dZy)CassandraLoaderNc                    i S )N )_s    m/var/www/html/test/engine/venv/lib/python3.12/site-packages/langchain_community/document_loaders/cassandra.py<lambda>zCassandraLoader.<lambda>#   s    2     F)query_parametersquery_timeoutquery_tracequery_custom_payloadquery_execution_profilequery_paging_state
query_hostquery_execute_asc                  |r|rt        d      |s|st        d      |r|r|s		 ddlm}m} |r%|xs  |      }d| d| d| _        ||d	| _        n|| _        i | _        |xs  |      | _        || _	        || _
        ||	|
|||d
| _        |t        ur|| j                  d<   |t        ur|| j                  d<   yy# t        t
        f$ r t	        d      w xY w)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 .;)tablekeyspace)
parameterstracecustom_payloadpaging_statehost
execute_astimeoutexecution_profileN)
ValueErrorcassio.configr#   r$   ImportErrorModuleNotFoundErrorquerymetadatasessionpage_content_mappermetadata_mapperquery_kwargs_NOT_SET)selfr'   r7   r(   r5   r8   r9   r   r   r   r   r   r   r    r!   r#   r$   	_keyspaces                     r   __init__zCassandraLoader.__init__   s   V UCDDU;<<5W  D$:8$DI))AeWA>DJ&+CDMDJDM@"7"@#6 . + 2.*
 (+8Di("(25LD12 3;  !45 !M s   C   Cc              #  (  K    | j                   j                  | j                  fi | j                  D ]Z  }| j                  j                         }|j                  | j                  |             t        | j                  |      |       \ y wN)page_contentr6   )
r7   executer5   r:   r6   copyupdater9   r   r8   r<   rowr6   s      r   	lazy_loadzCassandraLoader.lazy_loadp   s{     '4<<''

Hd6G6GH 	C}}))+HOOD0056!55c:X 	s   BBc               2  K   t        | j                  | j                  fi | j                   d {   D ][  }| j                  j                         }|j                  | j                  |             t        | j                  |      |       ] y 7 cwr@   )
r   r7   r5   r:   r6   rC   rD   r9   r   r8   rE   s      r   
alazy_loadzCassandraLoader.alazy_loadx   s{     %dllDJJT$BSBSTT 	C}}))+HOOD0056!55c:X 	Ts   /BBA$B)r'   Optional[str]r7   zOptional[Session]r(   rJ   r5   zUnion[str, Statement, None]r8   zCallable[[Any], str]r9   zCallable[[Any], dict]r   zUnion[dict, Sequence, None]r   zOptional[float]r   boolr   zOptional[dict]r   r   r   r   r    zOptional[Host]r!   rJ   returnNone)rL   zIterator[Document])rL   zAsyncIterator[Document])__name__
__module____qualname__strr;   r>   rG   rI   r   r   r   r   r      s      $%)"&-1471=RM 9=)1!/3'/"&%)*.!RMRM #RM  	RM
 +RM 2RM /RM 6RM 'RM RM -RM "%RM  RM #RM  (!RM" 
#RMhr   r   N)
__future__r   typingr   r   r   r   r   r	   r
   r   langchain_core.documentsr   )langchain_community.document_loaders.baser   'langchain_community.utilities.cassandrar   objectr;   cassandra.clusterr   cassandra.poolr   cassandra.queryr   r   r   r   r   <module>r[      sC    "	 	 	 . @ @8)#)cj cr   