Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'ExtractTableStorageJob.destination_uri_file_counts' property. #3803

Merged
merged 2 commits into from
Sep 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions bigquery/google/cloud/bigquery/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,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 @@ -1190,6 +1190,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