Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to specify credentials wihen using Google BigQuery as a data loader #5466

Merged
merged 6 commits into from
May 30, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions langchain/document_loaders/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,33 @@ class BigQueryLoader(BaseLoader):
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`.

"""

def __init__(
self,
query: str,
project: Optional[str] = None,
page_content_columns: Optional[List[str]] = None,
metadata_columns: Optional[List[str]] = None,
self,
query: str,
project: Optional[str] = None,
page_content_columns: Optional[List[str]] = None,
metadata_columns: Optional[List[str]] = None,
credentials=None,
):
"""
:param query: The query to run in BigQuery.
:param project: Optional. The project to run the query in.
:param page_content_columns: Optional. The columns to write into the `page_content` of the document.
:param metadata_columns: Optional. The columns to write into the `metadata` of the document.
:param credentials : google.auth.credentials.Credentials, optional
Credentials for accessing Google APIs. Use this parameter to override
default credentials, such as to use Compute Engine
:class:`google.auth.compute_engine.Credentials` or Service Account
:class:`google.oauth2.service_account.Credentials` directly.
"""
self.query = query
self.project = project
self.page_content_columns = page_content_columns
self.metadata_columns = metadata_columns
self.credentials = credentials

def load(self) -> List[Document]:
try:
Expand All @@ -34,7 +48,7 @@ def load(self) -> List[Document]:
"Please install it with `pip install google-cloud-bigquery`."
) from ex

bq_client = bigquery.Client(self.project)
bq_client = bigquery.Client(credentials=self.credentials, project=self.project)
query_result = bq_client.query(self.query).result()
docs: List[Document] = []

Expand Down