diff --git a/bigquery/google/cloud/bigquery/job.py b/bigquery/google/cloud/bigquery/job.py index 014eb2ee2740..f060ba1bc2f9 100644 --- a/bigquery/google/cloud/bigquery/job.py +++ b/bigquery/google/cloud/bigquery/job.py @@ -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: diff --git a/bigquery/tests/unit/test_job.py b/bigquery/tests/unit/test_job.py index 9e684faf4f8b..23fb95eea123 100644 --- a/bigquery/tests/unit/test_job.py +++ b/bigquery/tests/unit/test_job.py @@ -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)