Skip to content

Commit 8abc913

Browse files
jbatswast
authored andcommitted
bigquery: rename name field of Table to table_id (#3959)
* bigquery: rename name field of Table to table_id Also rename table_id to full_table_id. * fix lint errors * fix doc
1 parent 24c9313 commit 8abc913

File tree

5 files changed

+70
-61
lines changed

5 files changed

+70
-61
lines changed

bigquery/google/cloud/bigquery/job.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ def _build_resource(self):
774774
'destinationTable': {
775775
'projectId': self.destination.project,
776776
'datasetId': self.destination.dataset_id,
777-
'tableId': self.destination.name,
777+
'tableId': self.destination.table_id,
778778
},
779779
},
780780
},
@@ -901,7 +901,7 @@ def _build_resource(self):
901901
source_refs = [{
902902
'projectId': table.project,
903903
'datasetId': table.dataset_id,
904-
'tableId': table.name,
904+
'tableId': table.table_id,
905905
} for table in self.sources]
906906

907907
resource = {
@@ -915,7 +915,7 @@ def _build_resource(self):
915915
'destinationTable': {
916916
'projectId': self.destination.project,
917917
'datasetId': self.destination.dataset_id,
918-
'tableId': self.destination.name,
918+
'tableId': self.destination.table_id,
919919
},
920920
},
921921
},
@@ -1059,7 +1059,7 @@ def _build_resource(self):
10591059
source_ref = {
10601060
'projectId': self.source.project,
10611061
'datasetId': self.source.dataset_id,
1062-
'tableId': self.source.name,
1062+
'tableId': self.source.table_id,
10631063
}
10641064

