
    Ng                        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dS )    )annotations)TYPE_CHECKINGAnyAsyncIteratorCallableIteratorOptionalSequenceUnion)Document)
BaseLoader)aexecute_cql)Session)Host)	Statementc            
      J    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dS )(CassandraLoaderNc                    i S )N )_s    j/var/www/html/ai-engine/env/lib/python3.11/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_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                  |r|rt          d          |s|st          d          |r|r0|s.	 ddlm}m} n$# t          t
          f$ r t	          d          w xY w|r&|p
 ||          }d| d| d| _        ||d	| _        n|| _        i | _        |p
 ||          | _        || _	        || _
        ||	|
|||d
| _        |t          ur
|| j        d<   |t          ur|| 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tracecustom_payloadpaging_statehost
execute_astimeoutexecution_profileN)
ValueErrorcassio.configr5   r6   ImportErrorModuleNotFoundErrorr'   metadatar$   r)   r+   query_kwargs_NOT_SET)selfr"   r$   r&   r'   r)   r+   r   r   r   r   r   r   r    r!   r5   r6   	_keyspaces                     r   __init__zCassandraLoader.__init__   s   V  	EU 	ECDDD 	=U 	=;<<< 	5 	 	WWWWWWWWW!45   !M    	 D$:$:8$D$DI>)>>e>>>DJ&+CCDMMDJDM@"7"7"@"@#6 . + 2.*
 
 ((+8Di("(225LD1222 32s	   7 !AIterator[Document]c              #    K    | j         j        | j        fi | j        D ]i}| j                                        }|                    |                     |                     t          | 	                    |          |          V  jd S N)page_contentrE   )
r$   executer'   rF   rE   copyupdater+   r   r)   rH   rowrE   s      r   	lazy_loadzCassandraLoader.lazy_loadp   s      '4<'
HHd6GHH 	 	C}))++HOOD0055666!55c::X      	 	r   AsyncIterator[Document]c               &  K   t          | j        | j        fi | j         d {V D ]j}| j                                        }|                    |                     |                     t          | 	                    |          |          W V  kd S rM   )
r   r$   r'   rF   rE   rP   rQ   r+   r   r)   rR   s      r   
alazy_loadzCassandraLoader.alazy_loadx   s      %dlDJTT$BSTTTTTTTT 	 	C}))++HOOD0055666!55c::X       	 	r   )r"   r#   r$   r%   r&   r#   r'   r(   r)   r*   r+   r,   r   r-   r   r.   r   r/   r   r0   r   r   r   r   r    r1   r!   r#   r2   r3   )r2   rK   )r2   rU   )__name__
__module____qualname__strrG   rJ   rT   rW   r   r   r   r   r      s          $%)"&-1471=RM 9=)1!/3'/"&%)*.!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   objectrG   cassandra.clusterr   cassandra.poolr   cassandra.queryr   r   r   r   r   <module>re      s:   " " " " " "	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 . - - - - - @ @ @ @ @ @ @ @ @ @ @ @688 *))))))######))))))c c c c cj c c c c cr   