a
    bg
                     @  s   d dl mZ d dlmZmZmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ er`d dlmZ edd	d
dG dd deZdS )    )annotations)TYPE_CHECKINGListOptional)
deprecated)Document)
BaseLoader)get_client_info)Credentialsz0.0.32z1.0z)langchain_google_community.BigQueryLoader)ZsinceZremovalZalternative_importc                   @  s6   e Zd ZdZddddddddd	Zd
dddZdS )BigQueryLoaderah  Load from the Google Cloud Platform `BigQuery`.

    Each document represents one row of the result. The `page_content_columns`
    are written into the `page_content` of the document. The `metadata_columns`
    are written into the `metadata` of the document. By default, all columns
    are written into the `page_content` and none into the `metadata`.

    NstrzOptional[str]zOptional[List[str]]zOptional[Credentials]queryprojectpage_content_columnsmetadata_columnscredentialsc                 C  s"   || _ || _|| _|| _|| _dS )a  Initialize BigQuery document loader.

        Args:
            query: The query to run in BigQuery.
            project: Optional. The project to run the query in.
            page_content_columns: Optional. The columns to write into the `page_content`
                of the document.
            metadata_columns: Optional. The columns to write into the `metadata` of the
                document.
            credentials : google.auth.credentials.Credentials, optional
              Credentials for accessing Google APIs. Use this parameter to override
                default credentials, such as to use Compute Engine
                (`google.auth.compute_engine.Credentials`) or Service Account
                (`google.oauth2.service_account.Credentials`) credentials directly.
        Nr   )selfr   r   r   r   r    r   {/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/document_loaders/bigquery.py__init__   s
    zBigQueryLoader.__init__zList[Document])returnc              
     s  zddl m} W n. ty> } ztd|W Y d }~n
d }~0 0 |j| j| jtddd}|jsld}t||| j	 }g }| j
| j d u rdd	 |jD  d u rg  |D ]L}d
fdd| D } fdd| D }	t||	d}
||
 q|S )Nr   )bigqueryzrCould not import google-cloud-bigquery python package. Please install it with `pip install google-cloud-bigquery`.r   )module)r   r   Zclient_infozGCP project for Big Query is not set! Either provide a `project` argument during BigQueryLoader instantiation, or set a default project with `gcloud config set project` command.c                 S  s   g | ]
}|j qS r   )name).0columnr   r   r   
<listcomp>X       z'BigQueryLoader.load.<locals>.<listcomp>
c                 3  s(   | ] \}}| v r| d | V  qdS )z: Nr   r   kv)r   r   r   	<genexpr>]   s   z&BigQueryLoader.load.<locals>.<genexpr>c                   s   i | ]\}}| v r||qS r   r   r    )r   r   r   
<dictcomp>`   r   z'BigQueryLoader.load.<locals>.<dictcomp>)page_contentmetadata)Zgoogle.cloudr   ImportErrorZClientr   r   r	   
ValueErrorr   resultr   r   Zschemajoinitemsr   append)r   r   exZ	bq_clientZ
error_descZquery_resultdocsrowr%   r&   docr   )r   r   r   load;   sB    zBigQueryLoader.load)NNNN)__name__
__module____qualname____doc__r   r1   r   r   r   r   r      s       r   N)
__future__r   typingr   r   r   Zlangchain_core._api.deprecationr   Zlangchain_core.documentsr   Z)langchain_community.document_loaders.baser   Z&langchain_community.utilities.vertexair	   Zgoogle.auth.credentialsr
   r   r   r   r   r   <module>   s   