Skip to content

Commit 75ea788

Browse files
jbatswast
authored andcommitted
bigquery: rename name field of Dataset to dataset_id (#3955)
* bigquery: rename name field of Dataset to dataset_id Rename the former dataset_id property to full_dataset_id. Also rename Table.dataset_name to Table.dataset_id. Perform other renamings (of various variables and constants). These names match usage better. The API's Dataset.id field is "project:dataset_id", which is confusing and basically useless, so it's a mistake to call that dataset_id. * fix long line * fix long line
1 parent cb7ee59 commit 75ea788

File tree

9 files changed

+236
-234
lines changed

9 files changed

+236
-234
lines changed

bigquery/google/cloud/bigquery/dataset.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ class Dataset(object):
142142
See
143143
https://cloud.google.com/bigquery/docs/reference/rest/v2/datasets
144144
145-
:type name: str
146-
:param name: the name of the dataset
145+
:type dataset_id: str
146+
:param dataset_id: the ID of the dataset
147147
148148
:type client: :class:`google.cloud.bigquery.client.Client`
149149
:param client: A client which holds credentials and project configuration
@@ -159,8 +159,8 @@ class Dataset(object):
159159

160160
_access_entries = None
161161

162-
def __init__(self, name, client, access_entries=(), project=None):
163-
self.name = name
162+
def __init__(self, dataset_id, client, access_entries=(), project=None):
163+
self.dataset_id = dataset_id
164164
self._client = client
165165
self._properties = {}
166166
# Let the @property do validation.
@@ -181,9 +181,9 @@ def path(self):
181181
"""URL path for the dataset's APIs.
182182
183183
:rtype: str
184-
:returns: the path based on project and dataste name.
184+
:returns: the path based on project and dataset ID.
185185
"""
186-
return '/projects/%s/datasets/%s' % (self.project, self.name)
186+
return '/projects/%s/datasets/%s' % (self.project, self.dataset_id)
187187

188188
@property
189189
def access_entries(self):
@@ -221,8 +221,8 @@ def created(self):
221221
return _datetime_from_microseconds(1000.0 * creation_time)
222222

223223
@property
224-
def dataset_id(self):
225-
"""ID for the dataset resource.
224+
def full_dataset_id(self):
225+
"""ID for the dataset resource, in the form "project_id:dataset_id".
226226
227227
:rtype: str, or ``NoneType``
228228
:returns: the ID (None until set from the server).
@@ -365,8 +365,8 @@ def from_api_repr(cls, resource, client):
365365
'datasetId' not in resource['datasetReference']):
366366
raise KeyError('Resource lacks required identity information:'
367367
'["datasetReference"]["datasetId"]')
368-
name = resource['datasetReference']['datasetId']
369-
dataset = cls(name, client=client)
368+
dataset_id = resource['datasetReference']['datasetId']
369+
dataset = cls(dataset_id, client=client)
370370
dataset._set_properties(resource)
371371
return dataset
372372

