Skip to content

Commit 8a34642

Browse files
committed
use _get_sub_prop helper so missing load stats don't raise
1 parent 853b130 commit 8a34642

2 files changed

Lines changed: 21 additions & 17 deletions

File tree

bigquery/google/cloud/bigquery/job.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,9 +1332,9 @@ def input_file_bytes(self):
13321332
:returns: the count (None until set from the server).
13331333
:raises: ValueError for invalid value types.
13341334
"""
1335-
statistics = self._properties.get('statistics')
1336-
if statistics is not None:
1337-
return int(statistics['load']['inputFileBytes'])
1335+
return _helpers._get_sub_prop(
1336+
self._properties, ['statistics', 'load', 'inputFileBytes']
1337+
)
13381338

13391339
@property
13401340
def input_files(self):
@@ -1343,9 +1343,9 @@ def input_files(self):
13431343
:rtype: int, or ``NoneType``
13441344
:returns: the count (None until set from the server).
13451345
"""
1346-
statistics = self._properties.get('statistics')
1347-
if statistics is not None:
1348-
return int(statistics['load']['inputFiles'])
1346+
return _helpers._get_sub_prop(
1347+
self._properties, ['statistics', 'load', 'inputFiles']
1348+
)
13491349

13501350
@property
13511351
def output_bytes(self):
@@ -1354,9 +1354,9 @@ def output_bytes(self):
13541354
:rtype: int, or ``NoneType``
13551355
:returns: the count (None until set from the server).
13561356
"""
1357-
statistics = self._properties.get('statistics')
1358-
if statistics is not None:
1359-
return int(statistics['load']['outputBytes'])
1357+
return _helpers._get_sub_prop(
1358+
self._properties, ['statistics', 'load', 'outputBytes']
1359+
)
13601360

13611361
@property
13621362
def output_rows(self):
@@ -1365,9 +1365,9 @@ def output_rows(self):
13651365
:rtype: int, or ``NoneType``
13661366
:returns: the count (None until set from the server).
13671367
"""
1368-
statistics = self._properties.get('statistics')
1369-
if statistics is not None:
1370-
return int(statistics['load']['outputRows'])
1368+
return _helpers._get_sub_prop(
1369+
self._properties, ['statistics', 'load', 'outputRows']
1370+
)
13711371

13721372
def to_api_repr(self):
13731373
"""Generate a resource for :meth:`_begin`."""

bigquery/tests/unit/test_job.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,11 +1521,6 @@ def test_props_set_by_server(self):
15211521
statistics['creationTime'] = _millis(CREATED)
15221522
statistics['startTime'] = _millis(STARTED)
15231523
statistics['endTime'] = _millis(ENDED)
1524-
load_stats = statistics['load'] = {}
1525-
load_stats['inputFileBytes'] = 12345
1526-
load_stats['inputFiles'] = 1
1527-
load_stats['outputBytes'] = 23456
1528-
load_stats['outputRows'] = 345
15291524

15301525
self.assertEqual(job.etag, 'ETAG')
15311526
self.assertEqual(job.self_link, URL)
@@ -1535,6 +1530,15 @@ def test_props_set_by_server(self):
15351530
self.assertEqual(job.started, STARTED)
15361531
self.assertEqual(job.ended, ENDED)
15371532

1533+
# running jobs have no load stats not yet set.
1534+
self.assertIsNone(job.output_bytes)
1535+
1536+
load_stats = statistics['load'] = {}
1537+
load_stats['inputFileBytes'] = 12345
1538+
load_stats['inputFiles'] = 1
1539+
load_stats['outputBytes'] = 23456
1540+
load_stats['outputRows'] = 345
1541+
15381542
self.assertEqual(job.input_file_bytes, 12345)
15391543
self.assertEqual(job.input_files, 1)
15401544
self.assertEqual(job.output_bytes, 23456)

0 commit comments

Comments
 (0)