10651065
resource = {
@@ -1248,7 +1248,7 @@ def _destination_table_resource(self):
12481248
return {
12491249
'projectId': self.destination.project,
12501250
'datasetId': self.destination.dataset_id,
1251-
'tableId': self.destination.name,
1251+
'tableId': self.destination.table_id,
12521252
}
12531253

12541254
def _populate_config_resource_booleans(self, configuration):

bigquery/google/cloud/bigquery/table.py

+27-18
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ class Table(object):
9090
See
9191
https://cloud.google.com/bigquery/docs/reference/rest/v2/tables
9292
93-
:type name: str
94-
:param name: the name of the table
93+
:type table_id: str
94+
:param table_id: the ID of the table
9595
9696
:type dataset: :class:`google.cloud.bigquery.dataset.Dataset`
9797
:param dataset: The dataset which contains the table.
@@ -102,8 +102,8 @@ class Table(object):
102102

103103
_schema = None
104104

105-
def __init__(self, name, dataset, schema=()):
106-
self.name = name
105+
def __init__(self, table_id, dataset, schema=()):
106+
self._table_id = table_id
107107
self._dataset = dataset
108108
self._properties = {}
109109
# Let the @property do validation.
@@ -127,14 +127,23 @@ def dataset_id(self):
127127
"""
128128
return self._dataset.dataset_id
129129

130+
@property
131+
def table_id(self):
132+
"""ID of the table.
133+
134+
:rtype: str
135+
:returns: the table ID.
136+
"""
137+
return self._table_id
138+
130139
@property
131140
def path(self):
132141
"""URL path for the table's APIs.
133142
134143
:rtype: str
135-
:returns: the path based on project and dataste name.
144+
:returns: the path based on project, dataset and table IDs.
136145
"""
137-
return '%s/tables/%s' % (self._dataset.path, self.name)
146+
return '%s/tables/%s' % (self._dataset.path, self.table_id)
138147

139148
@property
140149
def schema(self):
@@ -224,11 +233,11 @@ def self_link(self):
224233
return self._properties.get('selfLink')
225234

226235
@property
227-
def table_id(self):
228-
"""ID for the table resource.
236+
def full_table_id(self):
237+
"""ID for the table, in the form ``project_id:dataset_id:table_id``.
229238
230239
:rtype: str, or ``NoneType``
231-
:returns: the ID (None until set from the server).
240+
:returns: the full ID (None until set from the server).
232241
"""
233242
return self._properties.get('id')
234243

@@ -463,7 +472,7 @@ def list_partitions(self, client=None):
463472
"""
464473
query = self._require_client(client).run_sync_query(
465474
'SELECT partition_id from [%s.%s$__PARTITIONS_SUMMARY__]' %
466-
(self.dataset_id, self.name))
475+
(self.dataset_id, self.table_id))
467476
query.run()
468477
return [row[0] for row in query.rows]
469478

@@ -484,8 +493,8 @@ def from_api_repr(cls, resource, dataset):
484493
'tableId' not in resource['tableReference']):
485494
raise KeyError('Resource lacks required identity information:'
486495
'["tableReference"]["tableId"]')
487-
table_name = resource['tableReference']['tableId']
488-
table = cls(table_name, dataset=dataset)
496+
table_id = resource['tableReference']['tableId']
497+
table = cls(table_id, dataset=dataset)
489498
table._set_properties(resource)
490499
return table
491500

@@ -528,7 +537,7 @@ def _build_resource(self):
528537
'tableReference': {
529538
'projectId': self._dataset.project,
530539
'datasetId': self._dataset.dataset_id,
531-
'tableId': self.name},
540+
'tableId': self.table_id},
532541
}
533542
if self.description is not None:
534543
resource['description'] = self.description
@@ -1181,7 +1190,7 @@ def upload_from_file(self,
11811190
_maybe_rewind(file_obj, rewind=rewind)
11821191
_check_mode(file_obj)
11831192
metadata = _get_upload_metadata(
1184-
source_format, self._schema, self._dataset, self.name)
1193+
source_format, self._schema, self._dataset, self.table_id)
11851194
_configure_job_metadata(metadata, allow_jagged_rows,
11861195
allow_quoted_newlines, create_disposition,
11871196
encoding, field_delimiter,
@@ -1346,7 +1355,7 @@ def _get_upload_headers(user_agent):
13461355
}
13471356

13481357

1349-
def _get_upload_metadata(source_format, schema, dataset, name):
1358+
def _get_upload_metadata(source_format, schema, dataset, table_id):
13501359
"""Get base metadata for creating a table.
13511360
13521361
:type source_format: str
@@ -1359,8 +1368,8 @@ def _get_upload_metadata(source_format, schema, dataset, name):
13591368
:type dataset: :class:`~google.cloud.bigquery.dataset.Dataset`
13601369
:param dataset: A dataset which contains a table.
13611370
1362-
:type name: str
1363-
:param name: The name of the table.
1371+
:type table_id: str
1372+
:param table_id: The table_id of the table.
13641373
13651374
:rtype: dict
13661375
:returns: The metadata dictionary.
@@ -1370,7 +1379,7 @@ def _get_upload_metadata(source_format, schema, dataset, name):
13701379
'destinationTable': {
13711380
'projectId': dataset.project,
13721381
'datasetId': dataset.dataset_id,
1373-
'tableId': name,
1382+
'tableId': table_id,
13741383
},
13751384
}
13761385
if schema:

bigquery/tests/unit/test_dataset.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ def test_list_tables_defaults(self):
763763
self.assertEqual(len(tables), len(DATA['tables']))
764764
for found, expected in zip(tables, DATA['tables']):
765765
self.assertIsInstance(found, Table)
766-
self.assertEqual(found.table_id, expected['id'])
766+
self.assertEqual(found.full_table_id, expected['id'])
767767
self.assertEqual(found.table_type, expected['type'])
768768
self.assertEqual(token, TOKEN)
769769

@@ -810,7 +810,7 @@ def test_list_tables_explicit(self):
810810
self.assertEqual(len(tables), len(DATA['tables']))
811811
for found, expected in zip(tables, DATA['tables']):
812812
self.assertIsInstance(found, Table)
813-
self.assertEqual(found.table_id, expected['id'])
813+
self.assertEqual(found.full_table_id, expected['id'])
814814
self.assertEqual(found.table_type, expected['type'])
815815
self.assertIsNone(token)
816816

