Skip to content

Commit c0befe0

Browse files
committed
Allow jobs to be run in a different project
1 parent a2974c5 commit c0befe0

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

sqlalchemy_bigquery/base.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,8 @@ def __init__(
10801080
self,
10811081
arraysize=5000,
10821082
credentials_path=None,
1083+
project_id=None,
1084+
job_project_id=None,
10831085
location=None,
10841086
credentials_info=None,
10851087
credentials_base64=None,
@@ -1092,6 +1094,8 @@ def __init__(
10921094
self.credentials_path = credentials_path
10931095
self.credentials_info = credentials_info
10941096
self.credentials_base64 = credentials_base64
1097+
self.project_id = project_id
1098+
self.job_project_id = job_project_id
10951099
self.location = location
10961100
self.identifier_preparer = self.preparer(self)
10971101
self.dataset_id = None
@@ -1152,6 +1156,9 @@ def create_connect_args(self, url):
11521156
self._add_default_dataset_to_job_config(
11531157
default_query_job_config, project_id, dataset_id
11541158
)
1159+
self.project_id = project_id
1160+
if self.job_project_id is None:
1161+
self.job_project_id = project_id
11551162

11561163
if user_supplied_client:
11571164
# The user is expected to supply a client with
@@ -1162,7 +1169,7 @@ def create_connect_args(self, url):
11621169
credentials_path=self.credentials_path,
11631170
credentials_info=self.credentials_info,
11641171
credentials_base64=self.credentials_base64,
1165-
project_id=project_id,
1172+
project_id=self.job_project_id,
11661173
location=self.location,
11671174
default_query_job_config=default_query_job_config,
11681175
)
@@ -1177,7 +1184,7 @@ def _get_table_or_view_names(self, connection, item_types, schema=None):
11771184
)
11781185

11791186
client = connection.connection._client
1180-
datasets = client.list_datasets()
1187+
datasets = client.list_datasets(self.project_id)
11811188

11821189
result = []
11831190
for dataset in datasets:
@@ -1278,7 +1285,7 @@ def _get_table(self, connection, table_name, schema=None):
12781285

12791286
client = connection.connection._client
12801287

1281-
table_ref = self._table_reference(schema, table_name, client.project)
1288+
table_ref = self._table_reference(schema, table_name, self.project_id)
12821289
try:
12831290
table = client.get_table(table_ref)
12841291
except NotFound:
@@ -1332,7 +1339,7 @@ def get_schema_names(self, connection, **kw):
13321339
if isinstance(connection, Engine):
13331340
connection = connection.connect()
13341341

1335-
datasets = connection.connection._client.list_datasets()
1342+
datasets = connection.connection._client.list_datasets(self.project_id)
13361343
return [d.dataset_id for d in datasets]
13371344

13381345
def get_table_names(self, connection, schema=None, **kw):

0 commit comments

Comments
 (0)