Skip to content

Commit

Permalink
Bigquery sqlalchemy metastore (#1352)
Browse files Browse the repository at this point in the history
* [bigquery] bump bigquery engine dependencies

* [bigquery] Allow use of Application defaults credentials if no credentials specified

* [metastore] Split table name on '.' when using sqlalchemy-bigquery metasore
  • Loading branch information
seuf authored Nov 29, 2023
1 parent f8d8dd4 commit 91b2daf
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
8 changes: 4 additions & 4 deletions querybook/server/clients/google_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ def get_google_credentials(creds_info=None):
)

cred_to_use = creds_info or QuerybookSettings.GOOGLE_CREDS
assert cred_to_use is not None, "Invalid Google credentials"

credentials = service_account.Credentials.from_service_account_info(cred_to_use)

return credentials
if cred_to_use is not None:
return service_account.Credentials.from_service_account_info(cred_to_use)
else:
return None


GOOGLE_AUTH_CONFIG = "https://accounts.google.com/.well-known/openid-configuration"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ def get_all_schema_names(self) -> List[str]:
return self._inspect.get_schema_names()

def get_all_table_names_in_schema(self, schema_name: str) -> List[str]:
return self._inspect.get_table_names(schema=schema_name)
if self._engine.dialect.name == "bigquery":
return [table.split(".")[1] for table in self._inspect.get_table_names(schema=schema_name)]
else:
return self._inspect.get_table_names(schema=schema_name)

def get_table_and_columns(
self, schema_name, table_name
Expand Down
8 changes: 5 additions & 3 deletions querybook/server/lib/query_executor/clients/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ def __init__(self, google_credentials_json=None, *args, **kwargs):
if google_credentials_json is not None
else None
)
cred = get_google_credentials(parsed_google_json)

client = Client(project=cred.project_id, credentials=cred)
if parsed_google_json is not None:
cred = get_google_credentials(parsed_google_json)
client = Client(project=cred.project_id, credentials=cred)
else:
client = Client()

self._conn = dbapi.connect(client=client)
super(BigQueryClient, self).__init__()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@
(
"google_credentials_json",
FormField(
helper="The JSON string used to log in as service account. If not provided then **GOOGLE_CREDS** from settings will be used.",
helper="""
<p>The JSON string used to log in as service account.</p>
<p>If not provided then **GOOGLE_CREDS** from settings will be used</p>
<p>If both are empty, Application default credentials are used</p>
""",
),
)
)
9 changes: 4 additions & 5 deletions requirements/engine/bigquery.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
google-cloud-bigquery==1.28.0

# Downgrade Protobuf to fix error with bigquery:
# TypeError: Descriptors cannot not be created directly.
protobuf==3.20.1
google-cloud-bigquery==3.12.0
google-cloud-bigquery-storage==2.22.0
pyarrow==13.0.0
sqlalchemy-bigquery==1.8.0

0 comments on commit 91b2daf

Please sign in to comment.