@@ -827,9 +827,9 @@ def test_table_wo_schema(self):
827827
conn = _Connection({})
828828
client = _Client(project=self.PROJECT, connection=conn)
829829
dataset = self._make_one(self.DS_ID, client=client)
830-
table = dataset.table('table_name')
830+
table = dataset.table('table_id')
831831
self.assertIsInstance(table, Table)
832-
self.assertEqual(table.name, 'table_name')
832+
self.assertEqual(table.table_id, 'table_id')
833833
self.assertIs(table._dataset, dataset)
834834
self.assertEqual(table.schema, [])
835835

@@ -842,9 +842,9 @@ def test_table_w_schema(self):
842842
dataset = self._make_one(self.DS_ID, client=client)
843843
full_name = SchemaField('full_name', 'STRING', mode='REQUIRED')
844844
age = SchemaField('age', 'INTEGER', mode='REQUIRED')
845-
table = dataset.table('table_name', schema=[full_name, age])
845+
table = dataset.table('table_id', schema=[full_name, age])
846846
self.assertIsInstance(table, Table)
847-
self.assertEqual(table.name, 'table_name')
847+
self.assertEqual(table.table_id, 'table_id')
848848
self.assertIs(table._dataset, dataset)
849849
self.assertEqual(table.schema, [full_name, age])
850850

bigquery/tests/unit/test_job.py

+20-20
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class _Base(object):
8383
PROJECT = 'project'
8484
SOURCE1 = 'http://example.com/source1.csv'
8585
DS_ID = 'datset_id'
86-
TABLE_NAME = 'table_name'
86+
TABLE_ID = 'table_id'
8787
JOB_NAME = 'job_name'
8888

8989
def _make_one(self, *args, **kw):
@@ -207,7 +207,7 @@ def _makeResource(self, started=False, ended=False):
207207
config['destinationTable'] = {
208208
'projectId': self.PROJECT,
209209
'datasetId': self.DS_ID,
210-
'tableId': self.TABLE_NAME,
210+
'tableId': self.TABLE_ID,
211211
}
212212

213213
if ended:
@@ -276,7 +276,7 @@ def _verifyResourceProperties(self, job, resource):
276276
table_ref = config['destinationTable']
277277
self.assertEqual(job.destination.project, table_ref['projectId'])
278278
self.assertEqual(job.destination.dataset_id, table_ref['datasetId'])
279-
self.assertEqual(job.destination.name, table_ref['tableId'])
279+
self.assertEqual(job.destination.table_id, table_ref['tableId'])
280280

281281
if 'fieldDelimiter' in config:
282282
self.assertEqual(job.field_delimiter,
@@ -544,7 +544,7 @@ def test_from_api_repr_bare(self):
544544
'destinationTable': {
545545
'projectId': self.PROJECT,
546546
'datasetId': self.DS_ID,
547-
'tableId': self.TABLE_NAME,
547+
'tableId': self.TABLE_ID,
548548
},
549549
}
550550
},
@@ -604,7 +604,7 @@ def test_begin_w_bound_client(self):
604604
'destinationTable': {
605605
'projectId': self.PROJECT,
606606
'datasetId': self.DS_ID,
607-
'tableId': self.TABLE_NAME,
607+
'tableId': self.TABLE_ID,
608608
},
609609
},
610610
},
@@ -639,7 +639,7 @@ def test_begin_w_autodetect(self):
639639
'destinationTable': {
640640
'projectId': self.PROJECT,
641641
'datasetId': self.DS_ID,
642-
'tableId': self.TABLE_NAME,
642+
'tableId': self.TABLE_ID,
643643
},
644644
'autodetect': True
645645
},
@@ -663,7 +663,7 @@ def test_begin_w_alternate_client(self):
663663
'destinationTable': {
664664
'projectId': self.PROJECT,
665665
'datasetId': self.DS_ID,
666-
'tableId': self.TABLE_NAME,
666+
'tableId': self.TABLE_ID,
667667
},
668668
'allowJaggedRows': True,
669669
'allowQuotedNewlines': True,
@@ -867,7 +867,7 @@ def _verifyResourceProperties(self, job, resource):
867867
table_ref = config['destinationTable']
868868
self.assertEqual(job.destination.project, table_ref['projectId'])
869869
self.assertEqual(job.destination.dataset_id, table_ref['datasetId'])
870-
self.assertEqual(job.destination.name, table_ref['tableId'])
870+
self.assertEqual(job.destination.table_id, table_ref['tableId'])
871871

