Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 4b670fa

Browse files
committed
Fix for BigQuery
1 parent 4e4958c commit 4b670fa

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

data_diff/database.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@ def parse_table_name(t):
2323
return tuple(t.split("."))
2424

2525

26-
def import_helper(s: str):
26+
def import_helper(package: str = None, text=""):
2727
def dec(f):
2828
@wraps(f)
2929
def _inner():
3030
try:
3131
return f()
3232
except ModuleNotFoundError as e:
33-
raise ModuleNotFoundError(f"{e}\n\nYou can install it using 'pip install data-diff[{s}]'.")
33+
s = text
34+
if package:
35+
s += f"You can install it using 'pip install data-diff[{package}]'."
36+
raise ModuleNotFoundError(f"{e}\n\n{s}\n")
3437

3538
return _inner
3639

@@ -79,6 +82,13 @@ def import_presto():
7982
return prestodb
8083

8184

85+
@import_helper(text="Please install BigQuery and configure your google-cloud access.")
86+
def import_bigquery():
87+
from google.cloud import bigquery
88+
89+
return bigquery
90+
91+
8292
class ConnectError(Exception):
8393
pass
8494

@@ -797,7 +807,7 @@ class BigQuery(Database):
797807
ROUNDS_ON_PREC_LOSS = False # Technically BigQuery doesn't allow implicit rounding or truncation
798808

799809
def __init__(self, project, *, dataset, **kw):
800-
from google.cloud import bigquery
810+
bigquery = import_bigquery()
801811

802812
self._client = bigquery.Client(project, **kw)
803813
self.project = project

0 commit comments

Comments
 (0)