77from google .cloud import bigquery
88from google .cloud .bigquery import dbapi , QueryJobConfig
99from google .cloud .bigquery .schema import SchemaField
10- from google .cloud .bigquery .table import EncryptionConfiguration
11- from google .cloud .bigquery .dataset import DatasetReference
10+ from google .cloud .bigquery .table import EncryptionConfiguration , TableReference
1211from google .oauth2 import service_account
1312from google .api_core .exceptions import NotFound
1413from sqlalchemy .exc import NoSuchTableError
@@ -350,7 +349,8 @@ def _json_deserializer(self, row):
350349 """
351350 return row
352351
353- def _split_table_name (self , full_table_name ):
352+ @staticmethod
353+ def _split_table_name (full_table_name ):
354354 # Split full_table_name to get project, dataset and table name
355355 dataset = None
356356 table_name = None
@@ -370,19 +370,20 @@ def _get_table(self, connection, table_name, schema=None):
370370 if isinstance (connection , Engine ):
371371 connection = connection .connect ()
372372
373- project , dataset , table_name_prepared = self ._split_table_name (table_name )
374- if dataset is None :
375- if schema is not None :
376- dataset = schema
377- elif self .dataset_id :
378- dataset = self .dataset_id
373+ client = connection .connection ._client
374+
375+ project_id , dataset_id , table_id = self ._split_table_name (table_name )
376+ project_id = project_id or client .project
377+ dataset_id = dataset_id or schema or self .dataset_id
379378
380- table = connection .connection ._client .dataset (dataset , project = project ).table (table_name_prepared )
379+ table_ref = TableReference .from_string ("{}.{}.{}" .format (
380+ project_id , dataset_id , table_id
381+ ))
381382 try :
382- t = connection . connection . _client . get_table (table )
383- except NotFound as e :
383+ table = client . get_table (table_ref )
384+ except NotFound :
384385 raise NoSuchTableError (table_name )
385- return t
386+ return table
386387
387388 def has_table (self , connection , table_name , schema = None ):
388389 try :
0 commit comments