Skip to content

Commit

Permalink
Add 'ExtractTableStorageJob.destination_uri_file_counts' property. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tseaver authored and tswast committed Sep 25, 2017
1 parent c5f5f12 commit 2ea7a6a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
16 changes: 16 additions & 0 deletions bigquery/google/cloud/bigquery/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,22 @@ def __init__(self, name, source, destination_uris, client):
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#configuration.extract.printHeader
"""

@property
def destination_uri_file_counts(self):
"""Return file counts from job statistics, if present.
See:
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#statistics.extract.destinationUriFileCounts
:rtype: int or None
:returns: number of DML rows affectd by the job, or None if job is not
yet complete.
"""
result = self._job_statistics().get('destinationUriFileCounts')
if result is not None:
result = int(result)
return result

def _populate_config_resource(self, configuration):
"""Helper for _build_resource: copy config properties to resource"""
if self.compression is not None:
Expand Down
17 changes: 17 additions & 0 deletions bigquery/tests/unit/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,23 @@ def test_ctor(self):
self.assertIsNone(job.field_delimiter)
self.assertIsNone(job.print_header)

def test_destination_uri_file_counts(self):
file_counts = 23
client = _Client(self.PROJECT)
source = _Table(self.SOURCE_TABLE)
job = self._make_one(self.JOB_NAME, source, [self.DESTINATION_URI],
client)
self.assertIsNone(job.destination_uri_file_counts)

statistics = job._properties['statistics'] = {}
self.assertIsNone(job.destination_uri_file_counts)

extract_stats = statistics['extract'] = {}
self.assertIsNone(job.destination_uri_file_counts)

extract_stats['destinationUriFileCounts'] = str(file_counts)
self.assertEqual(job.destination_uri_file_counts, file_counts)

def test_from_api_repr_missing_identity(self):
self._setUpConstants()
client = _Client(self.PROJECT)
Expand Down

0 comments on commit 2ea7a6a

Please sign in to comment.