Skip to content

Commit cad0adf

Browse files
committed
BQ: rename XJob.name to XJob.job_id. (#3962)
* BQ: rename XJob.name to XJob.job_id. * BQ: Remove references to table.name
1 parent fd917e0 commit cad0adf

5 files changed

Lines changed: 53 additions & 53 deletions

File tree

bigquery/google/cloud/bigquery/job.py

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,15 @@ class WriteDisposition(_EnumProperty):
164164
class _AsyncJob(google.api.core.future.polling.PollingFuture):
165165
"""Base class for asynchronous jobs.
166166
167-
:type name: str
168-
:param name: the name of the job
167+
:type job_id: str
168+
:param job_id: the job's ID in the project associated with the client.
169169
170170
:type client: :class:`google.cloud.bigquery.client.Client`
171-
:param client: A client which holds credentials and project configuration
172-
for the dataset (which requires a project).
171+
:param client: A client which holds credentials and project configuration.
173172
"""
174-
def __init__(self, name, client):
173+
def __init__(self, job_id, client):
175174
super(_AsyncJob, self).__init__()
176-
self.name = name
175+
self.job_id = job_id
177176
self._client = client
178177
self._properties = {}
179178
self._result_set = False
@@ -217,9 +216,9 @@ def path(self):
217216
"""URL path for the job's APIs.
218217
219218
:rtype: str
220-
:returns: the path based on project and job name.
219+
:returns: the path based on project and job ID.
221220
"""
222-
return '/projects/%s/jobs/%s' % (self.project, self.name)
221+
return '/projects/%s/jobs/%s' % (self.project, self.job_id)
223222

224223
@property
225224
def etag(self):
@@ -367,21 +366,21 @@ def _get_resource_config(cls, resource):
367366
368367
:rtype: dict
369368
:returns: tuple (string, dict), where the first element is the
370-
job name and the second contains job-specific configuration.
369+
job ID and the second contains job-specific configuration.
371370
:raises: :class:`KeyError` if the resource has no identifier, or
372371
is missing the appropriate configuration.
373372
"""
374373
if ('jobReference' not in resource or
375374
'jobId' not in resource['jobReference']):
376375
raise KeyError('Resource lacks required identity information: '
377376
'["jobReference"]["jobId"]')
378-
name = resource['jobReference']['jobId']
377+
job_id = resource['jobReference']['jobId']
379378
if ('configuration' not in resource or
380379
cls._JOB_TYPE not in resource['configuration']):
381380
raise KeyError('Resource lacks required configuration: '
382381
'["configuration"]["%s"]' % cls._JOB_TYPE)
383382
config = resource['configuration'][cls._JOB_TYPE]
384-
return name, config
383+
return job_id, config
385384

386385
def begin(self, client=None):
387386
"""API call: begin the job via a POST request
@@ -560,8 +559,9 @@ class _LoadConfiguration(object):
560559
class LoadJob(_AsyncJob):
561560
"""Asynchronous job for loading data into a table from remote URI.
562561
563-
:type name: str
564-
:param name: the name of the job
562+
:type job_id: str
563+
:param job_id:
564+
The job's ID, belonging to the project associated with the client.
565565
566566
:type destination: :class:`google.cloud.bigquery.table.Table`
567567
:param destination: Table into which data is to be loaded.
@@ -766,7 +766,7 @@ def _build_resource(self):
766766
resource = {
767767
'jobReference': {
768768
'projectId': self.project,
769-
'jobId': self.name,
769+
'jobId': self.job_id,
770770
},
771771
'configuration': {
772772
self._JOB_TYPE: {
@@ -834,12 +834,12 @@ def from_api_repr(cls, resource, client):
834834
:rtype: :class:`google.cloud.bigquery.job.LoadJob`
835835
:returns: Job parsed from ``resource``.
836836
"""
837-
name, config = cls._get_resource_config(resource)
837+
job_id, config = cls._get_resource_config(resource)
838838
dest_config = config['destinationTable']
839839
dataset = Dataset(dest_config['datasetId'], client)
840840
destination = Table(dest_config['tableId'], dataset)
841841
source_urls = config.get('sourceUris', ())
842-
job = cls(name, destination, source_urls, client=client)
842+
job = cls(job_id, destination, source_urls, client=client)
843843
job._set_properties(resource)
844844
return job
845845

@@ -856,8 +856,8 @@ class _CopyConfiguration(object):
856856
class CopyJob(_AsyncJob):
857857
"""Asynchronous job: copy data into a table from other tables.
858858
859-
:type name: str
860-
:param name: the name of the job
859+
:type job_id: str
860+
:param job_id: the job's ID, within the project belonging to ``client``.
861861
862862
:type destination: :class:`google.cloud.bigquery.table.Table`
863863
:param destination: Table into which data is to be loaded.
@@ -872,8 +872,8 @@ class CopyJob(_AsyncJob):
872872

873873
_JOB_TYPE = 'copy'
874874

875-
def __init__(self, name, destination, sources, client):
876-
super(CopyJob, self).__init__(name, client)
875+
def __init__(self, job_id, destination, sources, client):
876+
super(CopyJob, self).__init__(job_id, client)
877877
self.destination = destination
878878
self.sources = sources
879879
self._configuration = _CopyConfiguration()
@@ -907,7 +907,7 @@ def _build_resource(self):
907907
resource = {
908908
'jobReference': {
909909
'projectId': self.project,
910-
'jobId': self.name,
910+
'jobId': self.job_id,
911911
},
912912
'configuration': {
913913
self._JOB_TYPE: {
@@ -949,7 +949,7 @@ def from_api_repr(cls, resource, client):
949949
:rtype: :class:`google.cloud.bigquery.job.CopyJob`
950950
:returns: Job parsed from ``resource``.
951951
"""
952-
name, config = cls._get_resource_config(resource)
952+
job_id, config = cls._get_resource_config(resource)
953953
dest_config = config['destinationTable']
954954
dataset = Dataset(dest_config['datasetId'], client)
955955
destination = Table(dest_config['tableId'], dataset)
@@ -964,7 +964,7 @@ def from_api_repr(cls, resource, client):
964964
for source_config in source_configs:
965965
dataset = Dataset(source_config['datasetId'], client)
966966
sources.append(Table(source_config['tableId'], dataset))
967-
job = cls(name, destination, sources, client=client)
967+
job = cls(job_id, destination, sources, client=client)
968968
job._set_properties(resource)
969969
return job
970970

@@ -983,8 +983,8 @@ class _ExtractConfiguration(object):
983983
class ExtractJob(_AsyncJob):
984984
"""Asynchronous job: extract data from a table into Cloud Storage.
985985
986-
:type name: str
987-
:param name: the name of the job
986+
:type job_id: str
987+
:param job_id: the job's ID, within the project belonging to ``client``.
988988
989989
:type source: :class:`google.cloud.bigquery.table.Table`
990990
:param source: Table into which data is to be loaded.
@@ -1000,8 +1000,8 @@ class ExtractJob(_AsyncJob):
10001000
"""
10011001
_JOB_TYPE = 'extract'
10021002

1003-
def __init__(self, name, source, destination_uris, client):
1004-
super(ExtractJob, self).__init__(name, client)
1003+
def __init__(self, job_id, source, destination_uris, client):
1004+
super(ExtractJob, self).__init__(job_id, client)
10051005
self.source = source
10061006
self.destination_uris = destination_uris
10071007
self._configuration = _ExtractConfiguration()
@@ -1065,7 +1065,7 @@ def _build_resource(self):
10651065
resource = {
10661066
'jobReference': {
10671067
'projectId': self.project,
1068-
'jobId': self.name,
1068+
'jobId': self.job_id,
10691069
},
10701070
'configuration': {
10711071
self._JOB_TYPE: {
@@ -1106,12 +1106,12 @@ def from_api_repr(cls, resource, client):
11061106
:rtype: :class:`google.cloud.bigquery.job.ExtractJob`
11071107
:returns: Job parsed from ``resource``.
11081108
"""
1109-
name, config = cls._get_resource_config(resource)
1109+
job_id, config = cls._get_resource_config(resource)
11101110
source_config = config['sourceTable']
11111111
dataset = Dataset(source_config['datasetId'], client)
11121112
source = Table(source_config['tableId'], dataset)
11131113
destination_uris = config['destinationUris']
1114-
job = cls(name, source, destination_uris, client=client)
1114+
job = cls(job_id, source, destination_uris, client=client)
11151115
job._set_properties(resource)
11161116
return job
11171117

@@ -1138,8 +1138,8 @@ class _AsyncQueryConfiguration(object):
11381138
class QueryJob(_AsyncJob):
11391139
"""Asynchronous job: query tables.
11401140
1141-
:type name: str
1142-
:param name: the name of the job
1141+
:type job_id: str
1142+
:param job_id: the job's ID, within the project belonging to ``client``.
11431143
11441144
:type query: str
11451145
:param query: SQL query string
@@ -1163,9 +1163,9 @@ class QueryJob(_AsyncJob):
11631163
_UDF_KEY = 'userDefinedFunctionResources'
11641164
_QUERY_PARAMETERS_KEY = 'queryParameters'
11651165

1166-
def __init__(self, name, query, client,
1166+
def __init__(self, job_id, query, client,
11671167
udf_resources=(), query_parameters=()):
1168-
super(QueryJob, self).__init__(name, client)
1168+
super(QueryJob, self).__init__(job_id, client)
11691169
self.query = query
11701170
self.udf_resources = udf_resources
11711171
self.query_parameters = query_parameters
@@ -1306,7 +1306,7 @@ def _build_resource(self):
13061306
resource = {
13071307
'jobReference': {
13081308
'projectId': self.project,
1309-
'jobId': self.name,
1309+
'jobId': self.job_id,
13101310
},
13111311
'configuration': {
13121312
self._JOB_TYPE: {
@@ -1399,9 +1399,9 @@ def from_api_repr(cls, resource, client):
13991399
:rtype: :class:`google.cloud.bigquery.job.RunAsyncQueryJob`
14001400
:returns: Job parsed from ``resource``.
14011401
"""
1402-
name, config = cls._get_resource_config(resource)
1402+
job_id, config = cls._get_resource_config(resource)
14031403
query = config['query']
1404-
job = cls(name, query, client=client)
1404+
job = cls(job_id, query, client=client)
14051405
job._set_properties(resource)
14061406
return job
14071407

@@ -1573,7 +1573,7 @@ def query_results(self):
15731573
:returns: results instance
15741574
"""
15751575
if not self._query_results:
1576-
self._query_results = self._client._get_query_results(self.name)
1576+
self._query_results = self._client._get_query_results(self.job_id)
15771577
return self._query_results
15781578

15791579
def done(self):
@@ -1585,7 +1585,7 @@ def done(self):
15851585
# Do not refresh is the state is already done, as the job will not
15861586
# change once complete.
15871587
if self.state != _DONE_STATE:
1588-
self._query_results = self._client._get_query_results(self.name)
1588+
self._query_results = self._client._get_query_results(self.job_id)
15891589

15901590
# Only reload the job once we know the query is complete.
15911591
# This will ensure that fields such as the destination table are

bigquery/google/cloud/bigquery/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def from_query_job(cls, job):
9595
instance = cls(job.query, job._client, job.udf_resources)
9696
instance._job = job
9797
job_ref = instance._properties.setdefault('jobReference', {})
98-
job_ref['jobId'] = job.name
98+
job_ref['jobId'] = job.job_id
9999
if job.default_dataset is not None:
100100
instance.default_dataset = job.default_dataset
101101
if job.use_query_cache is not None:

bigquery/tests/system.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def test_create_table(self):
205205
table.create()
206206
self.to_delete.insert(0, table)
207207
self.assertTrue(table.exists())
208-
self.assertEqual(table.name, TABLE_NAME)
208+
self.assertEqual(table.table_id, TABLE_NAME)
209209

210210
def test_list_tables(self):
211211
DATASET_ID = _make_dataset_id('list_tables')
@@ -240,7 +240,7 @@ def test_list_tables(self):
240240
all_tables = list(iterator)
241241
self.assertIsNone(iterator.next_page_token)
242242
created = [table for table in all_tables
243-
if (table.name in tables_to_create and
243+
if (table.table_id in tables_to_create and
244244
table.dataset_id == DATASET_ID)]
245245
self.assertEqual(len(created), len(tables_to_create))
246246

@@ -1185,7 +1185,7 @@ def test_create_table_insert_fetch_nested_schema(self):
11851185
table.create()
11861186
self.to_delete.insert(0, table)
11871187
self.assertTrue(table.exists())
1188-
self.assertEqual(table.name, table_name)
1188+
self.assertEqual(table.table_id, table_name)
11891189

11901190
to_insert = []
11911191
# Data is in "JSON Lines" format, see http://jsonlines.org/

bigquery/tests/unit/test_client.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def test_get_job_hit(self):
333333
job = client.get_job(JOB_ID)
334334

335335
self.assertIsInstance(job, QueryJob)
336-
self.assertEqual(job.name, JOB_ID)
336+
self.assertEqual(job.job_id, JOB_ID)
337337
self.assertEqual(job.create_disposition, 'CREATE_IF_NEEDED')
338338
self.assertEqual(job.write_disposition, 'WRITE_TRUNCATE')
339339

@@ -466,7 +466,7 @@ def test_list_jobs_defaults(self):
466466
for found, expected in zip(jobs, DATA['jobs']):
467467
name = expected['jobReference']['jobId']
468468
self.assertIsInstance(found, JOB_TYPES[name])
469-
self.assertEqual(found.name, name)
469+
self.assertEqual(found.job_id, name)
470470
self.assertEqual(token, TOKEN)
471471

472472
self.assertEqual(len(conn._requested), 1)
@@ -523,7 +523,7 @@ def test_list_jobs_load_job_wo_sourceUris(self):
523523
for found, expected in zip(jobs, DATA['jobs']):
524524
name = expected['jobReference']['jobId']
525525
self.assertIsInstance(found, JOB_TYPES[name])
526-
self.assertEqual(found.name, name)
526+
self.assertEqual(found.job_id, name)
527527
self.assertEqual(token, TOKEN)
528528

529529
self.assertEqual(len(conn._requested), 1)
@@ -579,7 +579,7 @@ def test_load_table_from_storage(self):
579579
job = client.load_table_from_storage(JOB, destination, SOURCE_URI)
580580
self.assertIsInstance(job, LoadJob)
581581
self.assertIs(job._client, client)
582-
self.assertEqual(job.name, JOB)
582+
self.assertEqual(job.job_id, JOB)
583583
self.assertEqual(list(job.source_uris), [SOURCE_URI])
584584
self.assertIs(job.destination, destination)
585585

@@ -600,7 +600,7 @@ def test_copy_table(self):
600600
job = client.copy_table(JOB, destination, source)
601601
self.assertIsInstance(job, CopyJob)
602602
self.assertIs(job._client, client)
603-
self.assertEqual(job.name, JOB)
603+
self.assertEqual(job.job_id, JOB)
604604
self.assertEqual(list(job.sources), [source])
605605
self.assertIs(job.destination, destination)
606606

@@ -620,7 +620,7 @@ def test_extract_table_to_storage(self):
620620
job = client.extract_table_to_storage(JOB, source, DESTINATION)
621621
self.assertIsInstance(job, ExtractJob)
622622
self.assertIs(job._client, client)
623-
self.assertEqual(job.name, JOB)
623+
self.assertEqual(job.job_id, JOB)
624624
self.assertEqual(job.source, source)
625625
self.assertEqual(list(job.destination_uris), [DESTINATION])
626626

@@ -636,7 +636,7 @@ def test_run_async_query_defaults(self):
636636
job = client.run_async_query(JOB, QUERY)
637637
self.assertIsInstance(job, QueryJob)
638638
self.assertIs(job._client, client)
639-
self.assertEqual(job.name, JOB)
639+
self.assertEqual(job.job_id, JOB)
640640
self.assertEqual(job.query, QUERY)
641641
self.assertEqual(job.udf_resources, [])
642642
self.assertEqual(job.query_parameters, [])
@@ -656,7 +656,7 @@ def test_run_async_w_udf_resources(self):
656656
job = client.run_async_query(JOB, QUERY, udf_resources=udf_resources)
657657
self.assertIsInstance(job, QueryJob)
658658
self.assertIs(job._client, client)
659-
self.assertEqual(job.name, JOB)
659+
self.assertEqual(job.job_id, JOB)
660660
self.assertEqual(job.query, QUERY)
661661
self.assertEqual(job.udf_resources, udf_resources)
662662
self.assertEqual(job.query_parameters, [])
@@ -676,7 +676,7 @@ def test_run_async_w_query_parameters(self):
676676
query_parameters=query_parameters)
677677
self.assertIsInstance(job, QueryJob)
678678
self.assertIs(job._client, client)
679-
self.assertEqual(job.name, JOB)
679+
self.assertEqual(job.job_id, JOB)
680680
self.assertEqual(job.query, QUERY)
681681
self.assertEqual(job.udf_resources, [])
682682
self.assertEqual(job.query_parameters, query_parameters)

bigquery/tests/unit/test_query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def test_job_w_jobid(self):
262262
self.assertIsInstance(job, QueryJob)
263263
self.assertEqual(job.query, self.QUERY)
264264
self.assertIs(job._client, client)
265-
self.assertEqual(job.name, SERVER_GENERATED)
265+
self.assertEqual(job.job_id, SERVER_GENERATED)
266266
fetched_later = query.job
267267
self.assertIs(fetched_later, job)
268268

0 commit comments

Comments
 (0)