@@ -444,7 +444,7 @@ def _build_resource(self):
444444
"""Generate a resource for ``create`` or ``update``."""
445445
resource = {
446446
'datasetReference': {
447-
'projectId': self.project, 'datasetId': self.name},
447+
'projectId': self.project, 'datasetId': self.dataset_id},
448448
}
449449
if self.default_table_expiration_ms is not None:
450450
value = self.default_table_expiration_ms
@@ -610,7 +610,8 @@ def list_tables(self, max_results=None, page_token=None):
610610
:returns: Iterator of :class:`~google.cloud.bigquery.table.Table`
611611
contained within the current dataset.
612612
"""
613-
path = '/projects/%s/datasets/%s/tables' % (self.project, self.name)
613+
path = '/projects/%s/datasets/%s/tables' % (
614+
self.project, self.dataset_id)
614615
result = page_iterator.HTTPIterator(
615616
client=self._client,
616617
api_request=self._client._connection.api_request,

bigquery/google/cloud/bigquery/job.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ def _build_resource(self):
773773
'sourceUris': self.source_uris,
774774
'destinationTable': {
775775
'projectId': self.destination.project,
776-
'datasetId': self.destination.dataset_name,
776+
'datasetId': self.destination.dataset_id,
777777
'tableId': self.destination.name,
778778
},
779779
},
@@ -900,7 +900,7 @@ def _build_resource(self):
900900

901901
source_refs = [{
902902
'projectId': table.project,
903-
'datasetId': table.dataset_name,
903+
'datasetId': table.dataset_id,
904904
'tableId': table.name,
905905
} for table in self.sources]
906906

@@ -914,7 +914,7 @@ def _build_resource(self):
914914
'sourceTables': source_refs,
915915
'destinationTable': {
916916
'projectId': self.destination.project,
917-
'datasetId': self.destination.dataset_name,
917+
'datasetId': self.destination.dataset_id,
918918
'tableId': self.destination.name,
919919
},
920920
},
@@ -1058,7 +1058,7 @@ def _build_resource(self):
10581058

10591059
source_ref = {
10601060
'projectId': self.source.project,
1061-
'datasetId': self.source.dataset_name,
1061+
'datasetId': self.source.dataset_id,
10621062
'tableId': self.source.name,
10631063
}
10641064

@@ -1247,7 +1247,7 @@ def _destination_table_resource(self):
12471247
if self.destination is not None:
12481248
return {
12491249
'projectId': self.destination.project,
1250-
'datasetId': self.destination.dataset_name,
1250+
'datasetId': self.destination.dataset_id,
12511251
'tableId': self.destination.name,
12521252
}
12531253

@@ -1271,7 +1271,7 @@ def _populate_config_resource(self, configuration):
12711271
if self.default_dataset is not None:
12721272
configuration['defaultDataset'] = {
12731273
'projectId': self.default_dataset.project,
1274-
'datasetId': self.default_dataset.name,
1274+
'datasetId': self.default_dataset.dataset_id,
12751275
}
12761276
if self.destination is not None:
12771277
table_res = self._destination_table_resource()

bigquery/google/cloud/bigquery/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def _build_resource(self):
329329
if self.default_dataset is not None:
330330
resource['defaultDataset'] = {
331331
'projectId': self.project,
332-
'datasetId': self.default_dataset.name,
332+
'datasetId': self.default_dataset.dataset_id,
333333
}
334334

335335
if self.max_results is not None:

bigquery/google/cloud/bigquery/table.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ def project(self):
119119
return self._dataset.project
120120

121121
@property
122-
def dataset_name(self):
123-
"""Name of dataset containing the table.
122+
def dataset_id(self):
123+
"""ID of dataset containing the table.
124124
125125
:rtype: str
126126
:returns: the ID (derived from the dataset).
127127
"""
128-
return self._dataset.name
128+
return self._dataset.dataset_id
129129

130130
@property
131131
def path(self):
@@ -463,7 +463,7 @@ def list_partitions(self, client=None):
463463
"""
464464
query = self._require_client(client).run_sync_query(
465465
'SELECT partition_id from [%s.%s$__PARTITIONS_SUMMARY__]' %
466-
(self.dataset_name, self.name))
466+
(self.dataset_id, self.name))
467467
query.run()
468468
return [row[0] for row in query.rows]
469469

@@ -527,7 +527,7 @@ def _build_resource(self):
527527
resource = {
528528
'tableReference': {
529529
'projectId': self._dataset.project,
530-
'datasetId': self._dataset.name,
530+
'datasetId': self._dataset.dataset_id,
531531
'tableId': self.name},
532532
}
533533
if self.description is not None:
@@ -572,7 +572,7 @@ def create(self, client=None):
572572
"""
573573
client = self._require_client(client)
574574
path = '/projects/%s/datasets/%s/tables' % (
575-
self._dataset.project, self._dataset.name)
575+
self._dataset.project, self._dataset.dataset_id)
576576
api_response = client._connection.api_request(
577577
method='POST', path=path, data=self._build_resource())
578578
self._set_properties(api_response)
@@ -1369,7 +1369,7 @@ def _get_upload_metadata(source_format, schema, dataset, name):
13691369
'sourceFormat': source_format,
13701370
'destinationTable': {
13711371
'projectId': dataset.project,
1372-
'datasetId': dataset.name,
1372+
'datasetId': dataset.dataset_id,
13731373
'tableId': name,
13741374
},
13751375
}

0 commit comments

Comments
 (0)