@@ -633,70 +633,6 @@ def load_data(
633
633
except self .http_error as ex :
634
634
self .process_http_error (ex )
635
635
636
- def schema (self , dataset_id , table_id ):
637
- """Retrieve the schema of the table
638
-
639
- Obtain from BigQuery the field names and field types
640
- for the table defined by the parameters
641
-
642
- Parameters
643
- ----------
644
- dataset_id : str
645
- Name of the BigQuery dataset for the table
646
- table_id : str
647
- Name of the BigQuery table
648
-
649
- Returns
650
- -------
651
- list of dicts
652
- Fields representing the schema
653
- """
654
- table_ref = self .client .dataset (dataset_id ).table (table_id )
655
-
656
- try :
657
- table = self .client .get_table (table_ref )
658
- remote_schema = table .schema
659
-
660
- remote_fields = [
661
- field_remote .to_api_repr () for field_remote in remote_schema
662
- ]
663
- for field in remote_fields :
664
- field ["type" ] = field ["type" ].upper ()
665
- field ["mode" ] = field ["mode" ].upper ()
666
-
667
- return remote_fields
668
- except self .http_error as ex :
669
- self .process_http_error (ex )
670
-
671
- def verify_schema (self , dataset_id , table_id , schema ):
672
- """Indicate whether schemas match exactly
673
-
674
- Compare the BigQuery table identified in the parameters with
675
- the schema passed in and indicate whether all fields in the former
676
- are present in the latter. Order is not considered.
677
-
678
- Parameters
679
- ----------
680
- dataset_id :str
681
- Name of the BigQuery dataset for the table
682
- table_id : str
683
- Name of the BigQuery table
684
- schema : list(dict)
685
- Schema for comparison. Each item should have
686
- a 'name' and a 'type'
687
-
688
- Returns
689
- -------
690
- bool
691
- Whether the schemas match
692
- """
693
-
694
- fields_remote = pandas_gbq .schema ._clean_schema_fields (
695
- self .schema (dataset_id , table_id )
696
- )
697
- fields_local = pandas_gbq .schema ._clean_schema_fields (schema ["fields" ])
698
- return fields_remote == fields_local
699
-
700
636
def delete_and_recreate_table (self , dataset_id , table_id , table_schema ):
701
637
table = _Table (
702
638
self .project_id , dataset_id , credentials = self .credentials
@@ -1271,6 +1207,15 @@ def __init__(
1271
1207
private_key = private_key ,
1272
1208
)
1273
1209
1210
+ def _table_ref (self , table_id ):
1211
+ """Return a BigQuery client library table reference"""
1212
+ from google .cloud .bigquery import DatasetReference
1213
+ from google .cloud .bigquery import TableReference
1214
+
1215
+ return TableReference (
1216
+ DatasetReference (self .project_id , self .dataset_id ), table_id
1217
+ )
1218
+
1274
1219
def exists (self , table_id ):
1275
1220
"""Check if a table exists in Google BigQuery
1276
1221
@@ -1285,12 +1230,8 @@ def exists(self, table_id):
1285
1230
true if table exists, otherwise false
1286
1231
"""
1287
1232
from google .api_core .exceptions import NotFound
1288
- from google .cloud .bigquery import DatasetReference
1289
- from google .cloud .bigquery import TableReference
1290
1233
1291
- table_ref = TableReference (
1292
- DatasetReference (self .project_id , self .dataset_id ), table_id
1293
- )
1234
+ table_ref = self ._table_ref (table_id )
1294
1235
try :
1295
1236
self .client .get_table (table_ref )
1296
1237
return True
@@ -1358,7 +1299,7 @@ def delete(self, table_id):
1358
1299
if not self .exists (table_id ):
1359
1300
raise NotFoundException ("Table does not exist" )
1360
1301
1361
- table_ref = self .client . dataset ( self . dataset_id ). table (table_id )
1302
+ table_ref = self ._table_ref (table_id )
1362
1303
try :
1363
1304
self .client .delete_table (table_ref )
1364
1305
except NotFound :
@@ -1385,6 +1326,12 @@ def __init__(
1385
1326
private_key = private_key ,
1386
1327
)
1387
1328
1329
+ def _dataset_ref (self , dataset_id ):
1330
+ """Return a BigQuery client library dataset reference"""
1331
+ from google .cloud .bigquery import DatasetReference
1332
+
1333
+ return DatasetReference (self .project_id , dataset_id )
1334
+
1388
1335
def exists (self , dataset_id ):
1389
1336
"""Check if a dataset exists in Google BigQuery
1390
1337
@@ -1401,7 +1348,7 @@ def exists(self, dataset_id):
1401
1348
from google .api_core .exceptions import NotFound
1402
1349
1403
1350
try :
1404
- self .client .get_dataset (self .client . dataset (dataset_id ))
1351
+ self .client .get_dataset (self ._dataset_ref (dataset_id ))
1405
1352
return True
1406
1353
except NotFound :
1407
1354
return False
@@ -1423,7 +1370,7 @@ def create(self, dataset_id):
1423
1370
"Dataset {0} already " "exists" .format (dataset_id )
1424
1371
)
1425
1372
1426
- dataset = Dataset (self .client . dataset (dataset_id ))
1373
+ dataset = Dataset (self ._dataset_ref (dataset_id ))
1427
1374
1428
1375
if self .location is not None :
1429
1376
dataset .location = self .location
0 commit comments