872872
sources = config.get('sourceTables')
873873
if sources is None:
@@ -876,7 +876,7 @@ def _verifyResourceProperties(self, job, resource):
876876
for table_ref, table in zip(sources, job.sources):
877877
self.assertEqual(table.project, table_ref['projectId'])
878878
self.assertEqual(table.dataset_id, table_ref['datasetId'])
879-
self.assertEqual(table.name, table_ref['tableId'])
879+
self.assertEqual(table.table_id, table_ref['tableId'])
880880

881881
if 'createDisposition' in config:
882882
self.assertEqual(job.create_disposition,
@@ -1219,7 +1219,7 @@ def _verifyResourceProperties(self, job, resource):
12191219
table_ref = config['sourceTable']
12201220
self.assertEqual(job.source.project, table_ref['projectId'])
12211221
self.assertEqual(job.source.dataset_id, table_ref['datasetId'])
1222-
self.assertEqual(job.source.name, table_ref['tableId'])
1222+
self.assertEqual(job.source.table_id, table_ref['tableId'])
12231223

12241224
if 'compression' in config:
12251225
self.assertEqual(job.compression,
@@ -1614,7 +1614,7 @@ def _verifyResourceProperties(self, job, resource):
16141614
tb_ref = {
16151615
'projectId': table.project,
16161616
'datasetId': table.dataset_id,
1617-
'tableId': table.name
1617+
'tableId': table.table_id
16181618
}
16191619
self.assertEqual(tb_ref, query_config['destinationTable'])
16201620
else:
@@ -1934,21 +1934,21 @@ def test_referenced_tables(self):
19341934
local1, local2, remote = job.referenced_tables
19351935

19361936
self.assertIsInstance(local1, Table)
1937-
self.assertEqual(local1.name, 'local1')
1937+
self.assertEqual(local1.table_id, 'local1')
19381938
self.assertIsInstance(local1._dataset, Dataset)
19391939
self.assertEqual(local1.dataset_id, 'dataset')
19401940
self.assertEqual(local1.project, self.PROJECT)
19411941
self.assertIs(local1._dataset._client, client)
19421942

19431943
self.assertIsInstance(local2, Table)
1944-
self.assertEqual(local2.name, 'local2')
1944+
self.assertEqual(local2.table_id, 'local2')
19451945
self.assertIsInstance(local2._dataset, Dataset)
19461946
self.assertEqual(local2.dataset_id, 'dataset')
19471947
self.assertEqual(local2.project, self.PROJECT)
19481948
self.assertIs(local2._dataset._client, client)
19491949

19501950
self.assertIsInstance(remote, Table)
1951-
self.assertEqual(remote.name, 'other-table')
1951+
self.assertEqual(remote.table_id, 'other-table')
19521952
self.assertIsInstance(remote._dataset, Dataset)
19531953
self.assertEqual(remote.dataset_id, 'other-dataset')
19541954
self.assertEqual(remote.project, 'other-project-123')
@@ -2706,14 +2706,14 @@ def _get_query_results(self, job_id):
27062706

27072707
class _Table(object):
27082708

2709-
def __init__(self, name=None):
2710-
self._name = name
2709+
def __init__(self, table_id=None):
2710+
self._table_id = table_id
27112711

27122712
@property
2713-
def name(self):
2714-
if self._name is not None:
2715-
return self._name
2716-
return TestLoadJob.TABLE_NAME
2713+
def table_id(self):
2714+
if self._table_id is not None:
2715+
return self._table_id
2716+
return TestLoadJob.TABLE_ID
27172717

27182718
@property
27192719
def project(self):

0 commit comments

Comments
 (0)